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