Passed
Push — master ( 60b7d2...590c20 )
by Joas
18:40 queued 13s
created
apps/files/lib/Controller/ApiController.php 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -65,353 +65,353 @@
 block discarded – undo
65 65
  * @package OCA\Files\Controller
66 66
  */
67 67
 class ApiController extends Controller {
68
-	private TagService $tagService;
69
-	private IManager $shareManager;
70
-	private IPreview $previewManager;
71
-	private IUserSession $userSession;
72
-	private IConfig $config;
73
-	private ?Folder $userFolder;
74
-	private UserConfig $userConfig;
75
-	private ViewConfig $viewConfig;
68
+    private TagService $tagService;
69
+    private IManager $shareManager;
70
+    private IPreview $previewManager;
71
+    private IUserSession $userSession;
72
+    private IConfig $config;
73
+    private ?Folder $userFolder;
74
+    private UserConfig $userConfig;
75
+    private ViewConfig $viewConfig;
76 76
 
77
-	public function __construct(string $appName,
78
-								IRequest $request,
79
-								IUserSession $userSession,
80
-								TagService $tagService,
81
-								IPreview $previewManager,
82
-								IManager $shareManager,
83
-								IConfig $config,
84
-								?Folder $userFolder,
85
-								UserConfig $userConfig,
86
-								ViewConfig $viewConfig) {
87
-		parent::__construct($appName, $request);
88
-		$this->userSession = $userSession;
89
-		$this->tagService = $tagService;
90
-		$this->previewManager = $previewManager;
91
-		$this->shareManager = $shareManager;
92
-		$this->config = $config;
93
-		$this->userFolder = $userFolder;
94
-		$this->userConfig = $userConfig;
95
-		$this->viewConfig = $viewConfig;
96
-	}
77
+    public function __construct(string $appName,
78
+                                IRequest $request,
79
+                                IUserSession $userSession,
80
+                                TagService $tagService,
81
+                                IPreview $previewManager,
82
+                                IManager $shareManager,
83
+                                IConfig $config,
84
+                                ?Folder $userFolder,
85
+                                UserConfig $userConfig,
86
+                                ViewConfig $viewConfig) {
87
+        parent::__construct($appName, $request);
88
+        $this->userSession = $userSession;
89
+        $this->tagService = $tagService;
90
+        $this->previewManager = $previewManager;
91
+        $this->shareManager = $shareManager;
92
+        $this->config = $config;
93
+        $this->userFolder = $userFolder;
94
+        $this->userConfig = $userConfig;
95
+        $this->viewConfig = $viewConfig;
96
+    }
97 97
 
98
-	/**
99
-	 * Gets a thumbnail of the specified file
100
-	 *
101
-	 * @since API version 1.0
102
-	 *
103
-	 * @NoAdminRequired
104
-	 * @NoCSRFRequired
105
-	 * @StrictCookieRequired
106
-	 *
107
-	 * @param int $x
108
-	 * @param int $y
109
-	 * @param string $file URL-encoded filename
110
-	 * @return DataResponse|FileDisplayResponse
111
-	 */
112
-	public function getThumbnail($x, $y, $file) {
113
-		if ($x < 1 || $y < 1) {
114
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
115
-		}
98
+    /**
99
+     * Gets a thumbnail of the specified file
100
+     *
101
+     * @since API version 1.0
102
+     *
103
+     * @NoAdminRequired
104
+     * @NoCSRFRequired
105
+     * @StrictCookieRequired
106
+     *
107
+     * @param int $x
108
+     * @param int $y
109
+     * @param string $file URL-encoded filename
110
+     * @return DataResponse|FileDisplayResponse
111
+     */
112
+    public function getThumbnail($x, $y, $file) {
113
+        if ($x < 1 || $y < 1) {
114
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
115
+        }
116 116
 
117
-		try {
118
-			$file = $this->userFolder->get($file);
119
-			if ($file instanceof Folder) {
120
-				throw new NotFoundException();
121
-			}
117
+        try {
118
+            $file = $this->userFolder->get($file);
119
+            if ($file instanceof Folder) {
120
+                throw new NotFoundException();
121
+            }
122 122
 
123
-			/** @var File $file */
124
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
123
+            /** @var File $file */
124
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
125 125
 
126
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
127
-		} catch (NotFoundException $e) {
128
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
129
-		} catch (\Exception $e) {
130
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
131
-		}
132
-	}
126
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
127
+        } catch (NotFoundException $e) {
128
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
129
+        } catch (\Exception $e) {
130
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
131
+        }
132
+    }
133 133
 
134
-	/**
135
-	 * Updates the info of the specified file path
136
-	 * The passed tags are absolute, which means they will
137
-	 * replace the actual tag selection.
138
-	 *
139
-	 * @NoAdminRequired
140
-	 *
141
-	 * @param string $path path
142
-	 * @param array|string $tags array of tags
143
-	 * @return DataResponse
144
-	 */
145
-	public function updateFileTags($path, $tags = null) {
146
-		$result = [];
147
-		// if tags specified or empty array, update tags
148
-		if (!is_null($tags)) {
149
-			try {
150
-				$this->tagService->updateFileTags($path, $tags);
151
-			} catch (\OCP\Files\NotFoundException $e) {
152
-				return new DataResponse([
153
-					'message' => $e->getMessage()
154
-				], Http::STATUS_NOT_FOUND);
155
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
156
-				return new DataResponse([
157
-					'message' => $e->getMessage()
158
-				], Http::STATUS_SERVICE_UNAVAILABLE);
159
-			} catch (\Exception $e) {
160
-				return new DataResponse([
161
-					'message' => $e->getMessage()
162
-				], Http::STATUS_NOT_FOUND);
163
-			}
164
-			$result['tags'] = $tags;
165
-		}
166
-		return new DataResponse($result);
167
-	}
134
+    /**
135
+     * Updates the info of the specified file path
136
+     * The passed tags are absolute, which means they will
137
+     * replace the actual tag selection.
138
+     *
139
+     * @NoAdminRequired
140
+     *
141
+     * @param string $path path
142
+     * @param array|string $tags array of tags
143
+     * @return DataResponse
144
+     */
145
+    public function updateFileTags($path, $tags = null) {
146
+        $result = [];
147
+        // if tags specified or empty array, update tags
148
+        if (!is_null($tags)) {
149
+            try {
150
+                $this->tagService->updateFileTags($path, $tags);
151
+            } catch (\OCP\Files\NotFoundException $e) {
152
+                return new DataResponse([
153
+                    'message' => $e->getMessage()
154
+                ], Http::STATUS_NOT_FOUND);
155
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
156
+                return new DataResponse([
157
+                    'message' => $e->getMessage()
158
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
159
+            } catch (\Exception $e) {
160
+                return new DataResponse([
161
+                    'message' => $e->getMessage()
162
+                ], Http::STATUS_NOT_FOUND);
163
+            }
164
+            $result['tags'] = $tags;
165
+        }
166
+        return new DataResponse($result);
167
+    }
168 168
 
169
-	/**
170
-	 * @param \OCP\Files\Node[] $nodes
171
-	 * @return array
172
-	 */
173
-	private function formatNodes(array $nodes) {
174
-		$shareTypesForNodes = $this->getShareTypesForNodes($nodes);
175
-		return array_values(array_map(function (Node $node) use ($shareTypesForNodes) {
176
-			$shareTypes = $shareTypesForNodes[$node->getId()] ?? [];
177
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
178
-			$file['hasPreview'] = $this->previewManager->isAvailable($node);
179
-			$parts = explode('/', dirname($node->getPath()), 4);
180
-			if (isset($parts[3])) {
181
-				$file['path'] = '/' . $parts[3];
182
-			} else {
183
-				$file['path'] = '/';
184
-			}
185
-			if (!empty($shareTypes)) {
186
-				$file['shareTypes'] = $shareTypes;
187
-			}
188
-			return $file;
189
-		}, $nodes));
190
-	}
169
+    /**
170
+     * @param \OCP\Files\Node[] $nodes
171
+     * @return array
172
+     */
173
+    private function formatNodes(array $nodes) {
174
+        $shareTypesForNodes = $this->getShareTypesForNodes($nodes);
175
+        return array_values(array_map(function (Node $node) use ($shareTypesForNodes) {
176
+            $shareTypes = $shareTypesForNodes[$node->getId()] ?? [];
177
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
178
+            $file['hasPreview'] = $this->previewManager->isAvailable($node);
179
+            $parts = explode('/', dirname($node->getPath()), 4);
180
+            if (isset($parts[3])) {
181
+                $file['path'] = '/' . $parts[3];
182
+            } else {
183
+                $file['path'] = '/';
184
+            }
185
+            if (!empty($shareTypes)) {
186
+                $file['shareTypes'] = $shareTypes;
187
+            }
188
+            return $file;
189
+        }, $nodes));
190
+    }
191 191
 
192
-	/**
193
-	 * Get the share types for each node
194
-	 *
195
-	 * @param \OCP\Files\Node[] $nodes
196
-	 * @return array<int, int[]> list of share types for each fileid
197
-	 */
198
-	private function getShareTypesForNodes(array $nodes): array {
199
-		$userId = $this->userSession->getUser()->getUID();
200
-		$requestedShareTypes = [
201
-			IShare::TYPE_USER,
202
-			IShare::TYPE_GROUP,
203
-			IShare::TYPE_LINK,
204
-			IShare::TYPE_REMOTE,
205
-			IShare::TYPE_EMAIL,
206
-			IShare::TYPE_ROOM,
207
-			IShare::TYPE_DECK,
208
-			IShare::TYPE_SCIENCEMESH,
209
-		];
210
-		$shareTypes = [];
192
+    /**
193
+     * Get the share types for each node
194
+     *
195
+     * @param \OCP\Files\Node[] $nodes
196
+     * @return array<int, int[]> list of share types for each fileid
197
+     */
198
+    private function getShareTypesForNodes(array $nodes): array {
199
+        $userId = $this->userSession->getUser()->getUID();
200
+        $requestedShareTypes = [
201
+            IShare::TYPE_USER,
202
+            IShare::TYPE_GROUP,
203
+            IShare::TYPE_LINK,
204
+            IShare::TYPE_REMOTE,
205
+            IShare::TYPE_EMAIL,
206
+            IShare::TYPE_ROOM,
207
+            IShare::TYPE_DECK,
208
+            IShare::TYPE_SCIENCEMESH,
209
+        ];
210
+        $shareTypes = [];
211 211
 
212
-		$nodeIds = array_map(function (Node $node) {
213
-			return $node->getId();
214
-		}, $nodes);
212
+        $nodeIds = array_map(function (Node $node) {
213
+            return $node->getId();
214
+        }, $nodes);
215 215
 
216
-		foreach ($requestedShareTypes as $shareType) {
217
-			$nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true));
218
-			$offset = 0;
216
+        foreach ($requestedShareTypes as $shareType) {
217
+            $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true));
218
+            $offset = 0;
219 219
 
220
-			// fetch shares until we've either found shares for all nodes or there are no more shares left
221
-			while (count($nodesLeft) > 0) {
222
-				$shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset);
223
-				foreach ($shares as $share) {
224
-					$fileId = $share->getNodeId();
225
-					if (isset($nodesLeft[$fileId])) {
226
-						if (!isset($shareTypes[$fileId])) {
227
-							$shareTypes[$fileId] = [];
228
-						}
229
-						$shareTypes[$fileId][] = $shareType;
230
-						unset($nodesLeft[$fileId]);
231
-					}
232
-				}
220
+            // fetch shares until we've either found shares for all nodes or there are no more shares left
221
+            while (count($nodesLeft) > 0) {
222
+                $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset);
223
+                foreach ($shares as $share) {
224
+                    $fileId = $share->getNodeId();
225
+                    if (isset($nodesLeft[$fileId])) {
226
+                        if (!isset($shareTypes[$fileId])) {
227
+                            $shareTypes[$fileId] = [];
228
+                        }
229
+                        $shareTypes[$fileId][] = $shareType;
230
+                        unset($nodesLeft[$fileId]);
231
+                    }
232
+                }
233 233
 
234
-				if (count($shares) < 100) {
235
-					break;
236
-				} else {
237
-					$offset += count($shares);
238
-				}
239
-			}
240
-		}
241
-		return $shareTypes;
242
-	}
234
+                if (count($shares) < 100) {
235
+                    break;
236
+                } else {
237
+                    $offset += count($shares);
238
+                }
239
+            }
240
+        }
241
+        return $shareTypes;
242
+    }
243 243
 
244
-	/**
245
-	 * Returns a list of recently modified files.
246
-	 *
247
-	 * @NoAdminRequired
248
-	 *
249
-	 * @return DataResponse
250
-	 */
251
-	public function getRecentFiles() {
252
-		$nodes = $this->userFolder->getRecent(100);
253
-		$files = $this->formatNodes($nodes);
254
-		return new DataResponse(['files' => $files]);
255
-	}
244
+    /**
245
+     * Returns a list of recently modified files.
246
+     *
247
+     * @NoAdminRequired
248
+     *
249
+     * @return DataResponse
250
+     */
251
+    public function getRecentFiles() {
252
+        $nodes = $this->userFolder->getRecent(100);
253
+        $files = $this->formatNodes($nodes);
254
+        return new DataResponse(['files' => $files]);
255
+    }
256 256
 
257 257
 
258
-	/**
259
-	 * Returns the current logged-in user's storage stats.
260
-	 *
261
-	 * @NoAdminRequired
262
-	 *
263
-	 * @param ?string $dir the directory to get the storage stats from
264
-	 * @return JSONResponse
265
-	 */
266
-	public function getStorageStats($dir = '/'): JSONResponse {
267
-		$storageInfo = \OC_Helper::getStorageInfo($dir ?: '/');
268
-		return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]);
269
-	}
258
+    /**
259
+     * Returns the current logged-in user's storage stats.
260
+     *
261
+     * @NoAdminRequired
262
+     *
263
+     * @param ?string $dir the directory to get the storage stats from
264
+     * @return JSONResponse
265
+     */
266
+    public function getStorageStats($dir = '/'): JSONResponse {
267
+        $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/');
268
+        return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]);
269
+    }
270 270
 
271
-	/**
272
-	 * Set a user view config
273
-	 *
274
-	 * @NoAdminRequired
275
-	 *
276
-	 * @param string $view
277
-	 * @param string $key
278
-	 * @param string|bool $value
279
-	 * @return JSONResponse
280
-	 */
281
-	public function setViewConfig(string $view, string $key, $value): JSONResponse {
282
-		try {
283
-			$this->viewConfig->setConfig($view, $key, (string)$value);
284
-		} catch (\InvalidArgumentException $e) {
285
-			return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
286
-		}
271
+    /**
272
+     * Set a user view config
273
+     *
274
+     * @NoAdminRequired
275
+     *
276
+     * @param string $view
277
+     * @param string $key
278
+     * @param string|bool $value
279
+     * @return JSONResponse
280
+     */
281
+    public function setViewConfig(string $view, string $key, $value): JSONResponse {
282
+        try {
283
+            $this->viewConfig->setConfig($view, $key, (string)$value);
284
+        } catch (\InvalidArgumentException $e) {
285
+            return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
286
+        }
287 287
 
288
-		return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfig($view)]);
289
-	}
288
+        return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfig($view)]);
289
+    }
290 290
 
291 291
 
292
-	/**
293
-	 * Get the user view config
294
-	 *
295
-	 * @NoAdminRequired
296
-	 *
297
-	 * @return JSONResponse
298
-	 */
299
-	public function getViewConfigs(): JSONResponse {
300
-		return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfigs()]);
301
-	}
292
+    /**
293
+     * Get the user view config
294
+     *
295
+     * @NoAdminRequired
296
+     *
297
+     * @return JSONResponse
298
+     */
299
+    public function getViewConfigs(): JSONResponse {
300
+        return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfigs()]);
301
+    }
302 302
 
303
-	/**
304
-	 * Set a user config
305
-	 *
306
-	 * @NoAdminRequired
307
-	 *
308
-	 * @param string $key
309
-	 * @param string|bool $value
310
-	 * @return JSONResponse
311
-	 */
312
-	public function setConfig(string $key, $value): JSONResponse {
313
-		try {
314
-			$this->userConfig->setConfig($key, (string)$value);
315
-		} catch (\InvalidArgumentException $e) {
316
-			return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
317
-		}
303
+    /**
304
+     * Set a user config
305
+     *
306
+     * @NoAdminRequired
307
+     *
308
+     * @param string $key
309
+     * @param string|bool $value
310
+     * @return JSONResponse
311
+     */
312
+    public function setConfig(string $key, $value): JSONResponse {
313
+        try {
314
+            $this->userConfig->setConfig($key, (string)$value);
315
+        } catch (\InvalidArgumentException $e) {
316
+            return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
317
+        }
318 318
 
319
-		return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]);
320
-	}
319
+        return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]);
320
+    }
321 321
 
322 322
 
323
-	/**
324
-	 * Get the user config
325
-	 *
326
-	 * @NoAdminRequired
327
-	 *
328
-	 * @return JSONResponse
329
-	 */
330
-	public function getConfigs(): JSONResponse {
331
-		return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]);
332
-	}
323
+    /**
324
+     * Get the user config
325
+     *
326
+     * @NoAdminRequired
327
+     *
328
+     * @return JSONResponse
329
+     */
330
+    public function getConfigs(): JSONResponse {
331
+        return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]);
332
+    }
333 333
 
334
-	/**
335
-	 * Toggle default for showing/hiding hidden files
336
-	 *
337
-	 * @NoAdminRequired
338
-	 *
339
-	 * @param bool $value
340
-	 * @return Response
341
-	 * @throws \OCP\PreConditionNotMetException
342
-	 */
343
-	public function showHiddenFiles(bool $value): Response {
344
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0');
345
-		return new Response();
346
-	}
334
+    /**
335
+     * Toggle default for showing/hiding hidden files
336
+     *
337
+     * @NoAdminRequired
338
+     *
339
+     * @param bool $value
340
+     * @return Response
341
+     * @throws \OCP\PreConditionNotMetException
342
+     */
343
+    public function showHiddenFiles(bool $value): Response {
344
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0');
345
+        return new Response();
346
+    }
347 347
 
348
-	/**
349
-	 * Toggle default for cropping preview images
350
-	 *
351
-	 * @NoAdminRequired
352
-	 *
353
-	 * @param bool $value
354
-	 * @return Response
355
-	 * @throws \OCP\PreConditionNotMetException
356
-	 */
357
-	public function cropImagePreviews(bool $value): Response {
358
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0');
359
-		return new Response();
360
-	}
348
+    /**
349
+     * Toggle default for cropping preview images
350
+     *
351
+     * @NoAdminRequired
352
+     *
353
+     * @param bool $value
354
+     * @return Response
355
+     * @throws \OCP\PreConditionNotMetException
356
+     */
357
+    public function cropImagePreviews(bool $value): Response {
358
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0');
359
+        return new Response();
360
+    }
361 361
 
362
-	/**
363
-	 * Toggle default for files grid view
364
-	 *
365
-	 * @NoAdminRequired
366
-	 *
367
-	 * @param bool $show
368
-	 * @return Response
369
-	 * @throws \OCP\PreConditionNotMetException
370
-	 */
371
-	public function showGridView(bool $show): Response {
372
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0');
373
-		return new Response();
374
-	}
362
+    /**
363
+     * Toggle default for files grid view
364
+     *
365
+     * @NoAdminRequired
366
+     *
367
+     * @param bool $show
368
+     * @return Response
369
+     * @throws \OCP\PreConditionNotMetException
370
+     */
371
+    public function showGridView(bool $show): Response {
372
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0');
373
+        return new Response();
374
+    }
375 375
 
376
-	/**
377
-	 * Get default settings for the grid view
378
-	 *
379
-	 * @NoAdminRequired
380
-	 */
381
-	public function getGridView() {
382
-		$status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
383
-		return new JSONResponse(['gridview' => $status]);
384
-	}
376
+    /**
377
+     * Get default settings for the grid view
378
+     *
379
+     * @NoAdminRequired
380
+     */
381
+    public function getGridView() {
382
+        $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
383
+        return new JSONResponse(['gridview' => $status]);
384
+    }
385 385
 
386
-	/**
387
-	 * Get sorting-order for custom sorting
388
-	 *
389
-	 * @NoAdminRequired
390
-	 *
391
-	 * @param string $folderpath
392
-	 * @return string
393
-	 * @throws \OCP\Files\NotFoundException
394
-	 */
395
-	public function getNodeType($folderpath) {
396
-		$node = $this->userFolder->get($folderpath);
397
-		return $node->getType();
398
-	}
386
+    /**
387
+     * Get sorting-order for custom sorting
388
+     *
389
+     * @NoAdminRequired
390
+     *
391
+     * @param string $folderpath
392
+     * @return string
393
+     * @throws \OCP\Files\NotFoundException
394
+     */
395
+    public function getNodeType($folderpath) {
396
+        $node = $this->userFolder->get($folderpath);
397
+        return $node->getType();
398
+    }
399 399
 
400
-	/**
401
-	 * @NoAdminRequired
402
-	 * @NoCSRFRequired
403
-	 */
404
-	public function serviceWorker(): StreamResponse {
405
-		$response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js');
406
-		$response->setHeaders([
407
-			'Content-Type' => 'application/javascript',
408
-			'Service-Worker-Allowed' => '/'
409
-		]);
410
-		$policy = new ContentSecurityPolicy();
411
-		$policy->addAllowedWorkerSrcDomain("'self'");
412
-		$policy->addAllowedScriptDomain("'self'");
413
-		$policy->addAllowedConnectDomain("'self'");
414
-		$response->setContentSecurityPolicy($policy);
415
-		return $response;
416
-	}
400
+    /**
401
+     * @NoAdminRequired
402
+     * @NoCSRFRequired
403
+     */
404
+    public function serviceWorker(): StreamResponse {
405
+        $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js');
406
+        $response->setHeaders([
407
+            'Content-Type' => 'application/javascript',
408
+            'Service-Worker-Allowed' => '/'
409
+        ]);
410
+        $policy = new ContentSecurityPolicy();
411
+        $policy->addAllowedWorkerSrcDomain("'self'");
412
+        $policy->addAllowedScriptDomain("'self'");
413
+        $policy->addAllowedConnectDomain("'self'");
414
+        $response->setContentSecurityPolicy($policy);
415
+        return $response;
416
+    }
417 417
 }
Please login to merge, or discard this patch.
apps/files/lib/Service/TagService.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -38,110 +38,110 @@
 block discarded – undo
38 38
  */
39 39
 class TagService {
40 40
 
41
-	/** @var IUserSession */
42
-	private $userSession;
43
-	/** @var IManager */
44
-	private $activityManager;
45
-	/** @var ITags|null */
46
-	private $tagger;
47
-	/** @var Folder|null */
48
-	private $homeFolder;
49
-	/** @var EventDispatcherInterface */
50
-	private $dispatcher;
41
+    /** @var IUserSession */
42
+    private $userSession;
43
+    /** @var IManager */
44
+    private $activityManager;
45
+    /** @var ITags|null */
46
+    private $tagger;
47
+    /** @var Folder|null */
48
+    private $homeFolder;
49
+    /** @var EventDispatcherInterface */
50
+    private $dispatcher;
51 51
 
52
-	public function __construct(
53
-		IUserSession $userSession,
54
-		IManager $activityManager,
55
-		?ITags $tagger,
56
-		?Folder $homeFolder,
57
-		EventDispatcherInterface $dispatcher
58
-	) {
59
-		$this->userSession = $userSession;
60
-		$this->activityManager = $activityManager;
61
-		$this->tagger = $tagger;
62
-		$this->homeFolder = $homeFolder;
63
-		$this->dispatcher = $dispatcher;
64
-	}
52
+    public function __construct(
53
+        IUserSession $userSession,
54
+        IManager $activityManager,
55
+        ?ITags $tagger,
56
+        ?Folder $homeFolder,
57
+        EventDispatcherInterface $dispatcher
58
+    ) {
59
+        $this->userSession = $userSession;
60
+        $this->activityManager = $activityManager;
61
+        $this->tagger = $tagger;
62
+        $this->homeFolder = $homeFolder;
63
+        $this->dispatcher = $dispatcher;
64
+    }
65 65
 
66
-	/**
67
-	 * Updates the tags of the specified file path.
68
-	 * The passed tags are absolute, which means they will
69
-	 * replace the actual tag selection.
70
-	 *
71
-	 * @param string $path path
72
-	 * @param array  $tags array of tags
73
-	 * @return array list of tags
74
-	 * @throws \OCP\Files\NotFoundException if the file does not exist
75
-	 */
76
-	public function updateFileTags($path, $tags) {
77
-		if ($this->tagger === null) {
78
-			throw new \RuntimeException('No tagger set');
79
-		}
80
-		if ($this->homeFolder === null) {
81
-			throw new \RuntimeException('No homeFolder set');
82
-		}
66
+    /**
67
+     * Updates the tags of the specified file path.
68
+     * The passed tags are absolute, which means they will
69
+     * replace the actual tag selection.
70
+     *
71
+     * @param string $path path
72
+     * @param array  $tags array of tags
73
+     * @return array list of tags
74
+     * @throws \OCP\Files\NotFoundException if the file does not exist
75
+     */
76
+    public function updateFileTags($path, $tags) {
77
+        if ($this->tagger === null) {
78
+            throw new \RuntimeException('No tagger set');
79
+        }
80
+        if ($this->homeFolder === null) {
81
+            throw new \RuntimeException('No homeFolder set');
82
+        }
83 83
 
84
-		$fileId = $this->homeFolder->get($path)->getId();
84
+        $fileId = $this->homeFolder->get($path)->getId();
85 85
 
86
-		$currentTags = $this->tagger->getTagsForObjects([$fileId]);
86
+        $currentTags = $this->tagger->getTagsForObjects([$fileId]);
87 87
 
88
-		if (!empty($currentTags)) {
89
-			$currentTags = current($currentTags);
90
-		}
88
+        if (!empty($currentTags)) {
89
+            $currentTags = current($currentTags);
90
+        }
91 91
 
92
-		$newTags = array_diff($tags, $currentTags);
93
-		foreach ($newTags as $tag) {
94
-			if ($tag === ITags::TAG_FAVORITE) {
95
-				$this->addActivity(true, $fileId, $path);
96
-			}
97
-			$this->tagger->tagAs($fileId, $tag);
98
-		}
99
-		$deletedTags = array_diff($currentTags, $tags);
100
-		foreach ($deletedTags as $tag) {
101
-			if ($tag === ITags::TAG_FAVORITE) {
102
-				$this->addActivity(false, $fileId, $path);
103
-			}
104
-			$this->tagger->unTag($fileId, $tag);
105
-		}
92
+        $newTags = array_diff($tags, $currentTags);
93
+        foreach ($newTags as $tag) {
94
+            if ($tag === ITags::TAG_FAVORITE) {
95
+                $this->addActivity(true, $fileId, $path);
96
+            }
97
+            $this->tagger->tagAs($fileId, $tag);
98
+        }
99
+        $deletedTags = array_diff($currentTags, $tags);
100
+        foreach ($deletedTags as $tag) {
101
+            if ($tag === ITags::TAG_FAVORITE) {
102
+                $this->addActivity(false, $fileId, $path);
103
+            }
104
+            $this->tagger->unTag($fileId, $tag);
105
+        }
106 106
 
107
-		// TODO: re-read from tagger to make sure the
108
-		// list is up to date, in case of concurrent changes ?
109
-		return $tags;
110
-	}
107
+        // TODO: re-read from tagger to make sure the
108
+        // list is up to date, in case of concurrent changes ?
109
+        return $tags;
110
+    }
111 111
 
112
-	/**
113
-	 * @param bool $addToFavorite
114
-	 * @param int $fileId
115
-	 * @param string $path
116
-	 */
117
-	protected function addActivity($addToFavorite, $fileId, $path) {
118
-		$user = $this->userSession->getUser();
119
-		if (!$user instanceof IUser) {
120
-			return;
121
-		}
112
+    /**
113
+     * @param bool $addToFavorite
114
+     * @param int $fileId
115
+     * @param string $path
116
+     */
117
+    protected function addActivity($addToFavorite, $fileId, $path) {
118
+        $user = $this->userSession->getUser();
119
+        if (!$user instanceof IUser) {
120
+            return;
121
+        }
122 122
 
123
-		$eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
124
-		$this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
125
-			'userId' => $user->getUID(),
126
-			'fileId' => $fileId,
127
-			'path' => $path,
128
-		]));
123
+        $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite';
124
+        $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [
125
+            'userId' => $user->getUID(),
126
+            'fileId' => $fileId,
127
+            'path' => $path,
128
+        ]));
129 129
 
130
-		$event = $this->activityManager->generateEvent();
131
-		try {
132
-			$event->setApp('files')
133
-				->setObject('files', $fileId, $path)
134
-				->setType('favorite')
135
-				->setAuthor($user->getUID())
136
-				->setAffectedUser($user->getUID())
137
-				->setTimestamp(time())
138
-				->setSubject(
139
-					$addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED,
140
-					['id' => $fileId, 'path' => $path]
141
-				);
142
-			$this->activityManager->publish($event);
143
-		} catch (\InvalidArgumentException $e) {
144
-		} catch (\BadMethodCallException $e) {
145
-		}
146
-	}
130
+        $event = $this->activityManager->generateEvent();
131
+        try {
132
+            $event->setApp('files')
133
+                ->setObject('files', $fileId, $path)
134
+                ->setType('favorite')
135
+                ->setAuthor($user->getUID())
136
+                ->setAffectedUser($user->getUID())
137
+                ->setTimestamp(time())
138
+                ->setSubject(
139
+                    $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED,
140
+                    ['id' => $fileId, 'path' => $path]
141
+                );
142
+            $this->activityManager->publish($event);
143
+        } catch (\InvalidArgumentException $e) {
144
+        } catch (\BadMethodCallException $e) {
145
+        }
146
+    }
147 147
 }
Please login to merge, or discard this patch.