@@ -2,11 +2,11 @@ discard block |
||
2 | 2 | <div class="hidden"> |
3 | 3 | <ul class="with-icon" tabindex="0"> |
4 | 4 | <?php |
5 | - $pinned = 0; |
|
6 | - foreach ($_['navigationItems'] as $item) { |
|
7 | - $pinned = NavigationListElements($item, $l, $pinned); |
|
8 | - } |
|
9 | - ?> |
|
5 | + $pinned = 0; |
|
6 | + foreach ($_['navigationItems'] as $item) { |
|
7 | + $pinned = NavigationListElements($item, $l, $pinned); |
|
8 | + } |
|
9 | + ?> |
|
10 | 10 | </ul> |
11 | 11 | </div> |
12 | 12 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @return int Returns the pinned value |
24 | 24 | */ |
25 | 25 | function NavigationListElements($item, $l, $pinned) { |
26 | - strpos($item['classes'] ?? '', 'pinned') !== false ? $pinned++ : ''; ?> |
|
26 | + strpos($item['classes'] ?? '', 'pinned') !== false ? $pinned++ : ''; ?> |
|
27 | 27 | <li |
28 | 28 | data-id="<?php p($item['id']) ?>" |
29 | 29 | <?php if (isset($item['dir'])) { ?> data-dir="<?php p($item['dir']); ?>" <?php } ?> |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | <?php if (isset($item['expandedState'])) { ?> data-expandedstate="<?php p($item['expandedState']); ?>" <?php } ?> |
32 | 32 | class="nav-<?php p($item['id']) ?> |
33 | 33 | <?php if (isset($item['classes'])) { |
34 | - p($item['classes']); |
|
35 | - } ?> |
|
34 | + p($item['classes']); |
|
35 | + } ?> |
|
36 | 36 | <?php p($pinned === 1 ? 'first-pinned' : '') ?> |
37 | 37 | <?php if (isset($item['defaultExpandedState']) && $item['defaultExpandedState']) { ?> open<?php } ?>" |
38 | 38 | <?php if (isset($item['folderPosition'])) { ?> folderposition="<?php p($item['folderPosition']); ?>" <?php } ?>> |
@@ -42,26 +42,26 @@ discard block |
||
42 | 42 | |
43 | 43 | |
44 | 44 | <?php |
45 | - NavigationElementMenu($item); |
|
46 | - if (isset($item['sublist'])) { |
|
47 | - ?> |
|
45 | + NavigationElementMenu($item); |
|
46 | + if (isset($item['sublist'])) { |
|
47 | + ?> |
|
48 | 48 | <button class="collapse app-navigation-noclose" aria-expanded="<?= !empty($item['defaultExpandedState']) ? 'true' : 'false' ?>" |
49 | 49 | aria-label="<?php p($l->t('Toggle %1$s sublist', $item['name'])) ?>" |
50 | 50 | <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>> |
51 | 51 | </button> |
52 | 52 | <ul id="sublist-<?php p($item['id']); ?>"> |
53 | 53 | <?php |
54 | - foreach ($item['sublist'] as $item) { |
|
55 | - $pinned = NavigationListElements($item, $l, $pinned); |
|
56 | - } ?> |
|
54 | + foreach ($item['sublist'] as $item) { |
|
55 | + $pinned = NavigationListElements($item, $l, $pinned); |
|
56 | + } ?> |
|
57 | 57 | </ul> |
58 | 58 | <?php |
59 | - } ?> |
|
59 | + } ?> |
|
60 | 60 | </li> |
61 | 61 | |
62 | 62 | |
63 | 63 | <?php |
64 | - return $pinned; |
|
64 | + return $pinned; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * @return void |
73 | 73 | */ |
74 | 74 | function NavigationElementMenu($item) { |
75 | - if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') { |
|
76 | - ?> |
|
75 | + if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') { |
|
76 | + ?> |
|
77 | 77 | <div id="dotmenu-<?php p($item['id']); ?>" |
78 | 78 | class="app-navigation-entry-utils" <?php if (isset($item['enableMenuButton']) && $item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>> |
79 | 79 | <ul> |
@@ -89,5 +89,5 @@ discard block |
||
89 | 89 | </ul> |
90 | 90 | </div> |
91 | 91 | <?php |
92 | - } |
|
92 | + } |
|
93 | 93 | } |
@@ -64,386 +64,386 @@ |
||
64 | 64 | * @package OCA\Files\Controller |
65 | 65 | */ |
66 | 66 | class ApiController extends Controller { |
67 | - private TagService $tagService; |
|
68 | - private IManager $shareManager; |
|
69 | - private IPreview $previewManager; |
|
70 | - private IUserSession $userSession; |
|
71 | - private IConfig $config; |
|
72 | - private Folder $userFolder; |
|
73 | - private UserConfig $userConfig; |
|
74 | - |
|
75 | - /** |
|
76 | - * @param string $appName |
|
77 | - * @param IRequest $request |
|
78 | - * @param IUserSession $userSession |
|
79 | - * @param TagService $tagService |
|
80 | - * @param IPreview $previewManager |
|
81 | - * @param IManager $shareManager |
|
82 | - * @param IConfig $config |
|
83 | - * @param Folder $userFolder |
|
84 | - */ |
|
85 | - public function __construct($appName, |
|
86 | - IRequest $request, |
|
87 | - IUserSession $userSession, |
|
88 | - TagService $tagService, |
|
89 | - IPreview $previewManager, |
|
90 | - IManager $shareManager, |
|
91 | - IConfig $config, |
|
92 | - Folder $userFolder, |
|
93 | - UserConfig $userConfig) { |
|
94 | - parent::__construct($appName, $request); |
|
95 | - $this->userSession = $userSession; |
|
96 | - $this->tagService = $tagService; |
|
97 | - $this->previewManager = $previewManager; |
|
98 | - $this->shareManager = $shareManager; |
|
99 | - $this->config = $config; |
|
100 | - $this->userFolder = $userFolder; |
|
101 | - $this->userConfig = $userConfig; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Gets a thumbnail of the specified file |
|
106 | - * |
|
107 | - * @since API version 1.0 |
|
108 | - * |
|
109 | - * @NoAdminRequired |
|
110 | - * @NoCSRFRequired |
|
111 | - * @StrictCookieRequired |
|
112 | - * |
|
113 | - * @param int $x |
|
114 | - * @param int $y |
|
115 | - * @param string $file URL-encoded filename |
|
116 | - * @return DataResponse|FileDisplayResponse |
|
117 | - */ |
|
118 | - public function getThumbnail($x, $y, $file) { |
|
119 | - if ($x < 1 || $y < 1) { |
|
120 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
121 | - } |
|
122 | - |
|
123 | - try { |
|
124 | - $file = $this->userFolder->get($file); |
|
125 | - if ($file instanceof Folder) { |
|
126 | - throw new NotFoundException(); |
|
127 | - } |
|
128 | - |
|
129 | - /** @var File $file */ |
|
130 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
131 | - |
|
132 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
133 | - } catch (NotFoundException $e) { |
|
134 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
135 | - } catch (\Exception $e) { |
|
136 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Updates the info of the specified file path |
|
142 | - * The passed tags are absolute, which means they will |
|
143 | - * replace the actual tag selection. |
|
144 | - * |
|
145 | - * @NoAdminRequired |
|
146 | - * |
|
147 | - * @param string $path path |
|
148 | - * @param array|string $tags array of tags |
|
149 | - * @return DataResponse |
|
150 | - */ |
|
151 | - public function updateFileTags($path, $tags = null) { |
|
152 | - $result = []; |
|
153 | - // if tags specified or empty array, update tags |
|
154 | - if (!is_null($tags)) { |
|
155 | - try { |
|
156 | - $this->tagService->updateFileTags($path, $tags); |
|
157 | - } catch (\OCP\Files\NotFoundException $e) { |
|
158 | - return new DataResponse([ |
|
159 | - 'message' => $e->getMessage() |
|
160 | - ], Http::STATUS_NOT_FOUND); |
|
161 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
162 | - return new DataResponse([ |
|
163 | - 'message' => $e->getMessage() |
|
164 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
165 | - } catch (\Exception $e) { |
|
166 | - return new DataResponse([ |
|
167 | - 'message' => $e->getMessage() |
|
168 | - ], Http::STATUS_NOT_FOUND); |
|
169 | - } |
|
170 | - $result['tags'] = $tags; |
|
171 | - } |
|
172 | - return new DataResponse($result); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param \OCP\Files\Node[] $nodes |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - private function formatNodes(array $nodes) { |
|
180 | - $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
181 | - return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
182 | - $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
183 | - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
184 | - $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
185 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
186 | - if (isset($parts[3])) { |
|
187 | - $file['path'] = '/' . $parts[3]; |
|
188 | - } else { |
|
189 | - $file['path'] = '/'; |
|
190 | - } |
|
191 | - if (!empty($shareTypes)) { |
|
192 | - $file['shareTypes'] = $shareTypes; |
|
193 | - } |
|
194 | - return $file; |
|
195 | - }, $nodes)); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get the share types for each node |
|
200 | - * |
|
201 | - * @param \OCP\Files\Node[] $nodes |
|
202 | - * @return array<int, int[]> list of share types for each fileid |
|
203 | - */ |
|
204 | - private function getShareTypesForNodes(array $nodes): array { |
|
205 | - $userId = $this->userSession->getUser()->getUID(); |
|
206 | - $requestedShareTypes = [ |
|
207 | - IShare::TYPE_USER, |
|
208 | - IShare::TYPE_GROUP, |
|
209 | - IShare::TYPE_LINK, |
|
210 | - IShare::TYPE_REMOTE, |
|
211 | - IShare::TYPE_EMAIL, |
|
212 | - IShare::TYPE_ROOM, |
|
213 | - IShare::TYPE_DECK, |
|
214 | - IShare::TYPE_SCIENCEMESH, |
|
215 | - ]; |
|
216 | - $shareTypes = []; |
|
217 | - |
|
218 | - $nodeIds = array_map(function (Node $node) { |
|
219 | - return $node->getId(); |
|
220 | - }, $nodes); |
|
221 | - |
|
222 | - foreach ($requestedShareTypes as $shareType) { |
|
223 | - $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
224 | - $offset = 0; |
|
225 | - |
|
226 | - // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
227 | - while (count($nodesLeft) > 0) { |
|
228 | - $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
229 | - foreach ($shares as $share) { |
|
230 | - $fileId = $share->getNodeId(); |
|
231 | - if (isset($nodesLeft[$fileId])) { |
|
232 | - if (!isset($shareTypes[$fileId])) { |
|
233 | - $shareTypes[$fileId] = []; |
|
234 | - } |
|
235 | - $shareTypes[$fileId][] = $shareType; |
|
236 | - unset($nodesLeft[$fileId]); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - if (count($shares) < 100) { |
|
241 | - break; |
|
242 | - } else { |
|
243 | - $offset += count($shares); |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - return $shareTypes; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns a list of recently modified files. |
|
252 | - * |
|
253 | - * @NoAdminRequired |
|
254 | - * |
|
255 | - * @return DataResponse |
|
256 | - */ |
|
257 | - public function getRecentFiles() { |
|
258 | - $nodes = $this->userFolder->getRecent(100); |
|
259 | - $files = $this->formatNodes($nodes); |
|
260 | - return new DataResponse(['files' => $files]); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Returns the current logged-in user's storage stats. |
|
266 | - * |
|
267 | - * @NoAdminRequired |
|
268 | - * |
|
269 | - * @param ?string $dir the directory to get the storage stats from |
|
270 | - * @return JSONResponse |
|
271 | - */ |
|
272 | - public function getStorageStats($dir = '/'): JSONResponse { |
|
273 | - $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
274 | - return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Change the default sort mode |
|
279 | - * |
|
280 | - * @NoAdminRequired |
|
281 | - * |
|
282 | - * @param string $mode |
|
283 | - * @param string $direction |
|
284 | - * @return JSONResponse |
|
285 | - * @throws \OCP\PreConditionNotMetException |
|
286 | - */ |
|
287 | - public function updateFileSorting($mode, string $direction = 'asc', string $view = 'files'): JSONResponse { |
|
288 | - $allowedDirection = ['asc', 'desc']; |
|
289 | - if (!in_array($direction, $allowedDirection)) { |
|
290 | - return new JSONResponse(['message' => 'Invalid direction parameter'], Http::STATUS_UNPROCESSABLE_ENTITY); |
|
291 | - } |
|
292 | - |
|
293 | - $userId = $this->userSession->getUser()->getUID(); |
|
294 | - |
|
295 | - $sortingJson = $this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'); |
|
296 | - $sortingConfig = json_decode($sortingJson, true) ?: []; |
|
297 | - $sortingConfig[$view] = [ |
|
298 | - 'mode' => $mode, |
|
299 | - 'direction' => $direction, |
|
300 | - ]; |
|
301 | - |
|
302 | - $this->config->setUserValue($userId, 'files', 'files_sorting_configs', json_encode($sortingConfig)); |
|
303 | - return new JSONResponse([ |
|
304 | - 'message' => 'ok', |
|
305 | - 'data' => $sortingConfig, |
|
306 | - ]); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Toggle default files user config |
|
311 | - * |
|
312 | - * @NoAdminRequired |
|
313 | - * |
|
314 | - * @param string $key |
|
315 | - * @param string|bool $value |
|
316 | - * @return JSONResponse |
|
317 | - */ |
|
318 | - public function setConfig(string $key, $value): JSONResponse { |
|
319 | - try { |
|
320 | - $this->userConfig->setConfig($key, (string)$value); |
|
321 | - } catch (\InvalidArgumentException $e) { |
|
322 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
323 | - } |
|
324 | - |
|
325 | - return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Get the user config |
|
331 | - * |
|
332 | - * @NoAdminRequired |
|
333 | - * |
|
334 | - * @return JSONResponse |
|
335 | - */ |
|
336 | - public function getConfigs(): JSONResponse { |
|
337 | - return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Toggle default for showing/hiding hidden files |
|
342 | - * |
|
343 | - * @NoAdminRequired |
|
344 | - * |
|
345 | - * @param bool $value |
|
346 | - * @return Response |
|
347 | - * @throws \OCP\PreConditionNotMetException |
|
348 | - */ |
|
349 | - public function showHiddenFiles(bool $value): Response { |
|
350 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
351 | - return new Response(); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Toggle default for cropping preview images |
|
356 | - * |
|
357 | - * @NoAdminRequired |
|
358 | - * |
|
359 | - * @param bool $value |
|
360 | - * @return Response |
|
361 | - * @throws \OCP\PreConditionNotMetException |
|
362 | - */ |
|
363 | - public function cropImagePreviews(bool $value): Response { |
|
364 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
365 | - return new Response(); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Toggle default for files grid view |
|
370 | - * |
|
371 | - * @NoAdminRequired |
|
372 | - * |
|
373 | - * @param bool $show |
|
374 | - * @return Response |
|
375 | - * @throws \OCP\PreConditionNotMetException |
|
376 | - */ |
|
377 | - public function showGridView(bool $show): Response { |
|
378 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
379 | - return new Response(); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Get default settings for the grid view |
|
384 | - * |
|
385 | - * @NoAdminRequired |
|
386 | - */ |
|
387 | - public function getGridView() { |
|
388 | - $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
389 | - return new JSONResponse(['gridview' => $status]); |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Toggle default for showing/hiding xxx folder |
|
394 | - * |
|
395 | - * @NoAdminRequired |
|
396 | - * |
|
397 | - * @param int $show |
|
398 | - * @param string $key the key of the folder |
|
399 | - * |
|
400 | - * @return Response |
|
401 | - * @throws \OCP\PreConditionNotMetException |
|
402 | - */ |
|
403 | - public function toggleShowFolder(int $show, string $key): Response { |
|
404 | - if ($show !== 0 && $show !== 1) { |
|
405 | - return new DataResponse([ |
|
406 | - 'message' => 'Invalid show value. Only 0 and 1 are allowed.' |
|
407 | - ], Http::STATUS_BAD_REQUEST); |
|
408 | - } |
|
409 | - |
|
410 | - $userId = $this->userSession->getUser()->getUID(); |
|
411 | - |
|
412 | - // Set the new value and return it |
|
413 | - // Using a prefix prevents the user from setting arbitrary keys |
|
414 | - $this->config->setUserValue($userId, 'files', 'show_' . $key, (string)$show); |
|
415 | - return new JSONResponse([$key => $show]); |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Get sorting-order for custom sorting |
|
420 | - * |
|
421 | - * @NoAdminRequired |
|
422 | - * |
|
423 | - * @param string $folderpath |
|
424 | - * @return string |
|
425 | - * @throws \OCP\Files\NotFoundException |
|
426 | - */ |
|
427 | - public function getNodeType($folderpath) { |
|
428 | - $node = $this->userFolder->get($folderpath); |
|
429 | - return $node->getType(); |
|
430 | - } |
|
67 | + private TagService $tagService; |
|
68 | + private IManager $shareManager; |
|
69 | + private IPreview $previewManager; |
|
70 | + private IUserSession $userSession; |
|
71 | + private IConfig $config; |
|
72 | + private Folder $userFolder; |
|
73 | + private UserConfig $userConfig; |
|
74 | + |
|
75 | + /** |
|
76 | + * @param string $appName |
|
77 | + * @param IRequest $request |
|
78 | + * @param IUserSession $userSession |
|
79 | + * @param TagService $tagService |
|
80 | + * @param IPreview $previewManager |
|
81 | + * @param IManager $shareManager |
|
82 | + * @param IConfig $config |
|
83 | + * @param Folder $userFolder |
|
84 | + */ |
|
85 | + public function __construct($appName, |
|
86 | + IRequest $request, |
|
87 | + IUserSession $userSession, |
|
88 | + TagService $tagService, |
|
89 | + IPreview $previewManager, |
|
90 | + IManager $shareManager, |
|
91 | + IConfig $config, |
|
92 | + Folder $userFolder, |
|
93 | + UserConfig $userConfig) { |
|
94 | + parent::__construct($appName, $request); |
|
95 | + $this->userSession = $userSession; |
|
96 | + $this->tagService = $tagService; |
|
97 | + $this->previewManager = $previewManager; |
|
98 | + $this->shareManager = $shareManager; |
|
99 | + $this->config = $config; |
|
100 | + $this->userFolder = $userFolder; |
|
101 | + $this->userConfig = $userConfig; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Gets a thumbnail of the specified file |
|
106 | + * |
|
107 | + * @since API version 1.0 |
|
108 | + * |
|
109 | + * @NoAdminRequired |
|
110 | + * @NoCSRFRequired |
|
111 | + * @StrictCookieRequired |
|
112 | + * |
|
113 | + * @param int $x |
|
114 | + * @param int $y |
|
115 | + * @param string $file URL-encoded filename |
|
116 | + * @return DataResponse|FileDisplayResponse |
|
117 | + */ |
|
118 | + public function getThumbnail($x, $y, $file) { |
|
119 | + if ($x < 1 || $y < 1) { |
|
120 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
121 | + } |
|
122 | + |
|
123 | + try { |
|
124 | + $file = $this->userFolder->get($file); |
|
125 | + if ($file instanceof Folder) { |
|
126 | + throw new NotFoundException(); |
|
127 | + } |
|
128 | + |
|
129 | + /** @var File $file */ |
|
130 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
131 | + |
|
132 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
133 | + } catch (NotFoundException $e) { |
|
134 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
135 | + } catch (\Exception $e) { |
|
136 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Updates the info of the specified file path |
|
142 | + * The passed tags are absolute, which means they will |
|
143 | + * replace the actual tag selection. |
|
144 | + * |
|
145 | + * @NoAdminRequired |
|
146 | + * |
|
147 | + * @param string $path path |
|
148 | + * @param array|string $tags array of tags |
|
149 | + * @return DataResponse |
|
150 | + */ |
|
151 | + public function updateFileTags($path, $tags = null) { |
|
152 | + $result = []; |
|
153 | + // if tags specified or empty array, update tags |
|
154 | + if (!is_null($tags)) { |
|
155 | + try { |
|
156 | + $this->tagService->updateFileTags($path, $tags); |
|
157 | + } catch (\OCP\Files\NotFoundException $e) { |
|
158 | + return new DataResponse([ |
|
159 | + 'message' => $e->getMessage() |
|
160 | + ], Http::STATUS_NOT_FOUND); |
|
161 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
162 | + return new DataResponse([ |
|
163 | + 'message' => $e->getMessage() |
|
164 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
165 | + } catch (\Exception $e) { |
|
166 | + return new DataResponse([ |
|
167 | + 'message' => $e->getMessage() |
|
168 | + ], Http::STATUS_NOT_FOUND); |
|
169 | + } |
|
170 | + $result['tags'] = $tags; |
|
171 | + } |
|
172 | + return new DataResponse($result); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param \OCP\Files\Node[] $nodes |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + private function formatNodes(array $nodes) { |
|
180 | + $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
181 | + return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
182 | + $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
183 | + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
184 | + $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
185 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
186 | + if (isset($parts[3])) { |
|
187 | + $file['path'] = '/' . $parts[3]; |
|
188 | + } else { |
|
189 | + $file['path'] = '/'; |
|
190 | + } |
|
191 | + if (!empty($shareTypes)) { |
|
192 | + $file['shareTypes'] = $shareTypes; |
|
193 | + } |
|
194 | + return $file; |
|
195 | + }, $nodes)); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get the share types for each node |
|
200 | + * |
|
201 | + * @param \OCP\Files\Node[] $nodes |
|
202 | + * @return array<int, int[]> list of share types for each fileid |
|
203 | + */ |
|
204 | + private function getShareTypesForNodes(array $nodes): array { |
|
205 | + $userId = $this->userSession->getUser()->getUID(); |
|
206 | + $requestedShareTypes = [ |
|
207 | + IShare::TYPE_USER, |
|
208 | + IShare::TYPE_GROUP, |
|
209 | + IShare::TYPE_LINK, |
|
210 | + IShare::TYPE_REMOTE, |
|
211 | + IShare::TYPE_EMAIL, |
|
212 | + IShare::TYPE_ROOM, |
|
213 | + IShare::TYPE_DECK, |
|
214 | + IShare::TYPE_SCIENCEMESH, |
|
215 | + ]; |
|
216 | + $shareTypes = []; |
|
217 | + |
|
218 | + $nodeIds = array_map(function (Node $node) { |
|
219 | + return $node->getId(); |
|
220 | + }, $nodes); |
|
221 | + |
|
222 | + foreach ($requestedShareTypes as $shareType) { |
|
223 | + $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
224 | + $offset = 0; |
|
225 | + |
|
226 | + // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
227 | + while (count($nodesLeft) > 0) { |
|
228 | + $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
229 | + foreach ($shares as $share) { |
|
230 | + $fileId = $share->getNodeId(); |
|
231 | + if (isset($nodesLeft[$fileId])) { |
|
232 | + if (!isset($shareTypes[$fileId])) { |
|
233 | + $shareTypes[$fileId] = []; |
|
234 | + } |
|
235 | + $shareTypes[$fileId][] = $shareType; |
|
236 | + unset($nodesLeft[$fileId]); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + if (count($shares) < 100) { |
|
241 | + break; |
|
242 | + } else { |
|
243 | + $offset += count($shares); |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + return $shareTypes; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns a list of recently modified files. |
|
252 | + * |
|
253 | + * @NoAdminRequired |
|
254 | + * |
|
255 | + * @return DataResponse |
|
256 | + */ |
|
257 | + public function getRecentFiles() { |
|
258 | + $nodes = $this->userFolder->getRecent(100); |
|
259 | + $files = $this->formatNodes($nodes); |
|
260 | + return new DataResponse(['files' => $files]); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Returns the current logged-in user's storage stats. |
|
266 | + * |
|
267 | + * @NoAdminRequired |
|
268 | + * |
|
269 | + * @param ?string $dir the directory to get the storage stats from |
|
270 | + * @return JSONResponse |
|
271 | + */ |
|
272 | + public function getStorageStats($dir = '/'): JSONResponse { |
|
273 | + $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
274 | + return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Change the default sort mode |
|
279 | + * |
|
280 | + * @NoAdminRequired |
|
281 | + * |
|
282 | + * @param string $mode |
|
283 | + * @param string $direction |
|
284 | + * @return JSONResponse |
|
285 | + * @throws \OCP\PreConditionNotMetException |
|
286 | + */ |
|
287 | + public function updateFileSorting($mode, string $direction = 'asc', string $view = 'files'): JSONResponse { |
|
288 | + $allowedDirection = ['asc', 'desc']; |
|
289 | + if (!in_array($direction, $allowedDirection)) { |
|
290 | + return new JSONResponse(['message' => 'Invalid direction parameter'], Http::STATUS_UNPROCESSABLE_ENTITY); |
|
291 | + } |
|
292 | + |
|
293 | + $userId = $this->userSession->getUser()->getUID(); |
|
294 | + |
|
295 | + $sortingJson = $this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'); |
|
296 | + $sortingConfig = json_decode($sortingJson, true) ?: []; |
|
297 | + $sortingConfig[$view] = [ |
|
298 | + 'mode' => $mode, |
|
299 | + 'direction' => $direction, |
|
300 | + ]; |
|
301 | + |
|
302 | + $this->config->setUserValue($userId, 'files', 'files_sorting_configs', json_encode($sortingConfig)); |
|
303 | + return new JSONResponse([ |
|
304 | + 'message' => 'ok', |
|
305 | + 'data' => $sortingConfig, |
|
306 | + ]); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Toggle default files user config |
|
311 | + * |
|
312 | + * @NoAdminRequired |
|
313 | + * |
|
314 | + * @param string $key |
|
315 | + * @param string|bool $value |
|
316 | + * @return JSONResponse |
|
317 | + */ |
|
318 | + public function setConfig(string $key, $value): JSONResponse { |
|
319 | + try { |
|
320 | + $this->userConfig->setConfig($key, (string)$value); |
|
321 | + } catch (\InvalidArgumentException $e) { |
|
322 | + return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
323 | + } |
|
324 | + |
|
325 | + return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Get the user config |
|
331 | + * |
|
332 | + * @NoAdminRequired |
|
333 | + * |
|
334 | + * @return JSONResponse |
|
335 | + */ |
|
336 | + public function getConfigs(): JSONResponse { |
|
337 | + return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Toggle default for showing/hiding hidden files |
|
342 | + * |
|
343 | + * @NoAdminRequired |
|
344 | + * |
|
345 | + * @param bool $value |
|
346 | + * @return Response |
|
347 | + * @throws \OCP\PreConditionNotMetException |
|
348 | + */ |
|
349 | + public function showHiddenFiles(bool $value): Response { |
|
350 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
351 | + return new Response(); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Toggle default for cropping preview images |
|
356 | + * |
|
357 | + * @NoAdminRequired |
|
358 | + * |
|
359 | + * @param bool $value |
|
360 | + * @return Response |
|
361 | + * @throws \OCP\PreConditionNotMetException |
|
362 | + */ |
|
363 | + public function cropImagePreviews(bool $value): Response { |
|
364 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
365 | + return new Response(); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Toggle default for files grid view |
|
370 | + * |
|
371 | + * @NoAdminRequired |
|
372 | + * |
|
373 | + * @param bool $show |
|
374 | + * @return Response |
|
375 | + * @throws \OCP\PreConditionNotMetException |
|
376 | + */ |
|
377 | + public function showGridView(bool $show): Response { |
|
378 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
379 | + return new Response(); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Get default settings for the grid view |
|
384 | + * |
|
385 | + * @NoAdminRequired |
|
386 | + */ |
|
387 | + public function getGridView() { |
|
388 | + $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
389 | + return new JSONResponse(['gridview' => $status]); |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Toggle default for showing/hiding xxx folder |
|
394 | + * |
|
395 | + * @NoAdminRequired |
|
396 | + * |
|
397 | + * @param int $show |
|
398 | + * @param string $key the key of the folder |
|
399 | + * |
|
400 | + * @return Response |
|
401 | + * @throws \OCP\PreConditionNotMetException |
|
402 | + */ |
|
403 | + public function toggleShowFolder(int $show, string $key): Response { |
|
404 | + if ($show !== 0 && $show !== 1) { |
|
405 | + return new DataResponse([ |
|
406 | + 'message' => 'Invalid show value. Only 0 and 1 are allowed.' |
|
407 | + ], Http::STATUS_BAD_REQUEST); |
|
408 | + } |
|
409 | + |
|
410 | + $userId = $this->userSession->getUser()->getUID(); |
|
411 | + |
|
412 | + // Set the new value and return it |
|
413 | + // Using a prefix prevents the user from setting arbitrary keys |
|
414 | + $this->config->setUserValue($userId, 'files', 'show_' . $key, (string)$show); |
|
415 | + return new JSONResponse([$key => $show]); |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Get sorting-order for custom sorting |
|
420 | + * |
|
421 | + * @NoAdminRequired |
|
422 | + * |
|
423 | + * @param string $folderpath |
|
424 | + * @return string |
|
425 | + * @throws \OCP\Files\NotFoundException |
|
426 | + */ |
|
427 | + public function getNodeType($folderpath) { |
|
428 | + $node = $this->userFolder->get($folderpath); |
|
429 | + return $node->getType(); |
|
430 | + } |
|
431 | 431 | |
432 | - /** |
|
433 | - * @NoAdminRequired |
|
434 | - * @NoCSRFRequired |
|
435 | - */ |
|
436 | - public function serviceWorker(): StreamResponse { |
|
437 | - $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js'); |
|
438 | - $response->setHeaders([ |
|
439 | - 'Content-Type' => 'application/javascript', |
|
440 | - 'Service-Worker-Allowed' => '/' |
|
441 | - ]); |
|
442 | - $policy = new ContentSecurityPolicy(); |
|
443 | - $policy->addAllowedWorkerSrcDomain("'self'"); |
|
444 | - $policy->addAllowedScriptDomain("'self'"); |
|
445 | - $policy->addAllowedConnectDomain("'self'"); |
|
446 | - $response->setContentSecurityPolicy($policy); |
|
447 | - return $response; |
|
448 | - } |
|
432 | + /** |
|
433 | + * @NoAdminRequired |
|
434 | + * @NoCSRFRequired |
|
435 | + */ |
|
436 | + public function serviceWorker(): StreamResponse { |
|
437 | + $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js'); |
|
438 | + $response->setHeaders([ |
|
439 | + 'Content-Type' => 'application/javascript', |
|
440 | + 'Service-Worker-Allowed' => '/' |
|
441 | + ]); |
|
442 | + $policy = new ContentSecurityPolicy(); |
|
443 | + $policy->addAllowedWorkerSrcDomain("'self'"); |
|
444 | + $policy->addAllowedScriptDomain("'self'"); |
|
445 | + $policy->addAllowedConnectDomain("'self'"); |
|
446 | + $response->setContentSecurityPolicy($policy); |
|
447 | + return $response; |
|
448 | + } |
|
449 | 449 | } |
@@ -67,350 +67,350 @@ |
||
67 | 67 | * @package OCA\Files\Controller |
68 | 68 | */ |
69 | 69 | class ViewController extends Controller { |
70 | - private IURLGenerator $urlGenerator; |
|
71 | - private IL10N $l10n; |
|
72 | - private IConfig $config; |
|
73 | - private IEventDispatcher $eventDispatcher; |
|
74 | - private IUserSession $userSession; |
|
75 | - private IAppManager $appManager; |
|
76 | - private IRootFolder $rootFolder; |
|
77 | - private Helper $activityHelper; |
|
78 | - private IInitialState $initialState; |
|
79 | - private ITemplateManager $templateManager; |
|
80 | - private IManager $shareManager; |
|
81 | - private UserConfig $userConfig; |
|
82 | - |
|
83 | - public function __construct(string $appName, |
|
84 | - IRequest $request, |
|
85 | - IURLGenerator $urlGenerator, |
|
86 | - IL10N $l10n, |
|
87 | - IConfig $config, |
|
88 | - IEventDispatcher $eventDispatcher, |
|
89 | - IUserSession $userSession, |
|
90 | - IAppManager $appManager, |
|
91 | - IRootFolder $rootFolder, |
|
92 | - Helper $activityHelper, |
|
93 | - IInitialState $initialState, |
|
94 | - ITemplateManager $templateManager, |
|
95 | - IManager $shareManager, |
|
96 | - UserConfig $userConfig |
|
97 | - ) { |
|
98 | - parent::__construct($appName, $request); |
|
99 | - $this->urlGenerator = $urlGenerator; |
|
100 | - $this->l10n = $l10n; |
|
101 | - $this->config = $config; |
|
102 | - $this->eventDispatcher = $eventDispatcher; |
|
103 | - $this->userSession = $userSession; |
|
104 | - $this->appManager = $appManager; |
|
105 | - $this->rootFolder = $rootFolder; |
|
106 | - $this->activityHelper = $activityHelper; |
|
107 | - $this->initialState = $initialState; |
|
108 | - $this->templateManager = $templateManager; |
|
109 | - $this->shareManager = $shareManager; |
|
110 | - $this->userConfig = $userConfig; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $appName |
|
115 | - * @param string $scriptName |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function renderScript($appName, $scriptName) { |
|
119 | - $content = ''; |
|
120 | - $appPath = \OC_App::getAppPath($appName); |
|
121 | - $scriptPath = $appPath . '/' . $scriptName; |
|
122 | - if (file_exists($scriptPath)) { |
|
123 | - // TODO: sanitize path / script name ? |
|
124 | - ob_start(); |
|
125 | - include $scriptPath; |
|
126 | - $content = ob_get_contents(); |
|
127 | - @ob_end_clean(); |
|
128 | - } |
|
129 | - |
|
130 | - return $content; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * FIXME: Replace with non static code |
|
135 | - * |
|
136 | - * @return array |
|
137 | - * @throws \OCP\Files\NotFoundException |
|
138 | - */ |
|
139 | - protected function getStorageInfo(string $dir = '/') { |
|
140 | - $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
141 | - |
|
142 | - return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @NoCSRFRequired |
|
147 | - * @NoAdminRequired |
|
148 | - * |
|
149 | - * @param string $fileid |
|
150 | - * @return TemplateResponse|RedirectResponse |
|
151 | - * @throws NotFoundException |
|
152 | - */ |
|
153 | - public function showFile(string $fileid = null, int $openfile = 1): Response { |
|
154 | - // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
155 | - try { |
|
156 | - return $this->redirectToFile($fileid, $openfile !== 0); |
|
157 | - } catch (NotFoundException $e) { |
|
158 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @NoCSRFRequired |
|
164 | - * @NoAdminRequired |
|
165 | - * @UseSession |
|
166 | - * |
|
167 | - * @param string $dir |
|
168 | - * @param string $view |
|
169 | - * @param string $fileid |
|
170 | - * @param bool $fileNotFound |
|
171 | - * @param string $openfile - the openfile URL parameter if it was present in the initial request |
|
172 | - * @return TemplateResponse|RedirectResponse |
|
173 | - * @throws NotFoundException |
|
174 | - */ |
|
175 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { |
|
176 | - |
|
177 | - if ($fileid !== null && $dir === '') { |
|
178 | - try { |
|
179 | - return $this->redirectToFile($fileid); |
|
180 | - } catch (NotFoundException $e) { |
|
181 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
186 | - |
|
187 | - // Load the files we need |
|
188 | - \OCP\Util::addStyle('files', 'merged'); |
|
189 | - \OCP\Util::addScript('files', 'merged-index', 'files'); |
|
190 | - \OCP\Util::addScript('files', 'main'); |
|
191 | - |
|
192 | - $userId = $this->userSession->getUser()->getUID(); |
|
193 | - |
|
194 | - // Get all the user favorites to create a submenu |
|
195 | - try { |
|
196 | - $favElements = $this->activityHelper->getFavoriteFilePaths($userId); |
|
197 | - } catch (\RuntimeException $e) { |
|
198 | - $favElements['folders'] = []; |
|
199 | - } |
|
200 | - |
|
201 | - $collapseClasses = ''; |
|
202 | - if (count($favElements['folders']) > 0) { |
|
203 | - $collapseClasses = 'collapsible'; |
|
204 | - } |
|
205 | - |
|
206 | - $favoritesSublistArray = []; |
|
207 | - |
|
208 | - $navBarPositionPosition = 6; |
|
209 | - foreach ($favElements['folders'] as $favElement) { |
|
210 | - $element = [ |
|
211 | - 'id' => str_replace('/', '-', $favElement), |
|
212 | - 'dir' => $favElement, |
|
213 | - 'order' => $navBarPositionPosition, |
|
214 | - 'name' => basename($favElement), |
|
215 | - 'icon' => 'folder', |
|
216 | - 'params' => [ |
|
217 | - 'view' => 'files', |
|
218 | - 'dir' => $favElement, |
|
219 | - ], |
|
220 | - ]; |
|
221 | - |
|
222 | - array_push($favoritesSublistArray, $element); |
|
223 | - $navBarPositionPosition++; |
|
224 | - } |
|
225 | - |
|
226 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
227 | - |
|
228 | - // add the favorites entry in menu |
|
229 | - $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
230 | - $navItems['favorites']['classes'] = $collapseClasses; |
|
231 | - |
|
232 | - // parse every menu and add the expanded user value |
|
233 | - foreach ($navItems as $key => $item) { |
|
234 | - $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1'; |
|
235 | - } |
|
236 | - |
|
237 | - $nav->assign('navigationItems', $navItems); |
|
238 | - |
|
239 | - $contentItems = []; |
|
240 | - |
|
241 | - try { |
|
242 | - // If view is files, we use the directory, otherwise we use the root storage |
|
243 | - $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
244 | - } catch(\Exception $e) { |
|
245 | - $storageInfo = $this->getStorageInfo(); |
|
246 | - } |
|
247 | - |
|
248 | - $this->initialState->provideInitialState('storageStats', $storageInfo); |
|
249 | - $this->initialState->provideInitialState('navigation', $navItems); |
|
250 | - $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); |
|
251 | - |
|
252 | - // File sorting user config |
|
253 | - $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true); |
|
254 | - $this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig); |
|
255 | - |
|
256 | - // render the container content for every navigation item |
|
257 | - foreach ($navItems as $item) { |
|
258 | - $content = ''; |
|
259 | - if (isset($item['script'])) { |
|
260 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
261 | - } |
|
262 | - // parse submenus |
|
263 | - if (isset($item['sublist'])) { |
|
264 | - foreach ($item['sublist'] as $subitem) { |
|
265 | - $subcontent = ''; |
|
266 | - if (isset($subitem['script'])) { |
|
267 | - $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
268 | - } |
|
269 | - $contentItems[$subitem['id']] = [ |
|
270 | - 'id' => $subitem['id'], |
|
271 | - 'content' => $subcontent |
|
272 | - ]; |
|
273 | - } |
|
274 | - } |
|
275 | - $contentItems[$item['id']] = [ |
|
276 | - 'id' => $item['id'], |
|
277 | - 'content' => $content |
|
278 | - ]; |
|
279 | - } |
|
280 | - |
|
281 | - $this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent()); |
|
282 | - $event = new LoadAdditionalScriptsEvent(); |
|
283 | - $this->eventDispatcher->dispatchTyped($event); |
|
284 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
285 | - // Load Viewer scripts |
|
286 | - if (class_exists(LoadViewer::class)) { |
|
287 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
288 | - } |
|
289 | - |
|
290 | - $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
291 | - $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
292 | - |
|
293 | - $params = []; |
|
294 | - $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
295 | - $params['owner'] = $storageInfo['owner'] ?? ''; |
|
296 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
297 | - $params['isPublic'] = false; |
|
298 | - $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
299 | - $params['defaultFileSorting'] = $filesSortingConfig['files']['mode'] ?? 'basename'; |
|
300 | - $params['defaultFileSortingDirection'] = $filesSortingConfig['files']['direction'] ?? 'asc'; |
|
301 | - $params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false); |
|
302 | - $showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false); |
|
303 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
304 | - $cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true); |
|
305 | - $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
306 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
307 | - $params['appNavigation'] = $nav; |
|
308 | - $params['appContents'] = $contentItems; |
|
309 | - $params['hiddenFields'] = $event->getHiddenFields(); |
|
310 | - |
|
311 | - $response = new TemplateResponse( |
|
312 | - Application::APP_ID, |
|
313 | - 'index', |
|
314 | - $params |
|
315 | - ); |
|
316 | - $policy = new ContentSecurityPolicy(); |
|
317 | - $policy->addAllowedFrameDomain('\'self\''); |
|
318 | - $response->setContentSecurityPolicy($policy); |
|
319 | - |
|
320 | - $this->provideInitialState($dir, $openfile); |
|
321 | - |
|
322 | - return $response; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Add openFileInfo in initialState if $openfile is set. |
|
327 | - * @param string $dir - the ?dir= URL param |
|
328 | - * @param string $openfile - the ?openfile= URL param |
|
329 | - * @return void |
|
330 | - */ |
|
331 | - private function provideInitialState(string $dir, ?string $openfile): void { |
|
332 | - if ($openfile === null) { |
|
333 | - return; |
|
334 | - } |
|
335 | - |
|
336 | - $user = $this->userSession->getUser(); |
|
337 | - |
|
338 | - if ($user === null) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - $uid = $user->getUID(); |
|
343 | - $userFolder = $this->rootFolder->getUserFolder($uid); |
|
344 | - $nodes = $userFolder->getById((int) $openfile); |
|
345 | - $node = array_shift($nodes); |
|
346 | - |
|
347 | - if ($node === null) { |
|
348 | - return; |
|
349 | - } |
|
350 | - |
|
351 | - // properly format full path and make sure |
|
352 | - // we're relative to the user home folder |
|
353 | - $isRoot = $node === $userFolder; |
|
354 | - $path = $userFolder->getRelativePath($node->getPath()); |
|
355 | - $directory = $userFolder->getRelativePath($node->getParent()->getPath()); |
|
356 | - |
|
357 | - // Prevent opening a file from another folder. |
|
358 | - if ($dir !== $directory) { |
|
359 | - return; |
|
360 | - } |
|
361 | - |
|
362 | - $this->initialState->provideInitialState( |
|
363 | - 'openFileInfo', [ |
|
364 | - 'id' => $node->getId(), |
|
365 | - 'name' => $isRoot ? '' : $node->getName(), |
|
366 | - 'path' => $path, |
|
367 | - 'directory' => $directory, |
|
368 | - 'mime' => $node->getMimetype(), |
|
369 | - 'type' => $node->getType(), |
|
370 | - 'permissions' => $node->getPermissions(), |
|
371 | - ] |
|
372 | - ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Redirects to the file list and highlight the given file id |
|
377 | - * |
|
378 | - * @param string $fileId file id to show |
|
379 | - * @param bool $setOpenfile - whether or not to set the openfile URL parameter |
|
380 | - * @return RedirectResponse redirect response or not found response |
|
381 | - * @throws \OCP\Files\NotFoundException |
|
382 | - */ |
|
383 | - private function redirectToFile($fileId, bool $setOpenfile = false) { |
|
384 | - $uid = $this->userSession->getUser()->getUID(); |
|
385 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
386 | - $files = $baseFolder->getById($fileId); |
|
387 | - $params = []; |
|
388 | - |
|
389 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
390 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
391 | - $files = $baseFolder->getById($fileId); |
|
392 | - $params['view'] = 'trashbin'; |
|
393 | - } |
|
394 | - |
|
395 | - if (!empty($files)) { |
|
396 | - $file = current($files); |
|
397 | - if ($file instanceof Folder) { |
|
398 | - // set the full path to enter the folder |
|
399 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
400 | - } else { |
|
401 | - // set parent path as dir |
|
402 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
403 | - // and scroll to the entry |
|
404 | - $params['scrollto'] = $file->getName(); |
|
405 | - |
|
406 | - if ($setOpenfile) { |
|
407 | - // forward the openfile URL parameter. |
|
408 | - $params['openfile'] = $fileId; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
413 | - } |
|
414 | - throw new \OCP\Files\NotFoundException(); |
|
415 | - } |
|
70 | + private IURLGenerator $urlGenerator; |
|
71 | + private IL10N $l10n; |
|
72 | + private IConfig $config; |
|
73 | + private IEventDispatcher $eventDispatcher; |
|
74 | + private IUserSession $userSession; |
|
75 | + private IAppManager $appManager; |
|
76 | + private IRootFolder $rootFolder; |
|
77 | + private Helper $activityHelper; |
|
78 | + private IInitialState $initialState; |
|
79 | + private ITemplateManager $templateManager; |
|
80 | + private IManager $shareManager; |
|
81 | + private UserConfig $userConfig; |
|
82 | + |
|
83 | + public function __construct(string $appName, |
|
84 | + IRequest $request, |
|
85 | + IURLGenerator $urlGenerator, |
|
86 | + IL10N $l10n, |
|
87 | + IConfig $config, |
|
88 | + IEventDispatcher $eventDispatcher, |
|
89 | + IUserSession $userSession, |
|
90 | + IAppManager $appManager, |
|
91 | + IRootFolder $rootFolder, |
|
92 | + Helper $activityHelper, |
|
93 | + IInitialState $initialState, |
|
94 | + ITemplateManager $templateManager, |
|
95 | + IManager $shareManager, |
|
96 | + UserConfig $userConfig |
|
97 | + ) { |
|
98 | + parent::__construct($appName, $request); |
|
99 | + $this->urlGenerator = $urlGenerator; |
|
100 | + $this->l10n = $l10n; |
|
101 | + $this->config = $config; |
|
102 | + $this->eventDispatcher = $eventDispatcher; |
|
103 | + $this->userSession = $userSession; |
|
104 | + $this->appManager = $appManager; |
|
105 | + $this->rootFolder = $rootFolder; |
|
106 | + $this->activityHelper = $activityHelper; |
|
107 | + $this->initialState = $initialState; |
|
108 | + $this->templateManager = $templateManager; |
|
109 | + $this->shareManager = $shareManager; |
|
110 | + $this->userConfig = $userConfig; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $appName |
|
115 | + * @param string $scriptName |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function renderScript($appName, $scriptName) { |
|
119 | + $content = ''; |
|
120 | + $appPath = \OC_App::getAppPath($appName); |
|
121 | + $scriptPath = $appPath . '/' . $scriptName; |
|
122 | + if (file_exists($scriptPath)) { |
|
123 | + // TODO: sanitize path / script name ? |
|
124 | + ob_start(); |
|
125 | + include $scriptPath; |
|
126 | + $content = ob_get_contents(); |
|
127 | + @ob_end_clean(); |
|
128 | + } |
|
129 | + |
|
130 | + return $content; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * FIXME: Replace with non static code |
|
135 | + * |
|
136 | + * @return array |
|
137 | + * @throws \OCP\Files\NotFoundException |
|
138 | + */ |
|
139 | + protected function getStorageInfo(string $dir = '/') { |
|
140 | + $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
141 | + |
|
142 | + return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @NoCSRFRequired |
|
147 | + * @NoAdminRequired |
|
148 | + * |
|
149 | + * @param string $fileid |
|
150 | + * @return TemplateResponse|RedirectResponse |
|
151 | + * @throws NotFoundException |
|
152 | + */ |
|
153 | + public function showFile(string $fileid = null, int $openfile = 1): Response { |
|
154 | + // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
155 | + try { |
|
156 | + return $this->redirectToFile($fileid, $openfile !== 0); |
|
157 | + } catch (NotFoundException $e) { |
|
158 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @NoCSRFRequired |
|
164 | + * @NoAdminRequired |
|
165 | + * @UseSession |
|
166 | + * |
|
167 | + * @param string $dir |
|
168 | + * @param string $view |
|
169 | + * @param string $fileid |
|
170 | + * @param bool $fileNotFound |
|
171 | + * @param string $openfile - the openfile URL parameter if it was present in the initial request |
|
172 | + * @return TemplateResponse|RedirectResponse |
|
173 | + * @throws NotFoundException |
|
174 | + */ |
|
175 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { |
|
176 | + |
|
177 | + if ($fileid !== null && $dir === '') { |
|
178 | + try { |
|
179 | + return $this->redirectToFile($fileid); |
|
180 | + } catch (NotFoundException $e) { |
|
181 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
186 | + |
|
187 | + // Load the files we need |
|
188 | + \OCP\Util::addStyle('files', 'merged'); |
|
189 | + \OCP\Util::addScript('files', 'merged-index', 'files'); |
|
190 | + \OCP\Util::addScript('files', 'main'); |
|
191 | + |
|
192 | + $userId = $this->userSession->getUser()->getUID(); |
|
193 | + |
|
194 | + // Get all the user favorites to create a submenu |
|
195 | + try { |
|
196 | + $favElements = $this->activityHelper->getFavoriteFilePaths($userId); |
|
197 | + } catch (\RuntimeException $e) { |
|
198 | + $favElements['folders'] = []; |
|
199 | + } |
|
200 | + |
|
201 | + $collapseClasses = ''; |
|
202 | + if (count($favElements['folders']) > 0) { |
|
203 | + $collapseClasses = 'collapsible'; |
|
204 | + } |
|
205 | + |
|
206 | + $favoritesSublistArray = []; |
|
207 | + |
|
208 | + $navBarPositionPosition = 6; |
|
209 | + foreach ($favElements['folders'] as $favElement) { |
|
210 | + $element = [ |
|
211 | + 'id' => str_replace('/', '-', $favElement), |
|
212 | + 'dir' => $favElement, |
|
213 | + 'order' => $navBarPositionPosition, |
|
214 | + 'name' => basename($favElement), |
|
215 | + 'icon' => 'folder', |
|
216 | + 'params' => [ |
|
217 | + 'view' => 'files', |
|
218 | + 'dir' => $favElement, |
|
219 | + ], |
|
220 | + ]; |
|
221 | + |
|
222 | + array_push($favoritesSublistArray, $element); |
|
223 | + $navBarPositionPosition++; |
|
224 | + } |
|
225 | + |
|
226 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
227 | + |
|
228 | + // add the favorites entry in menu |
|
229 | + $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
230 | + $navItems['favorites']['classes'] = $collapseClasses; |
|
231 | + |
|
232 | + // parse every menu and add the expanded user value |
|
233 | + foreach ($navItems as $key => $item) { |
|
234 | + $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1'; |
|
235 | + } |
|
236 | + |
|
237 | + $nav->assign('navigationItems', $navItems); |
|
238 | + |
|
239 | + $contentItems = []; |
|
240 | + |
|
241 | + try { |
|
242 | + // If view is files, we use the directory, otherwise we use the root storage |
|
243 | + $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
244 | + } catch(\Exception $e) { |
|
245 | + $storageInfo = $this->getStorageInfo(); |
|
246 | + } |
|
247 | + |
|
248 | + $this->initialState->provideInitialState('storageStats', $storageInfo); |
|
249 | + $this->initialState->provideInitialState('navigation', $navItems); |
|
250 | + $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); |
|
251 | + |
|
252 | + // File sorting user config |
|
253 | + $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true); |
|
254 | + $this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig); |
|
255 | + |
|
256 | + // render the container content for every navigation item |
|
257 | + foreach ($navItems as $item) { |
|
258 | + $content = ''; |
|
259 | + if (isset($item['script'])) { |
|
260 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
261 | + } |
|
262 | + // parse submenus |
|
263 | + if (isset($item['sublist'])) { |
|
264 | + foreach ($item['sublist'] as $subitem) { |
|
265 | + $subcontent = ''; |
|
266 | + if (isset($subitem['script'])) { |
|
267 | + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
268 | + } |
|
269 | + $contentItems[$subitem['id']] = [ |
|
270 | + 'id' => $subitem['id'], |
|
271 | + 'content' => $subcontent |
|
272 | + ]; |
|
273 | + } |
|
274 | + } |
|
275 | + $contentItems[$item['id']] = [ |
|
276 | + 'id' => $item['id'], |
|
277 | + 'content' => $content |
|
278 | + ]; |
|
279 | + } |
|
280 | + |
|
281 | + $this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent()); |
|
282 | + $event = new LoadAdditionalScriptsEvent(); |
|
283 | + $this->eventDispatcher->dispatchTyped($event); |
|
284 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
285 | + // Load Viewer scripts |
|
286 | + if (class_exists(LoadViewer::class)) { |
|
287 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
288 | + } |
|
289 | + |
|
290 | + $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
291 | + $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
292 | + |
|
293 | + $params = []; |
|
294 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
295 | + $params['owner'] = $storageInfo['owner'] ?? ''; |
|
296 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
297 | + $params['isPublic'] = false; |
|
298 | + $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
299 | + $params['defaultFileSorting'] = $filesSortingConfig['files']['mode'] ?? 'basename'; |
|
300 | + $params['defaultFileSortingDirection'] = $filesSortingConfig['files']['direction'] ?? 'asc'; |
|
301 | + $params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false); |
|
302 | + $showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false); |
|
303 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
304 | + $cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true); |
|
305 | + $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
306 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
307 | + $params['appNavigation'] = $nav; |
|
308 | + $params['appContents'] = $contentItems; |
|
309 | + $params['hiddenFields'] = $event->getHiddenFields(); |
|
310 | + |
|
311 | + $response = new TemplateResponse( |
|
312 | + Application::APP_ID, |
|
313 | + 'index', |
|
314 | + $params |
|
315 | + ); |
|
316 | + $policy = new ContentSecurityPolicy(); |
|
317 | + $policy->addAllowedFrameDomain('\'self\''); |
|
318 | + $response->setContentSecurityPolicy($policy); |
|
319 | + |
|
320 | + $this->provideInitialState($dir, $openfile); |
|
321 | + |
|
322 | + return $response; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Add openFileInfo in initialState if $openfile is set. |
|
327 | + * @param string $dir - the ?dir= URL param |
|
328 | + * @param string $openfile - the ?openfile= URL param |
|
329 | + * @return void |
|
330 | + */ |
|
331 | + private function provideInitialState(string $dir, ?string $openfile): void { |
|
332 | + if ($openfile === null) { |
|
333 | + return; |
|
334 | + } |
|
335 | + |
|
336 | + $user = $this->userSession->getUser(); |
|
337 | + |
|
338 | + if ($user === null) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + $uid = $user->getUID(); |
|
343 | + $userFolder = $this->rootFolder->getUserFolder($uid); |
|
344 | + $nodes = $userFolder->getById((int) $openfile); |
|
345 | + $node = array_shift($nodes); |
|
346 | + |
|
347 | + if ($node === null) { |
|
348 | + return; |
|
349 | + } |
|
350 | + |
|
351 | + // properly format full path and make sure |
|
352 | + // we're relative to the user home folder |
|
353 | + $isRoot = $node === $userFolder; |
|
354 | + $path = $userFolder->getRelativePath($node->getPath()); |
|
355 | + $directory = $userFolder->getRelativePath($node->getParent()->getPath()); |
|
356 | + |
|
357 | + // Prevent opening a file from another folder. |
|
358 | + if ($dir !== $directory) { |
|
359 | + return; |
|
360 | + } |
|
361 | + |
|
362 | + $this->initialState->provideInitialState( |
|
363 | + 'openFileInfo', [ |
|
364 | + 'id' => $node->getId(), |
|
365 | + 'name' => $isRoot ? '' : $node->getName(), |
|
366 | + 'path' => $path, |
|
367 | + 'directory' => $directory, |
|
368 | + 'mime' => $node->getMimetype(), |
|
369 | + 'type' => $node->getType(), |
|
370 | + 'permissions' => $node->getPermissions(), |
|
371 | + ] |
|
372 | + ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Redirects to the file list and highlight the given file id |
|
377 | + * |
|
378 | + * @param string $fileId file id to show |
|
379 | + * @param bool $setOpenfile - whether or not to set the openfile URL parameter |
|
380 | + * @return RedirectResponse redirect response or not found response |
|
381 | + * @throws \OCP\Files\NotFoundException |
|
382 | + */ |
|
383 | + private function redirectToFile($fileId, bool $setOpenfile = false) { |
|
384 | + $uid = $this->userSession->getUser()->getUID(); |
|
385 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
386 | + $files = $baseFolder->getById($fileId); |
|
387 | + $params = []; |
|
388 | + |
|
389 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
390 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
391 | + $files = $baseFolder->getById($fileId); |
|
392 | + $params['view'] = 'trashbin'; |
|
393 | + } |
|
394 | + |
|
395 | + if (!empty($files)) { |
|
396 | + $file = current($files); |
|
397 | + if ($file instanceof Folder) { |
|
398 | + // set the full path to enter the folder |
|
399 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
400 | + } else { |
|
401 | + // set parent path as dir |
|
402 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
403 | + // and scroll to the entry |
|
404 | + $params['scrollto'] = $file->getName(); |
|
405 | + |
|
406 | + if ($setOpenfile) { |
|
407 | + // forward the openfile URL parameter. |
|
408 | + $params['openfile'] = $fileId; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
413 | + } |
|
414 | + throw new \OCP\Files\NotFoundException(); |
|
415 | + } |
|
416 | 416 | } |
@@ -42,178 +42,178 @@ |
||
42 | 42 | // Legacy routes above |
43 | 43 | /** @var \OC\Route\Router $this */ |
44 | 44 | $this->create('files_ajax_download', 'apps/files/ajax/download.php') |
45 | - ->actionInclude('files/ajax/download.php'); |
|
45 | + ->actionInclude('files/ajax/download.php'); |
|
46 | 46 | |
47 | 47 | /** @var Application $application */ |
48 | 48 | $application = \OC::$server->get(Application::class); |
49 | 49 | $application->registerRoutes( |
50 | - $this, |
|
51 | - [ |
|
52 | - 'routes' => [ |
|
53 | - [ |
|
54 | - 'name' => 'view#index', |
|
55 | - 'url' => '/', |
|
56 | - 'verb' => 'GET', |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'View#showFile', |
|
60 | - 'url' => '/f/{fileid}', |
|
61 | - 'verb' => 'GET', |
|
62 | - 'root' => '', |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'API#getThumbnail', |
|
66 | - 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', |
|
67 | - 'verb' => 'GET', |
|
68 | - 'requirements' => ['file' => '.+'] |
|
69 | - ], |
|
70 | - [ |
|
71 | - 'name' => 'API#updateFileTags', |
|
72 | - 'url' => '/api/v1/files/{path}', |
|
73 | - 'verb' => 'POST', |
|
74 | - 'requirements' => ['path' => '.+'], |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'name' => 'API#getRecentFiles', |
|
78 | - 'url' => '/api/v1/recent/', |
|
79 | - 'verb' => 'GET' |
|
80 | - ], |
|
81 | - [ |
|
82 | - 'name' => 'API#getStorageStats', |
|
83 | - 'url' => '/api/v1/stats', |
|
84 | - 'verb' => 'GET' |
|
85 | - ], |
|
86 | - [ |
|
87 | - 'name' => 'API#setConfig', |
|
88 | - 'url' => '/api/v1/config/{key}', |
|
89 | - 'verb' => 'POST' |
|
90 | - ], |
|
91 | - [ |
|
92 | - 'name' => 'API#getConfigs', |
|
93 | - 'url' => '/api/v1/configs', |
|
94 | - 'verb' => 'GET' |
|
95 | - ], |
|
96 | - [ |
|
97 | - 'name' => 'API#updateFileSorting', |
|
98 | - 'url' => '/api/v1/sorting', |
|
99 | - 'verb' => 'POST' |
|
100 | - ], |
|
101 | - [ |
|
102 | - 'name' => 'API#showHiddenFiles', |
|
103 | - 'url' => '/api/v1/showhidden', |
|
104 | - 'verb' => 'POST' |
|
105 | - ], |
|
106 | - [ |
|
107 | - 'name' => 'API#cropImagePreviews', |
|
108 | - 'url' => '/api/v1/cropimagepreviews', |
|
109 | - 'verb' => 'POST' |
|
110 | - ], |
|
111 | - [ |
|
112 | - 'name' => 'API#showGridView', |
|
113 | - 'url' => '/api/v1/showgridview', |
|
114 | - 'verb' => 'POST' |
|
115 | - ], |
|
116 | - [ |
|
117 | - 'name' => 'API#getGridView', |
|
118 | - 'url' => '/api/v1/showgridview', |
|
119 | - 'verb' => 'GET' |
|
120 | - ], |
|
121 | - [ |
|
122 | - 'name' => 'API#toggleShowFolder', |
|
123 | - 'url' => '/api/v1/toggleShowFolder/{key}', |
|
124 | - 'verb' => 'POST' |
|
125 | - ], |
|
126 | - [ |
|
127 | - 'name' => 'API#getNodeType', |
|
128 | - 'url' => '/api/v1/quickaccess/get/NodeType', |
|
129 | - 'verb' => 'GET', |
|
130 | - ], |
|
131 | - [ |
|
132 | - 'name' => 'DirectEditingView#edit', |
|
133 | - 'url' => '/directEditing/{token}', |
|
134 | - 'verb' => 'GET' |
|
135 | - ], |
|
136 | - [ |
|
137 | - 'name' => 'api#serviceWorker', |
|
138 | - 'url' => '/preview-service-worker.js', |
|
139 | - 'verb' => 'GET' |
|
140 | - ], |
|
141 | - [ |
|
142 | - 'name' => 'view#index', |
|
143 | - 'url' => '/{view}', |
|
144 | - 'verb' => 'GET', |
|
145 | - 'postfix' => 'view', |
|
146 | - ], |
|
147 | - [ |
|
148 | - 'name' => 'view#index', |
|
149 | - 'url' => '/{view}/{fileid}', |
|
150 | - 'verb' => 'GET', |
|
151 | - 'postfix' => 'fileid', |
|
152 | - ], |
|
153 | - ], |
|
154 | - 'ocs' => [ |
|
155 | - [ |
|
156 | - 'name' => 'DirectEditing#info', |
|
157 | - 'url' => '/api/v1/directEditing', |
|
158 | - 'verb' => 'GET' |
|
159 | - ], |
|
160 | - [ |
|
161 | - 'name' => 'DirectEditing#templates', |
|
162 | - 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', |
|
163 | - 'verb' => 'GET' |
|
164 | - ], |
|
165 | - [ |
|
166 | - 'name' => 'DirectEditing#open', |
|
167 | - 'url' => '/api/v1/directEditing/open', |
|
168 | - 'verb' => 'POST' |
|
169 | - ], |
|
170 | - [ |
|
171 | - 'name' => 'DirectEditing#create', |
|
172 | - 'url' => '/api/v1/directEditing/create', |
|
173 | - 'verb' => 'POST' |
|
174 | - ], |
|
175 | - [ |
|
176 | - 'name' => 'Template#list', |
|
177 | - 'url' => '/api/v1/templates', |
|
178 | - 'verb' => 'GET' |
|
179 | - ], |
|
180 | - [ |
|
181 | - 'name' => 'Template#create', |
|
182 | - 'url' => '/api/v1/templates/create', |
|
183 | - 'verb' => 'POST' |
|
184 | - ], |
|
185 | - [ |
|
186 | - 'name' => 'Template#path', |
|
187 | - 'url' => '/api/v1/templates/path', |
|
188 | - 'verb' => 'POST' |
|
189 | - ], |
|
190 | - [ |
|
191 | - 'name' => 'TransferOwnership#transfer', |
|
192 | - 'url' => '/api/v1/transferownership', |
|
193 | - 'verb' => 'POST', |
|
194 | - ], |
|
195 | - [ |
|
196 | - 'name' => 'TransferOwnership#accept', |
|
197 | - 'url' => '/api/v1/transferownership/{id}', |
|
198 | - 'verb' => 'POST', |
|
199 | - ], |
|
200 | - [ |
|
201 | - 'name' => 'TransferOwnership#reject', |
|
202 | - 'url' => '/api/v1/transferownership/{id}', |
|
203 | - 'verb' => 'DELETE', |
|
204 | - ], |
|
205 | - [ |
|
206 | - /** @see OpenLocalEditorController::create() */ |
|
207 | - 'name' => 'OpenLocalEditor#create', |
|
208 | - 'url' => '/api/v1/openlocaleditor', |
|
209 | - 'verb' => 'POST', |
|
210 | - ], |
|
211 | - [ |
|
212 | - /** @see OpenLocalEditorController::validate() */ |
|
213 | - 'name' => 'OpenLocalEditor#validate', |
|
214 | - 'url' => '/api/v1/openlocaleditor/{token}', |
|
215 | - 'verb' => 'POST', |
|
216 | - ], |
|
217 | - ], |
|
218 | - ] |
|
50 | + $this, |
|
51 | + [ |
|
52 | + 'routes' => [ |
|
53 | + [ |
|
54 | + 'name' => 'view#index', |
|
55 | + 'url' => '/', |
|
56 | + 'verb' => 'GET', |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'View#showFile', |
|
60 | + 'url' => '/f/{fileid}', |
|
61 | + 'verb' => 'GET', |
|
62 | + 'root' => '', |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'API#getThumbnail', |
|
66 | + 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', |
|
67 | + 'verb' => 'GET', |
|
68 | + 'requirements' => ['file' => '.+'] |
|
69 | + ], |
|
70 | + [ |
|
71 | + 'name' => 'API#updateFileTags', |
|
72 | + 'url' => '/api/v1/files/{path}', |
|
73 | + 'verb' => 'POST', |
|
74 | + 'requirements' => ['path' => '.+'], |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'name' => 'API#getRecentFiles', |
|
78 | + 'url' => '/api/v1/recent/', |
|
79 | + 'verb' => 'GET' |
|
80 | + ], |
|
81 | + [ |
|
82 | + 'name' => 'API#getStorageStats', |
|
83 | + 'url' => '/api/v1/stats', |
|
84 | + 'verb' => 'GET' |
|
85 | + ], |
|
86 | + [ |
|
87 | + 'name' => 'API#setConfig', |
|
88 | + 'url' => '/api/v1/config/{key}', |
|
89 | + 'verb' => 'POST' |
|
90 | + ], |
|
91 | + [ |
|
92 | + 'name' => 'API#getConfigs', |
|
93 | + 'url' => '/api/v1/configs', |
|
94 | + 'verb' => 'GET' |
|
95 | + ], |
|
96 | + [ |
|
97 | + 'name' => 'API#updateFileSorting', |
|
98 | + 'url' => '/api/v1/sorting', |
|
99 | + 'verb' => 'POST' |
|
100 | + ], |
|
101 | + [ |
|
102 | + 'name' => 'API#showHiddenFiles', |
|
103 | + 'url' => '/api/v1/showhidden', |
|
104 | + 'verb' => 'POST' |
|
105 | + ], |
|
106 | + [ |
|
107 | + 'name' => 'API#cropImagePreviews', |
|
108 | + 'url' => '/api/v1/cropimagepreviews', |
|
109 | + 'verb' => 'POST' |
|
110 | + ], |
|
111 | + [ |
|
112 | + 'name' => 'API#showGridView', |
|
113 | + 'url' => '/api/v1/showgridview', |
|
114 | + 'verb' => 'POST' |
|
115 | + ], |
|
116 | + [ |
|
117 | + 'name' => 'API#getGridView', |
|
118 | + 'url' => '/api/v1/showgridview', |
|
119 | + 'verb' => 'GET' |
|
120 | + ], |
|
121 | + [ |
|
122 | + 'name' => 'API#toggleShowFolder', |
|
123 | + 'url' => '/api/v1/toggleShowFolder/{key}', |
|
124 | + 'verb' => 'POST' |
|
125 | + ], |
|
126 | + [ |
|
127 | + 'name' => 'API#getNodeType', |
|
128 | + 'url' => '/api/v1/quickaccess/get/NodeType', |
|
129 | + 'verb' => 'GET', |
|
130 | + ], |
|
131 | + [ |
|
132 | + 'name' => 'DirectEditingView#edit', |
|
133 | + 'url' => '/directEditing/{token}', |
|
134 | + 'verb' => 'GET' |
|
135 | + ], |
|
136 | + [ |
|
137 | + 'name' => 'api#serviceWorker', |
|
138 | + 'url' => '/preview-service-worker.js', |
|
139 | + 'verb' => 'GET' |
|
140 | + ], |
|
141 | + [ |
|
142 | + 'name' => 'view#index', |
|
143 | + 'url' => '/{view}', |
|
144 | + 'verb' => 'GET', |
|
145 | + 'postfix' => 'view', |
|
146 | + ], |
|
147 | + [ |
|
148 | + 'name' => 'view#index', |
|
149 | + 'url' => '/{view}/{fileid}', |
|
150 | + 'verb' => 'GET', |
|
151 | + 'postfix' => 'fileid', |
|
152 | + ], |
|
153 | + ], |
|
154 | + 'ocs' => [ |
|
155 | + [ |
|
156 | + 'name' => 'DirectEditing#info', |
|
157 | + 'url' => '/api/v1/directEditing', |
|
158 | + 'verb' => 'GET' |
|
159 | + ], |
|
160 | + [ |
|
161 | + 'name' => 'DirectEditing#templates', |
|
162 | + 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', |
|
163 | + 'verb' => 'GET' |
|
164 | + ], |
|
165 | + [ |
|
166 | + 'name' => 'DirectEditing#open', |
|
167 | + 'url' => '/api/v1/directEditing/open', |
|
168 | + 'verb' => 'POST' |
|
169 | + ], |
|
170 | + [ |
|
171 | + 'name' => 'DirectEditing#create', |
|
172 | + 'url' => '/api/v1/directEditing/create', |
|
173 | + 'verb' => 'POST' |
|
174 | + ], |
|
175 | + [ |
|
176 | + 'name' => 'Template#list', |
|
177 | + 'url' => '/api/v1/templates', |
|
178 | + 'verb' => 'GET' |
|
179 | + ], |
|
180 | + [ |
|
181 | + 'name' => 'Template#create', |
|
182 | + 'url' => '/api/v1/templates/create', |
|
183 | + 'verb' => 'POST' |
|
184 | + ], |
|
185 | + [ |
|
186 | + 'name' => 'Template#path', |
|
187 | + 'url' => '/api/v1/templates/path', |
|
188 | + 'verb' => 'POST' |
|
189 | + ], |
|
190 | + [ |
|
191 | + 'name' => 'TransferOwnership#transfer', |
|
192 | + 'url' => '/api/v1/transferownership', |
|
193 | + 'verb' => 'POST', |
|
194 | + ], |
|
195 | + [ |
|
196 | + 'name' => 'TransferOwnership#accept', |
|
197 | + 'url' => '/api/v1/transferownership/{id}', |
|
198 | + 'verb' => 'POST', |
|
199 | + ], |
|
200 | + [ |
|
201 | + 'name' => 'TransferOwnership#reject', |
|
202 | + 'url' => '/api/v1/transferownership/{id}', |
|
203 | + 'verb' => 'DELETE', |
|
204 | + ], |
|
205 | + [ |
|
206 | + /** @see OpenLocalEditorController::create() */ |
|
207 | + 'name' => 'OpenLocalEditor#create', |
|
208 | + 'url' => '/api/v1/openlocaleditor', |
|
209 | + 'verb' => 'POST', |
|
210 | + ], |
|
211 | + [ |
|
212 | + /** @see OpenLocalEditorController::validate() */ |
|
213 | + 'name' => 'OpenLocalEditor#validate', |
|
214 | + 'url' => '/api/v1/openlocaleditor/{token}', |
|
215 | + 'verb' => 'POST', |
|
216 | + ], |
|
217 | + ], |
|
218 | + ] |
|
219 | 219 | ); |
@@ -42,58 +42,58 @@ |
||
42 | 42 | use OCP\IServerContainer; |
43 | 43 | |
44 | 44 | class Application extends App implements IBootstrap { |
45 | - public const APP_ID = 'files_trashbin'; |
|
45 | + public const APP_ID = 'files_trashbin'; |
|
46 | 46 | |
47 | - public function __construct(array $urlParams = []) { |
|
48 | - parent::__construct(self::APP_ID, $urlParams); |
|
49 | - } |
|
47 | + public function __construct(array $urlParams = []) { |
|
48 | + parent::__construct(self::APP_ID, $urlParams); |
|
49 | + } |
|
50 | 50 | |
51 | - public function register(IRegistrationContext $context): void { |
|
52 | - $context->registerCapability(Capabilities::class); |
|
51 | + public function register(IRegistrationContext $context): void { |
|
52 | + $context->registerCapability(Capabilities::class); |
|
53 | 53 | |
54 | - $context->registerServiceAlias('Expiration', Expiration::class); |
|
55 | - $context->registerServiceAlias(ITrashManager::class, TrashManager::class); |
|
56 | - /** Register $principalBackend for the DAV collection */ |
|
57 | - $context->registerServiceAlias('principalBackend', Principal::class); |
|
54 | + $context->registerServiceAlias('Expiration', Expiration::class); |
|
55 | + $context->registerServiceAlias(ITrashManager::class, TrashManager::class); |
|
56 | + /** Register $principalBackend for the DAV collection */ |
|
57 | + $context->registerServiceAlias('principalBackend', Principal::class); |
|
58 | 58 | |
59 | - $context->registerUserMigrator(TrashbinMigrator::class); |
|
59 | + $context->registerUserMigrator(TrashbinMigrator::class); |
|
60 | 60 | |
61 | - $context->registerEventListener( |
|
62 | - LoadAdditionalScriptsEvent::class, |
|
63 | - LoadAdditionalScripts::class |
|
64 | - ); |
|
65 | - } |
|
61 | + $context->registerEventListener( |
|
62 | + LoadAdditionalScriptsEvent::class, |
|
63 | + LoadAdditionalScripts::class |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | - public function boot(IBootContext $context): void { |
|
68 | - $context->injectFn([$this, 'registerTrashBackends']); |
|
67 | + public function boot(IBootContext $context): void { |
|
68 | + $context->injectFn([$this, 'registerTrashBackends']); |
|
69 | 69 | |
70 | - // create storage wrapper on setup |
|
71 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage'); |
|
72 | - //Listen to delete user signal |
|
73 | - \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook'); |
|
74 | - //Listen to post write hook |
|
75 | - \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); |
|
76 | - // pre and post-rename, disable trash logic for the copy+unlink case |
|
77 | - \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); |
|
78 | - } |
|
70 | + // create storage wrapper on setup |
|
71 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage'); |
|
72 | + //Listen to delete user signal |
|
73 | + \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook'); |
|
74 | + //Listen to post write hook |
|
75 | + \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); |
|
76 | + // pre and post-rename, disable trash logic for the copy+unlink case |
|
77 | + \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); |
|
78 | + } |
|
79 | 79 | |
80 | - public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) { |
|
81 | - foreach ($appManager->getInstalledApps() as $app) { |
|
82 | - $appInfo = $appManager->getAppInfo($app); |
|
83 | - if (isset($appInfo['trash'])) { |
|
84 | - $backends = $appInfo['trash']; |
|
85 | - foreach ($backends as $backend) { |
|
86 | - $class = $backend['@value']; |
|
87 | - $for = $backend['@attributes']['for']; |
|
80 | + public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) { |
|
81 | + foreach ($appManager->getInstalledApps() as $app) { |
|
82 | + $appInfo = $appManager->getAppInfo($app); |
|
83 | + if (isset($appInfo['trash'])) { |
|
84 | + $backends = $appInfo['trash']; |
|
85 | + foreach ($backends as $backend) { |
|
86 | + $class = $backend['@value']; |
|
87 | + $for = $backend['@attributes']['for']; |
|
88 | 88 | |
89 | - try { |
|
90 | - $backendObject = $serverContainer->query($class); |
|
91 | - $trashManager->registerBackend($for, $backendObject); |
|
92 | - } catch (\Exception $e) { |
|
93 | - $logger->logException($e); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
89 | + try { |
|
90 | + $backendObject = $serverContainer->query($class); |
|
91 | + $trashManager->registerBackend($for, $backendObject); |
|
92 | + } catch (\Exception $e) { |
|
93 | + $logger->logException($e); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
@@ -31,11 +31,11 @@ |
||
31 | 31 | use OCP\Util; |
32 | 32 | |
33 | 33 | class LoadAdditionalScripts implements IEventListener { |
34 | - public function handle(Event $event): void { |
|
35 | - if (!($event instanceof LoadAdditionalScriptsEvent)) { |
|
36 | - return; |
|
37 | - } |
|
34 | + public function handle(Event $event): void { |
|
35 | + if (!($event instanceof LoadAdditionalScriptsEvent)) { |
|
36 | + return; |
|
37 | + } |
|
38 | 38 | |
39 | - Util::addScript(Application::APP_ID, 'main'); |
|
40 | - } |
|
39 | + Util::addScript(Application::APP_ID, 'main'); |
|
40 | + } |
|
41 | 41 | } |
@@ -43,92 +43,92 @@ |
||
43 | 43 | use OCP\IUserSession; |
44 | 44 | |
45 | 45 | class PreviewController extends Controller { |
46 | - /** @var IRootFolder */ |
|
47 | - private $rootFolder; |
|
48 | - |
|
49 | - /** @var ITrashManager */ |
|
50 | - private $trashManager; |
|
51 | - |
|
52 | - /** @var IUserSession */ |
|
53 | - private $userSession; |
|
54 | - |
|
55 | - /** @var IMimeTypeDetector */ |
|
56 | - private $mimeTypeDetector; |
|
57 | - |
|
58 | - /** @var IPreview */ |
|
59 | - private $previewManager; |
|
60 | - |
|
61 | - /** @var ITimeFactory */ |
|
62 | - private $time; |
|
63 | - |
|
64 | - public function __construct( |
|
65 | - string $appName, |
|
66 | - IRequest $request, |
|
67 | - IRootFolder $rootFolder, |
|
68 | - ITrashManager $trashManager, |
|
69 | - IUserSession $userSession, |
|
70 | - IMimeTypeDetector $mimeTypeDetector, |
|
71 | - IPreview $previewManager, |
|
72 | - ITimeFactory $time |
|
73 | - ) { |
|
74 | - parent::__construct($appName, $request); |
|
75 | - |
|
76 | - $this->trashManager = $trashManager; |
|
77 | - $this->rootFolder = $rootFolder; |
|
78 | - $this->userSession = $userSession; |
|
79 | - $this->mimeTypeDetector = $mimeTypeDetector; |
|
80 | - $this->previewManager = $previewManager; |
|
81 | - $this->time = $time; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @NoAdminRequired |
|
86 | - * @NoCSRFRequired |
|
87 | - * |
|
88 | - * @return DataResponse|Http\FileDisplayResponse |
|
89 | - */ |
|
90 | - public function getPreview( |
|
91 | - int $fileId = -1, |
|
92 | - int $x = 32, |
|
93 | - int $y = 32, |
|
94 | - bool $a = false, |
|
95 | - ) { |
|
96 | - if ($fileId === -1 || $x === 0 || $y === 0) { |
|
97 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | - } |
|
99 | - |
|
100 | - try { |
|
101 | - $file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId); |
|
102 | - if ($file === null) { |
|
103 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
104 | - } |
|
105 | - if ($file instanceof Folder) { |
|
106 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
107 | - } |
|
108 | - |
|
109 | - $pathParts = pathinfo($file->getName()); |
|
110 | - $extension = $pathParts['extension'] ?? ''; |
|
111 | - $fileName = $pathParts['filename']; |
|
112 | - /* |
|
46 | + /** @var IRootFolder */ |
|
47 | + private $rootFolder; |
|
48 | + |
|
49 | + /** @var ITrashManager */ |
|
50 | + private $trashManager; |
|
51 | + |
|
52 | + /** @var IUserSession */ |
|
53 | + private $userSession; |
|
54 | + |
|
55 | + /** @var IMimeTypeDetector */ |
|
56 | + private $mimeTypeDetector; |
|
57 | + |
|
58 | + /** @var IPreview */ |
|
59 | + private $previewManager; |
|
60 | + |
|
61 | + /** @var ITimeFactory */ |
|
62 | + private $time; |
|
63 | + |
|
64 | + public function __construct( |
|
65 | + string $appName, |
|
66 | + IRequest $request, |
|
67 | + IRootFolder $rootFolder, |
|
68 | + ITrashManager $trashManager, |
|
69 | + IUserSession $userSession, |
|
70 | + IMimeTypeDetector $mimeTypeDetector, |
|
71 | + IPreview $previewManager, |
|
72 | + ITimeFactory $time |
|
73 | + ) { |
|
74 | + parent::__construct($appName, $request); |
|
75 | + |
|
76 | + $this->trashManager = $trashManager; |
|
77 | + $this->rootFolder = $rootFolder; |
|
78 | + $this->userSession = $userSession; |
|
79 | + $this->mimeTypeDetector = $mimeTypeDetector; |
|
80 | + $this->previewManager = $previewManager; |
|
81 | + $this->time = $time; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @NoAdminRequired |
|
86 | + * @NoCSRFRequired |
|
87 | + * |
|
88 | + * @return DataResponse|Http\FileDisplayResponse |
|
89 | + */ |
|
90 | + public function getPreview( |
|
91 | + int $fileId = -1, |
|
92 | + int $x = 32, |
|
93 | + int $y = 32, |
|
94 | + bool $a = false, |
|
95 | + ) { |
|
96 | + if ($fileId === -1 || $x === 0 || $y === 0) { |
|
97 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | + } |
|
99 | + |
|
100 | + try { |
|
101 | + $file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId); |
|
102 | + if ($file === null) { |
|
103 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
104 | + } |
|
105 | + if ($file instanceof Folder) { |
|
106 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
107 | + } |
|
108 | + |
|
109 | + $pathParts = pathinfo($file->getName()); |
|
110 | + $extension = $pathParts['extension'] ?? ''; |
|
111 | + $fileName = $pathParts['filename']; |
|
112 | + /* |
|
113 | 113 | * Files in the root of the trashbin are timetamped. |
114 | 114 | * So we have to strip that in order to properly detect the mimetype of the file. |
115 | 115 | */ |
116 | - if (preg_match('/d\d+/', $extension)) { |
|
117 | - $mimeType = $this->mimeTypeDetector->detectPath($fileName); |
|
118 | - } else { |
|
119 | - $mimeType = $this->mimeTypeDetector->detectPath($file->getName()); |
|
120 | - } |
|
121 | - |
|
122 | - $f = $this->previewManager->getPreview($file, $x, $y, $a, IPreview::MODE_FILL, $mimeType); |
|
123 | - $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
124 | - |
|
125 | - // Cache previews for 24H |
|
126 | - $response->cacheFor(3600 * 24); |
|
127 | - return $response; |
|
128 | - } catch (NotFoundException $e) { |
|
129 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
130 | - } catch (\InvalidArgumentException $e) { |
|
131 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
132 | - } |
|
133 | - } |
|
116 | + if (preg_match('/d\d+/', $extension)) { |
|
117 | + $mimeType = $this->mimeTypeDetector->detectPath($fileName); |
|
118 | + } else { |
|
119 | + $mimeType = $this->mimeTypeDetector->detectPath($file->getName()); |
|
120 | + } |
|
121 | + |
|
122 | + $f = $this->previewManager->getPreview($file, $x, $y, $a, IPreview::MODE_FILL, $mimeType); |
|
123 | + $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
124 | + |
|
125 | + // Cache previews for 24H |
|
126 | + $response->cacheFor(3600 * 24); |
|
127 | + return $response; |
|
128 | + } catch (NotFoundException $e) { |
|
129 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
130 | + } catch (\InvalidArgumentException $e) { |
|
131 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |