|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Music app |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Pauli Järvinen <[email protected]> |
|
10
|
|
|
* @copyright Pauli Järvinen 2018 - 2020 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Music\Controller; |
|
14
|
|
|
|
|
15
|
|
|
use \OCP\AppFramework\Controller; |
|
|
|
|
|
|
16
|
|
|
use \OCP\AppFramework\Http; |
|
|
|
|
|
|
17
|
|
|
use \OCP\AppFramework\Http\JSONResponse; |
|
|
|
|
|
|
18
|
|
|
use \OCP\IRequest; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
use \OCA\Music\AppFramework\Core\Logger; |
|
21
|
|
|
use \OCA\Music\Http\ErrorResponse; |
|
22
|
|
|
use \OCA\Music\Utility\PlaylistFileService; |
|
23
|
|
|
use \OCA\Music\Utility\Scanner; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* End-points for shared audio file handling. Methods of this class may be |
|
27
|
|
|
* used while there is no user logged in. |
|
28
|
|
|
*/ |
|
29
|
|
|
class ShareController extends Controller { |
|
30
|
|
|
|
|
31
|
|
|
/** @var \OCP\Share\IManager */ |
|
|
|
|
|
|
32
|
|
|
private $shareManager; |
|
33
|
|
|
/** @var Scanner */ |
|
34
|
|
|
private $scanner; |
|
35
|
|
|
/** @var PlaylistFileService */ |
|
36
|
|
|
private $playlistFileService; |
|
37
|
|
|
/** @var Logger */ |
|
38
|
|
|
private $logger; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct($appname, |
|
41
|
|
|
IRequest $request, |
|
42
|
|
|
Scanner $scanner, |
|
43
|
|
|
PlaylistFileService $playlistFileService, |
|
44
|
|
|
Logger $logger, |
|
45
|
|
|
\OCP\Share\IManager $shareManager) { |
|
46
|
|
|
parent::__construct($appname, $request); |
|
47
|
|
|
$this->shareManager = $shareManager; |
|
48
|
|
|
$this->scanner = $scanner; |
|
49
|
|
|
$this->playlistFileService = $playlistFileService; |
|
50
|
|
|
$this->logger = $logger; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @PublicPage |
|
55
|
|
|
* @NoCSRFRequired |
|
56
|
|
|
*/ |
|
57
|
|
|
public function fileInfo($token, $fileId) { |
|
58
|
|
|
$share = $this->shareManager->getShareByToken($token); |
|
59
|
|
|
$fileOwner = $share->getShareOwner(); |
|
60
|
|
|
$fileOwnerHome = $this->scanner->resolveUserFolder($fileOwner); |
|
61
|
|
|
|
|
62
|
|
|
// If non-zero fileId is given, the $share identified by the token should |
|
63
|
|
|
// be the file's parent directory. Otherwise the share is the target file. |
|
64
|
|
|
if ($fileId == 0) { |
|
65
|
|
|
$fileId = $share->getNodeId(); |
|
66
|
|
|
} else { |
|
67
|
|
|
$folderId = $share->getNodeId(); |
|
68
|
|
|
$matchingFolders = $fileOwnerHome->getById($folderId); |
|
69
|
|
|
if (empty($matchingFolders) |
|
70
|
|
|
|| empty($matchingFolders[0]->getById($fileId))) { |
|
71
|
|
|
// no such shared folder or the folder does not contain the given file |
|
72
|
|
|
$fileId = null; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$info = $this->scanner->getFileInfo($fileId, $fileOwner, $fileOwnerHome); |
|
77
|
|
|
|
|
78
|
|
|
if ($info) { |
|
79
|
|
|
return new JSONResponse($info); |
|
80
|
|
|
} else { |
|
81
|
|
|
return new ErrorResponse(Http::STATUS_NOT_FOUND); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @PublicPage |
|
87
|
|
|
* @NoCSRFRequired |
|
88
|
|
|
*/ |
|
89
|
|
|
public function parsePlaylist($token, $fileId) { |
|
90
|
|
|
$share = $this->shareManager->getShareByToken($token); |
|
91
|
|
|
$fileOwner = $share->getShareOwner(); |
|
92
|
|
|
$fileOwnerHome = $this->scanner->resolveUserFolder($fileOwner); |
|
93
|
|
|
|
|
94
|
|
|
$matchingFolders = $fileOwnerHome->getById($share->getNodeId()); |
|
95
|
|
|
|
|
96
|
|
|
try { |
|
97
|
|
|
if (empty($matchingFolders)) { |
|
98
|
|
|
throw new \OCP\Files\NotFoundException(); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
$sharedFolder = $matchingFolders[0]; |
|
101
|
|
|
$result = $this->playlistFileService->parseFile($fileId, $sharedFolder); |
|
102
|
|
|
|
|
103
|
|
|
// compose the final result |
|
104
|
|
|
$result['files'] = \array_map(function($fileAndCaption) use ($sharedFolder) { |
|
105
|
|
|
$file = $fileAndCaption['file']; |
|
106
|
|
|
return [ |
|
107
|
|
|
'id' => $file->getId(), |
|
108
|
|
|
'name' => $file->getName(), |
|
109
|
|
|
'path' => $sharedFolder->getRelativePath($file->getParent()->getPath()), |
|
110
|
|
|
'mimetype' => $file->getMimeType() |
|
111
|
|
|
]; |
|
112
|
|
|
}, $result['files']); |
|
113
|
|
|
return new JSONResponse($result); |
|
114
|
|
|
} |
|
115
|
|
|
catch (\OCP\Files\NotFoundException $ex) { |
|
116
|
|
|
return new ErrorResponse(Http::STATUS_NOT_FOUND, 'playlist file not found'); |
|
117
|
|
|
} |
|
118
|
|
|
catch (\UnexpectedValueException $ex) { |
|
119
|
|
|
return new ErrorResponse(Http::STATUS_UNSUPPORTED_MEDIA_TYPE, $ex->getMessage()); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths