From 5e5c5a16dc6b26b7a9c367a2a395527ea818c764 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 14 Mar 2019 15:12:16 +0100 Subject: [PATCH 1/2] Add correct method for hardcoded `/f/{fileid}` Signed-off-by: Joas Schilling --- apps/files/lib/Controller/ViewController.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index fc0fb120cfe4f..3f35b8b7be584 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -128,6 +128,18 @@ protected function getStorageInfo() { return \OC_Helper::getStorageInfo('/', $dirInfo); } + /** + * @NoCSRFRequired + * @NoAdminRequired + * + * @param string $fileid + * @return TemplateResponse|RedirectResponse + */ + public function showFile(string $fileid = null): Response { + // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. + return $this->redirectToFile($fileid); + } + /** * @NoCSRFRequired * @NoAdminRequired @@ -140,7 +152,7 @@ protected function getStorageInfo() { public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { if ($fileid !== null) { try { - return $this->showFile($fileid); + return $this->redirectToFile($fileid); } catch (NotFoundException $e) { return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); } @@ -285,7 +297,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal * @return RedirectResponse redirect response or not found response * @throws \OCP\Files\NotFoundException */ - private function showFile($fileId) { + private function redirectToFile($fileId) { $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); $files = $baseFolder->getById($fileId); From 37b1a9c4ea73ac2a9a49f306731a204caa33c44a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 14 Mar 2019 16:28:01 +0100 Subject: [PATCH 2/2] Import needed class Signed-off-by: Morris Jobke --- apps/files/lib/Controller/ViewController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 3f35b8b7be584..9f9cd0b33c15d 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -32,6 +32,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; use OCP\App\IAppManager; use OCP\Files\Folder;