getFile($path); return new DataResponse($this->fileTargetService->getFileTargets($file)); } catch (NotFoundException $e) { } return new DataResponse('File not found', Http::STATUS_NOT_FOUND); } /** * @NoAdminRequired * @NoCSRFRequired */ public function getPreview(string $path, string $target): Response { try { $file = $this->getFile($path); return new DataDisplayResponse( $this->fileTargetService->getTargetPreview($file, $target), Http::STATUS_OK, ['Content-Type' => 'image/png'] ); } catch (NotFoundException $e) { return new DataResponse('File not found', Http::STATUS_NOT_FOUND); } } /** * @throws NotFoundException */ private function getFile(string $path): File { try { $file = $this->rootFolder->getUserFolder($this->userId)->get($path); if (!$file instanceof File) { throw new NotFoundException(); } return $file; } catch (NotFoundException|NotPermittedException|NoUserException $e) { throw new NotFoundException(); } } }