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