Add correct method for hardcoded `/f/{fileid}`

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-03-14 15:12:16 +01:00
parent 762a8bb3d9
commit 5e5c5a16dc
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 14 additions and 2 deletions

View File

@ -128,6 +128,18 @@ class ViewController extends Controller {
return \OC_Helper::getStorageInfo('/', $dirInfo); 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 * @NoCSRFRequired
* @NoAdminRequired * @NoAdminRequired
@ -140,7 +152,7 @@ class ViewController extends Controller {
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
if ($fileid !== null) { if ($fileid !== null) {
try { try {
return $this->showFile($fileid); return $this->redirectToFile($fileid);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
} }
@ -285,7 +297,7 @@ class ViewController extends Controller {
* @return RedirectResponse redirect response or not found response * @return RedirectResponse redirect response or not found response
* @throws \OCP\Files\NotFoundException * @throws \OCP\Files\NotFoundException
*/ */
private function showFile($fileId) { private function redirectToFile($fileId) {
$uid = $this->userSession->getUser()->getUID(); $uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid); $baseFolder = $this->rootFolder->getUserFolder($uid);
$files = $baseFolder->getById($fileId); $files = $baseFolder->getById($fileId);