aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Controller/ViewController.php
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2025-02-14 09:28:58 +0100
committerskjnldsv <skjnldsv@protonmail.com>2025-02-18 10:53:23 +0100
commit2e50a39265e09ac5e8de6ec53cff1546aafe8629 (patch)
tree970943e299b7eea185bf5352c47db97093adee5e /apps/files/lib/Controller/ViewController.php
parent8886f367e433277cf7aa0c01b93a9d4348db47a8 (diff)
downloadnextcloud-server-2e50a39265e09ac5e8de6ec53cff1546aafe8629.tar.gz
nextcloud-server-2e50a39265e09ac5e8de6ec53cff1546aafe8629.zip
fix(files): properly forward open params from short urls
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/lib/Controller/ViewController.php')
-rw-r--r--apps/files/lib/Controller/ViewController.php40
1 files changed, 26 insertions, 14 deletions
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index a0b5c1c282c..50b0ae558aa 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -82,16 +82,18 @@ class ViewController extends Controller {
*/
#[NoAdminRequired]
#[NoCSRFRequired]
- public function showFile(?string $fileid = null): Response {
+ public function showFile(?string $fileid = null, ?string $opendetails = null, ?string $openfile = null): Response {
if (!$fileid) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
}
// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
try {
- return $this->redirectToFile((int)$fileid);
+ return $this->redirectToFile((int)$fileid, $opendetails, $openfile);
} catch (NotFoundException $e) {
- return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
+ // Keep the fileid even if not found, it will be used
+ // to detect the file could not be found and warn the user
+ return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', ['fileid' => $fileid, 'view' => 'files']));
}
}
@@ -100,38 +102,35 @@ class ViewController extends Controller {
* @param string $dir
* @param string $view
* @param string $fileid
- * @param bool $fileNotFound
* @return TemplateResponse|RedirectResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
- public function indexView($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
- return $this->index($dir, $view, $fileid, $fileNotFound);
+ public function indexView($dir = '', $view = '', $fileid = null) {
+ return $this->index($dir, $view, $fileid);
}
/**
* @param string $dir
* @param string $view
* @param string $fileid
- * @param bool $fileNotFound
* @return TemplateResponse|RedirectResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
- public function indexViewFileid($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
- return $this->index($dir, $view, $fileid, $fileNotFound);
+ public function indexViewFileid($dir = '', $view = '', $fileid = null) {
+ return $this->index($dir, $view, $fileid);
}
/**
* @param string $dir
* @param string $view
* @param string $fileid
- * @param bool $fileNotFound
* @return TemplateResponse|RedirectResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
- public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
+ public function index($dir = '', $view = '', $fileid = null) {
if ($fileid !== null && $view !== 'trashbin') {
try {
return $this->redirectToFileIfInTrashbin((int)$fileid);
@@ -159,8 +158,6 @@ class ViewController extends Controller {
if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) {
return $this->redirectToFile((int)$fileid);
}
- } else { // fileid does not exist anywhere
- $fileNotFound = true;
}
}
@@ -249,10 +246,12 @@ class ViewController extends Controller {
* Redirects to the file list and highlight the given file id
*
* @param int $fileId file id to show
+ * @param string|null $openDetails open details parameter
+ * @param string|null $openFile open file parameter
* @return RedirectResponse redirect response or not found response
* @throws NotFoundException
*/
- private function redirectToFile(int $fileId) {
+ private function redirectToFile(int $fileId, ?string $openDetails = null, ?string $openFile = null): RedirectResponse {
$uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid);
$node = $baseFolder->getFirstNodeById($fileId);
@@ -274,6 +273,19 @@ class ViewController extends Controller {
// open the file by default (opening the viewer)
$params['openfile'] = 'true';
}
+
+ // Forward open parameters if any.
+ // - openfile is true by default
+ // - opendetails is undefined by default
+ // - both will be evaluated as truthy
+ if ($openDetails !== null) {
+ $params['opendetails'] = $openDetails !== 'false' ? 'true' : 'false';
+ }
+
+ if ($openFile !== null) {
+ $params['openfile'] = $openFile !== 'false' ? 'true' : 'false';
+ }
+
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params));
}