Passed
Push — master ( bda3d0...32f64b )
by John
17:57 queued 10s
created
apps/files/lib/Controller/ApiController.php 2 patches
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -59,286 +59,286 @@
 block discarded – undo
59 59
  * @package OCA\Files\Controller
60 60
  */
61 61
 class ApiController extends Controller {
62
-	/** @var TagService */
63
-	private $tagService;
64
-	/** @var IManager * */
65
-	private $shareManager;
66
-	/** @var IPreview */
67
-	private $previewManager;
68
-	/** IUserSession */
69
-	private $userSession;
70
-	/** IConfig */
71
-	private $config;
72
-	/** @var Folder */
73
-	private $userFolder;
62
+    /** @var TagService */
63
+    private $tagService;
64
+    /** @var IManager * */
65
+    private $shareManager;
66
+    /** @var IPreview */
67
+    private $previewManager;
68
+    /** IUserSession */
69
+    private $userSession;
70
+    /** IConfig */
71
+    private $config;
72
+    /** @var Folder */
73
+    private $userFolder;
74 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
-		parent::__construct($appName, $request);
94
-		$this->userSession = $userSession;
95
-		$this->tagService = $tagService;
96
-		$this->previewManager = $previewManager;
97
-		$this->shareManager = $shareManager;
98
-		$this->config = $config;
99
-		$this->userFolder = $userFolder;
100
-	}
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
+        parent::__construct($appName, $request);
94
+        $this->userSession = $userSession;
95
+        $this->tagService = $tagService;
96
+        $this->previewManager = $previewManager;
97
+        $this->shareManager = $shareManager;
98
+        $this->config = $config;
99
+        $this->userFolder = $userFolder;
100
+    }
101 101
 
102
-	/**
103
-	 * Gets a thumbnail of the specified file
104
-	 *
105
-	 * @since API version 1.0
106
-	 *
107
-	 * @NoAdminRequired
108
-	 * @NoCSRFRequired
109
-	 * @StrictCookieRequired
110
-	 *
111
-	 * @param int $x
112
-	 * @param int $y
113
-	 * @param string $file URL-encoded filename
114
-	 * @return DataResponse|FileDisplayResponse
115
-	 */
116
-	public function getThumbnail($x, $y, $file) {
117
-		if ($x < 1 || $y < 1) {
118
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
119
-		}
102
+    /**
103
+     * Gets a thumbnail of the specified file
104
+     *
105
+     * @since API version 1.0
106
+     *
107
+     * @NoAdminRequired
108
+     * @NoCSRFRequired
109
+     * @StrictCookieRequired
110
+     *
111
+     * @param int $x
112
+     * @param int $y
113
+     * @param string $file URL-encoded filename
114
+     * @return DataResponse|FileDisplayResponse
115
+     */
116
+    public function getThumbnail($x, $y, $file) {
117
+        if ($x < 1 || $y < 1) {
118
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
119
+        }
120 120
 
121
-		try {
122
-			$file = $this->userFolder->get($file);
123
-			if ($file instanceof Folder) {
124
-				throw new NotFoundException();
125
-			}
121
+        try {
122
+            $file = $this->userFolder->get($file);
123
+            if ($file instanceof Folder) {
124
+                throw new NotFoundException();
125
+            }
126 126
 
127
-			/** @var File $file */
128
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
127
+            /** @var File $file */
128
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
129 129
 
130
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
131
-		} catch (NotFoundException $e) {
132
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
133
-		} catch (\Exception $e) {
134
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
135
-		}
136
-	}
130
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
131
+        } catch (NotFoundException $e) {
132
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
133
+        } catch (\Exception $e) {
134
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
135
+        }
136
+    }
137 137
 
138
-	/**
139
-	 * Updates the info of the specified file path
140
-	 * The passed tags are absolute, which means they will
141
-	 * replace the actual tag selection.
142
-	 *
143
-	 * @NoAdminRequired
144
-	 *
145
-	 * @param string $path path
146
-	 * @param array|string $tags array of tags
147
-	 * @return DataResponse
148
-	 */
149
-	public function updateFileTags($path, $tags = null) {
150
-		$result = [];
151
-		// if tags specified or empty array, update tags
152
-		if (!is_null($tags)) {
153
-			try {
154
-				$this->tagService->updateFileTags($path, $tags);
155
-			} catch (\OCP\Files\NotFoundException $e) {
156
-				return new DataResponse([
157
-					'message' => $e->getMessage()
158
-				], Http::STATUS_NOT_FOUND);
159
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
160
-				return new DataResponse([
161
-					'message' => $e->getMessage()
162
-				], Http::STATUS_SERVICE_UNAVAILABLE);
163
-			} catch (\Exception $e) {
164
-				return new DataResponse([
165
-					'message' => $e->getMessage()
166
-				], Http::STATUS_NOT_FOUND);
167
-			}
168
-			$result['tags'] = $tags;
169
-		}
170
-		return new DataResponse($result);
171
-	}
138
+    /**
139
+     * Updates the info of the specified file path
140
+     * The passed tags are absolute, which means they will
141
+     * replace the actual tag selection.
142
+     *
143
+     * @NoAdminRequired
144
+     *
145
+     * @param string $path path
146
+     * @param array|string $tags array of tags
147
+     * @return DataResponse
148
+     */
149
+    public function updateFileTags($path, $tags = null) {
150
+        $result = [];
151
+        // if tags specified or empty array, update tags
152
+        if (!is_null($tags)) {
153
+            try {
154
+                $this->tagService->updateFileTags($path, $tags);
155
+            } catch (\OCP\Files\NotFoundException $e) {
156
+                return new DataResponse([
157
+                    'message' => $e->getMessage()
158
+                ], Http::STATUS_NOT_FOUND);
159
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
160
+                return new DataResponse([
161
+                    'message' => $e->getMessage()
162
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
163
+            } catch (\Exception $e) {
164
+                return new DataResponse([
165
+                    'message' => $e->getMessage()
166
+                ], Http::STATUS_NOT_FOUND);
167
+            }
168
+            $result['tags'] = $tags;
169
+        }
170
+        return new DataResponse($result);
171
+    }
172 172
 
173
-	/**
174
-	 * @param \OCP\Files\Node[] $nodes
175
-	 * @return array
176
-	 */
177
-	private function formatNodes(array $nodes) {
178
-		return array_values(array_map(function (Node $node) {
179
-			/** @var \OC\Files\Node\Node $shareTypes */
180
-			$shareTypes = $this->getShareTypes($node);
181
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
182
-			$file['hasPreview'] = $this->previewManager->isAvailable($node);
183
-			$parts = explode('/', dirname($node->getPath()), 4);
184
-			if (isset($parts[3])) {
185
-				$file['path'] = '/' . $parts[3];
186
-			} else {
187
-				$file['path'] = '/';
188
-			}
189
-			if (!empty($shareTypes)) {
190
-				$file['shareTypes'] = $shareTypes;
191
-			}
192
-			return $file;
193
-		}, $nodes));
194
-	}
173
+    /**
174
+     * @param \OCP\Files\Node[] $nodes
175
+     * @return array
176
+     */
177
+    private function formatNodes(array $nodes) {
178
+        return array_values(array_map(function (Node $node) {
179
+            /** @var \OC\Files\Node\Node $shareTypes */
180
+            $shareTypes = $this->getShareTypes($node);
181
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
182
+            $file['hasPreview'] = $this->previewManager->isAvailable($node);
183
+            $parts = explode('/', dirname($node->getPath()), 4);
184
+            if (isset($parts[3])) {
185
+                $file['path'] = '/' . $parts[3];
186
+            } else {
187
+                $file['path'] = '/';
188
+            }
189
+            if (!empty($shareTypes)) {
190
+                $file['shareTypes'] = $shareTypes;
191
+            }
192
+            return $file;
193
+        }, $nodes));
194
+    }
195 195
 
196
-	/**
197
-	 * Returns a list of recently modifed files.
198
-	 *
199
-	 * @NoAdminRequired
200
-	 *
201
-	 * @return DataResponse
202
-	 */
203
-	public function getRecentFiles() {
204
-		$nodes = $this->userFolder->getRecent(100);
205
-		$files = $this->formatNodes($nodes);
206
-		return new DataResponse(['files' => $files]);
207
-	}
196
+    /**
197
+     * Returns a list of recently modifed files.
198
+     *
199
+     * @NoAdminRequired
200
+     *
201
+     * @return DataResponse
202
+     */
203
+    public function getRecentFiles() {
204
+        $nodes = $this->userFolder->getRecent(100);
205
+        $files = $this->formatNodes($nodes);
206
+        return new DataResponse(['files' => $files]);
207
+    }
208 208
 
209
-	/**
210
-	 * Return a list of share types for outgoing shares
211
-	 *
212
-	 * @param Node $node file node
213
-	 *
214
-	 * @return int[] array of share types
215
-	 */
216
-	private function getShareTypes(Node $node) {
217
-		$userId = $this->userSession->getUser()->getUID();
218
-		$shareTypes = [];
219
-		$requestedShareTypes = [
220
-			IShare::TYPE_USER,
221
-			IShare::TYPE_GROUP,
222
-			IShare::TYPE_LINK,
223
-			IShare::TYPE_REMOTE,
224
-			IShare::TYPE_EMAIL,
225
-			IShare::TYPE_ROOM,
226
-			IShare::TYPE_DECK,
227
-		];
228
-		foreach ($requestedShareTypes as $requestedShareType) {
229
-			// one of each type is enough to find out about the types
230
-			$shares = $this->shareManager->getSharesBy(
231
-				$userId,
232
-				$requestedShareType,
233
-				$node,
234
-				false,
235
-				1
236
-			);
237
-			if (!empty($shares)) {
238
-				$shareTypes[] = $requestedShareType;
239
-			}
240
-		}
241
-		return $shareTypes;
242
-	}
209
+    /**
210
+     * Return a list of share types for outgoing shares
211
+     *
212
+     * @param Node $node file node
213
+     *
214
+     * @return int[] array of share types
215
+     */
216
+    private function getShareTypes(Node $node) {
217
+        $userId = $this->userSession->getUser()->getUID();
218
+        $shareTypes = [];
219
+        $requestedShareTypes = [
220
+            IShare::TYPE_USER,
221
+            IShare::TYPE_GROUP,
222
+            IShare::TYPE_LINK,
223
+            IShare::TYPE_REMOTE,
224
+            IShare::TYPE_EMAIL,
225
+            IShare::TYPE_ROOM,
226
+            IShare::TYPE_DECK,
227
+        ];
228
+        foreach ($requestedShareTypes as $requestedShareType) {
229
+            // one of each type is enough to find out about the types
230
+            $shares = $this->shareManager->getSharesBy(
231
+                $userId,
232
+                $requestedShareType,
233
+                $node,
234
+                false,
235
+                1
236
+            );
237
+            if (!empty($shares)) {
238
+                $shareTypes[] = $requestedShareType;
239
+            }
240
+        }
241
+        return $shareTypes;
242
+    }
243 243
 
244
-	/**
245
-	 * Change the default sort mode
246
-	 *
247
-	 * @NoAdminRequired
248
-	 *
249
-	 * @param string $mode
250
-	 * @param string $direction
251
-	 * @return Response
252
-	 * @throws \OCP\PreConditionNotMetException
253
-	 */
254
-	public function updateFileSorting($mode, $direction) {
255
-		$allowedMode = ['name', 'size', 'mtime'];
256
-		$allowedDirection = ['asc', 'desc'];
257
-		if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
258
-			$response = new Response();
259
-			$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
260
-			return $response;
261
-		}
262
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
263
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
264
-		return new Response();
265
-	}
244
+    /**
245
+     * Change the default sort mode
246
+     *
247
+     * @NoAdminRequired
248
+     *
249
+     * @param string $mode
250
+     * @param string $direction
251
+     * @return Response
252
+     * @throws \OCP\PreConditionNotMetException
253
+     */
254
+    public function updateFileSorting($mode, $direction) {
255
+        $allowedMode = ['name', 'size', 'mtime'];
256
+        $allowedDirection = ['asc', 'desc'];
257
+        if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
258
+            $response = new Response();
259
+            $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
260
+            return $response;
261
+        }
262
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
263
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
264
+        return new Response();
265
+    }
266 266
 
267
-	/**
268
-	 * Toggle default for showing/hiding hidden files
269
-	 *
270
-	 * @NoAdminRequired
271
-	 *
272
-	 * @param bool $show
273
-	 * @return Response
274
-	 * @throws \OCP\PreConditionNotMetException
275
-	 */
276
-	public function showHiddenFiles($show) {
277
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
278
-		return new Response();
279
-	}
267
+    /**
268
+     * Toggle default for showing/hiding hidden files
269
+     *
270
+     * @NoAdminRequired
271
+     *
272
+     * @param bool $show
273
+     * @return Response
274
+     * @throws \OCP\PreConditionNotMetException
275
+     */
276
+    public function showHiddenFiles($show) {
277
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
278
+        return new Response();
279
+    }
280 280
 
281
-	/**
282
-	 * Toggle default for files grid view
283
-	 *
284
-	 * @NoAdminRequired
285
-	 *
286
-	 * @param bool $show
287
-	 * @return Response
288
-	 * @throws \OCP\PreConditionNotMetException
289
-	 */
290
-	public function showGridView($show) {
291
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
292
-		return new Response();
293
-	}
281
+    /**
282
+     * Toggle default for files grid view
283
+     *
284
+     * @NoAdminRequired
285
+     *
286
+     * @param bool $show
287
+     * @return Response
288
+     * @throws \OCP\PreConditionNotMetException
289
+     */
290
+    public function showGridView($show) {
291
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
292
+        return new Response();
293
+    }
294 294
 
295
-	/**
296
-	 * Get default settings for the grid view
297
-	 *
298
-	 * @NoAdminRequired
299
-	 */
300
-	public function getGridView() {
301
-		$status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
302
-		return new JSONResponse(['gridview' => $status]);
303
-	}
295
+    /**
296
+     * Get default settings for the grid view
297
+     *
298
+     * @NoAdminRequired
299
+     */
300
+    public function getGridView() {
301
+        $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
302
+        return new JSONResponse(['gridview' => $status]);
303
+    }
304 304
 
305
-	/**
306
-	 * Toggle default for showing/hiding xxx folder
307
-	 *
308
-	 * @NoAdminRequired
309
-	 *
310
-	 * @param int $show
311
-	 * @param string $key the key of the folder
312
-	 *
313
-	 * @return Response
314
-	 * @throws \OCP\PreConditionNotMetException
315
-	 */
316
-	public function toggleShowFolder(int $show, string $key) {
317
-		// ensure the edited key exists
318
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
319
-		foreach ($navItems as $item) {
320
-			// check if data is valid
321
-			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
322
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
323
-				return new Response();
324
-			}
325
-		}
326
-		$response = new Response();
327
-		$response->setStatus(Http::STATUS_FORBIDDEN);
328
-		return $response;
329
-	}
305
+    /**
306
+     * Toggle default for showing/hiding xxx folder
307
+     *
308
+     * @NoAdminRequired
309
+     *
310
+     * @param int $show
311
+     * @param string $key the key of the folder
312
+     *
313
+     * @return Response
314
+     * @throws \OCP\PreConditionNotMetException
315
+     */
316
+    public function toggleShowFolder(int $show, string $key) {
317
+        // ensure the edited key exists
318
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
319
+        foreach ($navItems as $item) {
320
+            // check if data is valid
321
+            if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
322
+                $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
323
+                return new Response();
324
+            }
325
+        }
326
+        $response = new Response();
327
+        $response->setStatus(Http::STATUS_FORBIDDEN);
328
+        return $response;
329
+    }
330 330
 
331
-	/**
332
-	 * Get sorting-order for custom sorting
333
-	 *
334
-	 * @NoAdminRequired
335
-	 *
336
-	 * @param string $folderpath
337
-	 * @return string
338
-	 * @throws \OCP\Files\NotFoundException
339
-	 */
340
-	public function getNodeType($folderpath) {
341
-		$node = $this->userFolder->get($folderpath);
342
-		return $node->getType();
343
-	}
331
+    /**
332
+     * Get sorting-order for custom sorting
333
+     *
334
+     * @NoAdminRequired
335
+     *
336
+     * @param string $folderpath
337
+     * @return string
338
+     * @throws \OCP\Files\NotFoundException
339
+     */
340
+    public function getNodeType($folderpath) {
341
+        $node = $this->userFolder->get($folderpath);
342
+        return $node->getType();
343
+    }
344 344
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
 	 * @return array
176 176
 	 */
177 177
 	private function formatNodes(array $nodes) {
178
-		return array_values(array_map(function (Node $node) {
178
+		return array_values(array_map(function(Node $node) {
179 179
 			/** @var \OC\Files\Node\Node $shareTypes */
180 180
 			$shareTypes = $this->getShareTypes($node);
181 181
 			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
182 182
 			$file['hasPreview'] = $this->previewManager->isAvailable($node);
183 183
 			$parts = explode('/', dirname($node->getPath()), 4);
184 184
 			if (isset($parts[3])) {
185
-				$file['path'] = '/' . $parts[3];
185
+				$file['path'] = '/'.$parts[3];
186 186
 			} else {
187 187
 				$file['path'] = '/';
188 188
 			}
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * @throws \OCP\PreConditionNotMetException
275 275
 	 */
276 276
 	public function showHiddenFiles($show) {
277
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
277
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show);
278 278
 		return new Response();
279 279
 	}
280 280
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	 * @throws \OCP\PreConditionNotMetException
289 289
 	 */
290 290
 	public function showGridView($show) {
291
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
291
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int) $show);
292 292
 		return new Response();
293 293
 	}
294 294
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		foreach ($navItems as $item) {
320 320
 			// check if data is valid
321 321
 			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
322
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
322
+				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int) $show);
323 323
 				return new Response();
324 324
 			}
325 325
 		}
Please login to merge, or discard this patch.