@@ -61,316 +61,316 @@ |
||
| 61 | 61 | * @package OCA\Files\Controller |
| 62 | 62 | */ |
| 63 | 63 | class ApiController extends Controller { |
| 64 | - /** @var TagService */ |
|
| 65 | - private $tagService; |
|
| 66 | - /** @var IManager * */ |
|
| 67 | - private $shareManager; |
|
| 68 | - /** @var IPreview */ |
|
| 69 | - private $previewManager; |
|
| 70 | - /** @var IUserSession */ |
|
| 71 | - private $userSession; |
|
| 72 | - /** @var IConfig */ |
|
| 73 | - private $config; |
|
| 74 | - /** @var Folder */ |
|
| 75 | - private $userFolder; |
|
| 64 | + /** @var TagService */ |
|
| 65 | + private $tagService; |
|
| 66 | + /** @var IManager * */ |
|
| 67 | + private $shareManager; |
|
| 68 | + /** @var IPreview */ |
|
| 69 | + private $previewManager; |
|
| 70 | + /** @var IUserSession */ |
|
| 71 | + private $userSession; |
|
| 72 | + /** @var IConfig */ |
|
| 73 | + private $config; |
|
| 74 | + /** @var Folder */ |
|
| 75 | + private $userFolder; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param string $appName |
|
| 79 | - * @param IRequest $request |
|
| 80 | - * @param IUserSession $userSession |
|
| 81 | - * @param TagService $tagService |
|
| 82 | - * @param IPreview $previewManager |
|
| 83 | - * @param IManager $shareManager |
|
| 84 | - * @param IConfig $config |
|
| 85 | - * @param Folder $userFolder |
|
| 86 | - */ |
|
| 87 | - public function __construct($appName, |
|
| 88 | - IRequest $request, |
|
| 89 | - IUserSession $userSession, |
|
| 90 | - TagService $tagService, |
|
| 91 | - IPreview $previewManager, |
|
| 92 | - IManager $shareManager, |
|
| 93 | - IConfig $config, |
|
| 94 | - Folder $userFolder) { |
|
| 95 | - parent::__construct($appName, $request); |
|
| 96 | - $this->userSession = $userSession; |
|
| 97 | - $this->tagService = $tagService; |
|
| 98 | - $this->previewManager = $previewManager; |
|
| 99 | - $this->shareManager = $shareManager; |
|
| 100 | - $this->config = $config; |
|
| 101 | - $this->userFolder = $userFolder; |
|
| 102 | - } |
|
| 77 | + /** |
|
| 78 | + * @param string $appName |
|
| 79 | + * @param IRequest $request |
|
| 80 | + * @param IUserSession $userSession |
|
| 81 | + * @param TagService $tagService |
|
| 82 | + * @param IPreview $previewManager |
|
| 83 | + * @param IManager $shareManager |
|
| 84 | + * @param IConfig $config |
|
| 85 | + * @param Folder $userFolder |
|
| 86 | + */ |
|
| 87 | + public function __construct($appName, |
|
| 88 | + IRequest $request, |
|
| 89 | + IUserSession $userSession, |
|
| 90 | + TagService $tagService, |
|
| 91 | + IPreview $previewManager, |
|
| 92 | + IManager $shareManager, |
|
| 93 | + IConfig $config, |
|
| 94 | + Folder $userFolder) { |
|
| 95 | + parent::__construct($appName, $request); |
|
| 96 | + $this->userSession = $userSession; |
|
| 97 | + $this->tagService = $tagService; |
|
| 98 | + $this->previewManager = $previewManager; |
|
| 99 | + $this->shareManager = $shareManager; |
|
| 100 | + $this->config = $config; |
|
| 101 | + $this->userFolder = $userFolder; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Gets a thumbnail of the specified file |
|
| 106 | - * |
|
| 107 | - * @since API version 1.0 |
|
| 108 | - * |
|
| 109 | - * @NoAdminRequired |
|
| 110 | - * @NoCSRFRequired |
|
| 111 | - * @StrictCookieRequired |
|
| 112 | - * |
|
| 113 | - * @param int $x |
|
| 114 | - * @param int $y |
|
| 115 | - * @param string $file URL-encoded filename |
|
| 116 | - * @return DataResponse|FileDisplayResponse |
|
| 117 | - */ |
|
| 118 | - public function getThumbnail($x, $y, $file) { |
|
| 119 | - if ($x < 1 || $y < 1) { |
|
| 120 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 121 | - } |
|
| 104 | + /** |
|
| 105 | + * Gets a thumbnail of the specified file |
|
| 106 | + * |
|
| 107 | + * @since API version 1.0 |
|
| 108 | + * |
|
| 109 | + * @NoAdminRequired |
|
| 110 | + * @NoCSRFRequired |
|
| 111 | + * @StrictCookieRequired |
|
| 112 | + * |
|
| 113 | + * @param int $x |
|
| 114 | + * @param int $y |
|
| 115 | + * @param string $file URL-encoded filename |
|
| 116 | + * @return DataResponse|FileDisplayResponse |
|
| 117 | + */ |
|
| 118 | + public function getThumbnail($x, $y, $file) { |
|
| 119 | + if ($x < 1 || $y < 1) { |
|
| 120 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - try { |
|
| 124 | - $file = $this->userFolder->get($file); |
|
| 125 | - if ($file instanceof Folder) { |
|
| 126 | - throw new NotFoundException(); |
|
| 127 | - } |
|
| 123 | + try { |
|
| 124 | + $file = $this->userFolder->get($file); |
|
| 125 | + if ($file instanceof Folder) { |
|
| 126 | + throw new NotFoundException(); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** @var File $file */ |
|
| 130 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
| 129 | + /** @var File $file */ |
|
| 130 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
| 131 | 131 | |
| 132 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
| 133 | - } catch (NotFoundException $e) { |
|
| 134 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 135 | - } catch (\Exception $e) { |
|
| 136 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 137 | - } |
|
| 138 | - } |
|
| 132 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
| 133 | + } catch (NotFoundException $e) { |
|
| 134 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 135 | + } catch (\Exception $e) { |
|
| 136 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Updates the info of the specified file path |
|
| 142 | - * The passed tags are absolute, which means they will |
|
| 143 | - * replace the actual tag selection. |
|
| 144 | - * |
|
| 145 | - * @NoAdminRequired |
|
| 146 | - * |
|
| 147 | - * @param string $path path |
|
| 148 | - * @param array|string $tags array of tags |
|
| 149 | - * @return DataResponse |
|
| 150 | - */ |
|
| 151 | - public function updateFileTags($path, $tags = null) { |
|
| 152 | - $result = []; |
|
| 153 | - // if tags specified or empty array, update tags |
|
| 154 | - if (!is_null($tags)) { |
|
| 155 | - try { |
|
| 156 | - $this->tagService->updateFileTags($path, $tags); |
|
| 157 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 158 | - return new DataResponse([ |
|
| 159 | - 'message' => $e->getMessage() |
|
| 160 | - ], Http::STATUS_NOT_FOUND); |
|
| 161 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 162 | - return new DataResponse([ |
|
| 163 | - 'message' => $e->getMessage() |
|
| 164 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 165 | - } catch (\Exception $e) { |
|
| 166 | - return new DataResponse([ |
|
| 167 | - 'message' => $e->getMessage() |
|
| 168 | - ], Http::STATUS_NOT_FOUND); |
|
| 169 | - } |
|
| 170 | - $result['tags'] = $tags; |
|
| 171 | - } |
|
| 172 | - return new DataResponse($result); |
|
| 173 | - } |
|
| 140 | + /** |
|
| 141 | + * Updates the info of the specified file path |
|
| 142 | + * The passed tags are absolute, which means they will |
|
| 143 | + * replace the actual tag selection. |
|
| 144 | + * |
|
| 145 | + * @NoAdminRequired |
|
| 146 | + * |
|
| 147 | + * @param string $path path |
|
| 148 | + * @param array|string $tags array of tags |
|
| 149 | + * @return DataResponse |
|
| 150 | + */ |
|
| 151 | + public function updateFileTags($path, $tags = null) { |
|
| 152 | + $result = []; |
|
| 153 | + // if tags specified or empty array, update tags |
|
| 154 | + if (!is_null($tags)) { |
|
| 155 | + try { |
|
| 156 | + $this->tagService->updateFileTags($path, $tags); |
|
| 157 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 158 | + return new DataResponse([ |
|
| 159 | + 'message' => $e->getMessage() |
|
| 160 | + ], Http::STATUS_NOT_FOUND); |
|
| 161 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 162 | + return new DataResponse([ |
|
| 163 | + 'message' => $e->getMessage() |
|
| 164 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 165 | + } catch (\Exception $e) { |
|
| 166 | + return new DataResponse([ |
|
| 167 | + 'message' => $e->getMessage() |
|
| 168 | + ], Http::STATUS_NOT_FOUND); |
|
| 169 | + } |
|
| 170 | + $result['tags'] = $tags; |
|
| 171 | + } |
|
| 172 | + return new DataResponse($result); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * @param \OCP\Files\Node[] $nodes |
|
| 177 | - * @return array |
|
| 178 | - */ |
|
| 179 | - private function formatNodes(array $nodes) { |
|
| 180 | - $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
| 181 | - return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
| 182 | - $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
| 183 | - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
| 184 | - $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
| 185 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
| 186 | - if (isset($parts[3])) { |
|
| 187 | - $file['path'] = '/' . $parts[3]; |
|
| 188 | - } else { |
|
| 189 | - $file['path'] = '/'; |
|
| 190 | - } |
|
| 191 | - if (!empty($shareTypes)) { |
|
| 192 | - $file['shareTypes'] = $shareTypes; |
|
| 193 | - } |
|
| 194 | - return $file; |
|
| 195 | - }, $nodes)); |
|
| 196 | - } |
|
| 175 | + /** |
|
| 176 | + * @param \OCP\Files\Node[] $nodes |
|
| 177 | + * @return array |
|
| 178 | + */ |
|
| 179 | + private function formatNodes(array $nodes) { |
|
| 180 | + $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
| 181 | + return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
| 182 | + $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
| 183 | + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
| 184 | + $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
| 185 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
| 186 | + if (isset($parts[3])) { |
|
| 187 | + $file['path'] = '/' . $parts[3]; |
|
| 188 | + } else { |
|
| 189 | + $file['path'] = '/'; |
|
| 190 | + } |
|
| 191 | + if (!empty($shareTypes)) { |
|
| 192 | + $file['shareTypes'] = $shareTypes; |
|
| 193 | + } |
|
| 194 | + return $file; |
|
| 195 | + }, $nodes)); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Get the share types for each node |
|
| 200 | - * |
|
| 201 | - * @param \OCP\Files\Node[] $nodes |
|
| 202 | - * @return array<int, int[]> list of share types for each fileid |
|
| 203 | - */ |
|
| 204 | - private function getShareTypesForNodes(array $nodes): array { |
|
| 205 | - $userId = $this->userSession->getUser()->getUID(); |
|
| 206 | - $requestedShareTypes = [ |
|
| 207 | - IShare::TYPE_USER, |
|
| 208 | - IShare::TYPE_GROUP, |
|
| 209 | - IShare::TYPE_LINK, |
|
| 210 | - IShare::TYPE_REMOTE, |
|
| 211 | - IShare::TYPE_EMAIL, |
|
| 212 | - IShare::TYPE_ROOM, |
|
| 213 | - IShare::TYPE_DECK, |
|
| 214 | - ]; |
|
| 215 | - $shareTypes = []; |
|
| 198 | + /** |
|
| 199 | + * Get the share types for each node |
|
| 200 | + * |
|
| 201 | + * @param \OCP\Files\Node[] $nodes |
|
| 202 | + * @return array<int, int[]> list of share types for each fileid |
|
| 203 | + */ |
|
| 204 | + private function getShareTypesForNodes(array $nodes): array { |
|
| 205 | + $userId = $this->userSession->getUser()->getUID(); |
|
| 206 | + $requestedShareTypes = [ |
|
| 207 | + IShare::TYPE_USER, |
|
| 208 | + IShare::TYPE_GROUP, |
|
| 209 | + IShare::TYPE_LINK, |
|
| 210 | + IShare::TYPE_REMOTE, |
|
| 211 | + IShare::TYPE_EMAIL, |
|
| 212 | + IShare::TYPE_ROOM, |
|
| 213 | + IShare::TYPE_DECK, |
|
| 214 | + ]; |
|
| 215 | + $shareTypes = []; |
|
| 216 | 216 | |
| 217 | - $nodeIds = array_map(function (Node $node) { |
|
| 218 | - return $node->getId(); |
|
| 219 | - }, $nodes); |
|
| 217 | + $nodeIds = array_map(function (Node $node) { |
|
| 218 | + return $node->getId(); |
|
| 219 | + }, $nodes); |
|
| 220 | 220 | |
| 221 | - foreach ($requestedShareTypes as $shareType) { |
|
| 222 | - $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
| 223 | - $offset = 0; |
|
| 221 | + foreach ($requestedShareTypes as $shareType) { |
|
| 222 | + $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
| 223 | + $offset = 0; |
|
| 224 | 224 | |
| 225 | - // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
| 226 | - while (count($nodesLeft) > 0) { |
|
| 227 | - $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
| 228 | - foreach ($shares as $share) { |
|
| 229 | - $fileId = $share->getNodeId(); |
|
| 230 | - if (isset($nodesLeft[$fileId])) { |
|
| 231 | - if (!isset($shareTypes[$fileId])) { |
|
| 232 | - $shareTypes[$fileId] = []; |
|
| 233 | - } |
|
| 234 | - $shareTypes[$fileId][] = $shareType; |
|
| 235 | - unset($nodesLeft[$fileId]); |
|
| 236 | - } |
|
| 237 | - } |
|
| 225 | + // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
| 226 | + while (count($nodesLeft) > 0) { |
|
| 227 | + $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
| 228 | + foreach ($shares as $share) { |
|
| 229 | + $fileId = $share->getNodeId(); |
|
| 230 | + if (isset($nodesLeft[$fileId])) { |
|
| 231 | + if (!isset($shareTypes[$fileId])) { |
|
| 232 | + $shareTypes[$fileId] = []; |
|
| 233 | + } |
|
| 234 | + $shareTypes[$fileId][] = $shareType; |
|
| 235 | + unset($nodesLeft[$fileId]); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - if (count($shares) < 100) { |
|
| 240 | - break; |
|
| 241 | - } else { |
|
| 242 | - $offset += count($shares); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - return $shareTypes; |
|
| 247 | - } |
|
| 239 | + if (count($shares) < 100) { |
|
| 240 | + break; |
|
| 241 | + } else { |
|
| 242 | + $offset += count($shares); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + return $shareTypes; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Returns a list of recently modifed files. |
|
| 251 | - * |
|
| 252 | - * @NoAdminRequired |
|
| 253 | - * |
|
| 254 | - * @return DataResponse |
|
| 255 | - */ |
|
| 256 | - public function getRecentFiles() { |
|
| 257 | - $nodes = $this->userFolder->getRecent(100); |
|
| 258 | - $files = $this->formatNodes($nodes); |
|
| 259 | - return new DataResponse(['files' => $files]); |
|
| 260 | - } |
|
| 249 | + /** |
|
| 250 | + * Returns a list of recently modifed files. |
|
| 251 | + * |
|
| 252 | + * @NoAdminRequired |
|
| 253 | + * |
|
| 254 | + * @return DataResponse |
|
| 255 | + */ |
|
| 256 | + public function getRecentFiles() { |
|
| 257 | + $nodes = $this->userFolder->getRecent(100); |
|
| 258 | + $files = $this->formatNodes($nodes); |
|
| 259 | + return new DataResponse(['files' => $files]); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Change the default sort mode |
|
| 264 | - * |
|
| 265 | - * @NoAdminRequired |
|
| 266 | - * |
|
| 267 | - * @param string $mode |
|
| 268 | - * @param string $direction |
|
| 269 | - * @return Response |
|
| 270 | - * @throws \OCP\PreConditionNotMetException |
|
| 271 | - */ |
|
| 272 | - public function updateFileSorting($mode, $direction) { |
|
| 273 | - $allowedMode = ['name', 'size', 'mtime']; |
|
| 274 | - $allowedDirection = ['asc', 'desc']; |
|
| 275 | - if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
| 276 | - $response = new Response(); |
|
| 277 | - $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
| 278 | - return $response; |
|
| 279 | - } |
|
| 280 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
| 281 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
| 282 | - return new Response(); |
|
| 283 | - } |
|
| 262 | + /** |
|
| 263 | + * Change the default sort mode |
|
| 264 | + * |
|
| 265 | + * @NoAdminRequired |
|
| 266 | + * |
|
| 267 | + * @param string $mode |
|
| 268 | + * @param string $direction |
|
| 269 | + * @return Response |
|
| 270 | + * @throws \OCP\PreConditionNotMetException |
|
| 271 | + */ |
|
| 272 | + public function updateFileSorting($mode, $direction) { |
|
| 273 | + $allowedMode = ['name', 'size', 'mtime']; |
|
| 274 | + $allowedDirection = ['asc', 'desc']; |
|
| 275 | + if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
| 276 | + $response = new Response(); |
|
| 277 | + $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
| 278 | + return $response; |
|
| 279 | + } |
|
| 280 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
| 281 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
| 282 | + return new Response(); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Toggle default for showing/hiding hidden files |
|
| 287 | - * |
|
| 288 | - * @NoAdminRequired |
|
| 289 | - * |
|
| 290 | - * @param bool $show |
|
| 291 | - * @return Response |
|
| 292 | - * @throws \OCP\PreConditionNotMetException |
|
| 293 | - */ |
|
| 294 | - public function showHiddenFiles(bool $show): Response { |
|
| 295 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $show ? '1' : '0'); |
|
| 296 | - return new Response(); |
|
| 297 | - } |
|
| 285 | + /** |
|
| 286 | + * Toggle default for showing/hiding hidden files |
|
| 287 | + * |
|
| 288 | + * @NoAdminRequired |
|
| 289 | + * |
|
| 290 | + * @param bool $show |
|
| 291 | + * @return Response |
|
| 292 | + * @throws \OCP\PreConditionNotMetException |
|
| 293 | + */ |
|
| 294 | + public function showHiddenFiles(bool $show): Response { |
|
| 295 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $show ? '1' : '0'); |
|
| 296 | + return new Response(); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Toggle default for cropping preview images |
|
| 301 | - * |
|
| 302 | - * @NoAdminRequired |
|
| 303 | - * |
|
| 304 | - * @param bool $crop |
|
| 305 | - * @return Response |
|
| 306 | - * @throws \OCP\PreConditionNotMetException |
|
| 307 | - */ |
|
| 308 | - public function cropImagePreviews(bool $crop): Response { |
|
| 309 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $crop ? '1' : '0'); |
|
| 310 | - return new Response(); |
|
| 311 | - } |
|
| 299 | + /** |
|
| 300 | + * Toggle default for cropping preview images |
|
| 301 | + * |
|
| 302 | + * @NoAdminRequired |
|
| 303 | + * |
|
| 304 | + * @param bool $crop |
|
| 305 | + * @return Response |
|
| 306 | + * @throws \OCP\PreConditionNotMetException |
|
| 307 | + */ |
|
| 308 | + public function cropImagePreviews(bool $crop): Response { |
|
| 309 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $crop ? '1' : '0'); |
|
| 310 | + return new Response(); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Toggle default for files grid view |
|
| 315 | - * |
|
| 316 | - * @NoAdminRequired |
|
| 317 | - * |
|
| 318 | - * @param bool $show |
|
| 319 | - * @return Response |
|
| 320 | - * @throws \OCP\PreConditionNotMetException |
|
| 321 | - */ |
|
| 322 | - public function showGridView(bool $show): Response { |
|
| 323 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
| 324 | - return new Response(); |
|
| 325 | - } |
|
| 313 | + /** |
|
| 314 | + * Toggle default for files grid view |
|
| 315 | + * |
|
| 316 | + * @NoAdminRequired |
|
| 317 | + * |
|
| 318 | + * @param bool $show |
|
| 319 | + * @return Response |
|
| 320 | + * @throws \OCP\PreConditionNotMetException |
|
| 321 | + */ |
|
| 322 | + public function showGridView(bool $show): Response { |
|
| 323 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
| 324 | + return new Response(); |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * Get default settings for the grid view |
|
| 329 | - * |
|
| 330 | - * @NoAdminRequired |
|
| 331 | - */ |
|
| 332 | - public function getGridView() { |
|
| 333 | - $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
| 334 | - return new JSONResponse(['gridview' => $status]); |
|
| 335 | - } |
|
| 327 | + /** |
|
| 328 | + * Get default settings for the grid view |
|
| 329 | + * |
|
| 330 | + * @NoAdminRequired |
|
| 331 | + */ |
|
| 332 | + public function getGridView() { |
|
| 333 | + $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
| 334 | + return new JSONResponse(['gridview' => $status]); |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * Toggle default for showing/hiding xxx folder |
|
| 339 | - * |
|
| 340 | - * @NoAdminRequired |
|
| 341 | - * |
|
| 342 | - * @param int $show |
|
| 343 | - * @param string $key the key of the folder |
|
| 344 | - * |
|
| 345 | - * @return Response |
|
| 346 | - * @throws \OCP\PreConditionNotMetException |
|
| 347 | - */ |
|
| 348 | - public function toggleShowFolder(int $show, string $key): Response { |
|
| 349 | - // ensure the edited key exists |
|
| 350 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 351 | - foreach ($navItems as $item) { |
|
| 352 | - // check if data is valid |
|
| 353 | - if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { |
|
| 354 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (string)$show); |
|
| 355 | - return new Response(); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - $response = new Response(); |
|
| 359 | - $response->setStatus(Http::STATUS_FORBIDDEN); |
|
| 360 | - return $response; |
|
| 361 | - } |
|
| 337 | + /** |
|
| 338 | + * Toggle default for showing/hiding xxx folder |
|
| 339 | + * |
|
| 340 | + * @NoAdminRequired |
|
| 341 | + * |
|
| 342 | + * @param int $show |
|
| 343 | + * @param string $key the key of the folder |
|
| 344 | + * |
|
| 345 | + * @return Response |
|
| 346 | + * @throws \OCP\PreConditionNotMetException |
|
| 347 | + */ |
|
| 348 | + public function toggleShowFolder(int $show, string $key): Response { |
|
| 349 | + // ensure the edited key exists |
|
| 350 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 351 | + foreach ($navItems as $item) { |
|
| 352 | + // check if data is valid |
|
| 353 | + if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { |
|
| 354 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (string)$show); |
|
| 355 | + return new Response(); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + $response = new Response(); |
|
| 359 | + $response->setStatus(Http::STATUS_FORBIDDEN); |
|
| 360 | + return $response; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - /** |
|
| 364 | - * Get sorting-order for custom sorting |
|
| 365 | - * |
|
| 366 | - * @NoAdminRequired |
|
| 367 | - * |
|
| 368 | - * @param string $folderpath |
|
| 369 | - * @return string |
|
| 370 | - * @throws \OCP\Files\NotFoundException |
|
| 371 | - */ |
|
| 372 | - public function getNodeType($folderpath) { |
|
| 373 | - $node = $this->userFolder->get($folderpath); |
|
| 374 | - return $node->getType(); |
|
| 375 | - } |
|
| 363 | + /** |
|
| 364 | + * Get sorting-order for custom sorting |
|
| 365 | + * |
|
| 366 | + * @NoAdminRequired |
|
| 367 | + * |
|
| 368 | + * @param string $folderpath |
|
| 369 | + * @return string |
|
| 370 | + * @throws \OCP\Files\NotFoundException |
|
| 371 | + */ |
|
| 372 | + public function getNodeType($folderpath) { |
|
| 373 | + $node = $this->userFolder->get($folderpath); |
|
| 374 | + return $node->getType(); |
|
| 375 | + } |
|
| 376 | 376 | } |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | private function formatNodes(array $nodes) { |
| 180 | 180 | $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
| 181 | - return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
| 181 | + return array_values(array_map(function(Node $node) use ($shareTypesForNodes) { |
|
| 182 | 182 | $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
| 183 | 183 | $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
| 184 | 184 | $file['hasPreview'] = $this->previewManager->isAvailable($node); |
| 185 | 185 | $parts = explode('/', dirname($node->getPath()), 4); |
| 186 | 186 | if (isset($parts[3])) { |
| 187 | - $file['path'] = '/' . $parts[3]; |
|
| 187 | + $file['path'] = '/'.$parts[3]; |
|
| 188 | 188 | } else { |
| 189 | 189 | $file['path'] = '/'; |
| 190 | 190 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | ]; |
| 215 | 215 | $shareTypes = []; |
| 216 | 216 | |
| 217 | - $nodeIds = array_map(function (Node $node) { |
|
| 217 | + $nodeIds = array_map(function(Node $node) { |
|
| 218 | 218 | return $node->getId(); |
| 219 | 219 | }, $nodes); |
| 220 | 220 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | foreach ($navItems as $item) { |
| 352 | 352 | // check if data is valid |
| 353 | 353 | if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { |
| 354 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (string)$show); |
|
| 354 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (string) $show); |
|
| 355 | 355 | return new Response(); |
| 356 | 356 | } |
| 357 | 357 | } |