Skip to content

Commit

Permalink
Merge pull request #28174 from nextcloud/feature/set_openfile_for_int…
Browse files Browse the repository at this point in the history
…ernal_links
  • Loading branch information
skjnldsv authored Jul 28, 2021
2 parents a71294e + 1ad5e8a commit 3ced840
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function getStorageInfo() {
public function showFile(string $fileid = null): Response {
// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
try {
return $this->redirectToFile($fileid);
return $this->redirectToFile($fileid, true);
} catch (NotFoundException $e) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
}
Expand All @@ -179,7 +179,7 @@ public function showFile(string $fileid = null): Response {
* @param string $view
* @param string $fileid
* @param bool $fileNotFound
* @param string $openfile
* @param string $openfile - the openfile URL parameter if it was present in the initial request
* @return TemplateResponse|RedirectResponse
* @throws NotFoundException
*/
Expand Down Expand Up @@ -391,10 +391,11 @@ private function provideInitialState(string $dir, ?string $openfile): void {
* Redirects to the file list and highlight the given file id
*
* @param string $fileId file id to show
* @param bool $setOpenfile - whether or not to set the openfile URL parameter
* @return RedirectResponse redirect response or not found response
* @throws \OCP\Files\NotFoundException
*/
private function redirectToFile($fileId) {
private function redirectToFile($fileId, bool $setOpenfile = false) {
$uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid);
$files = $baseFolder->getById($fileId);
Expand All @@ -416,6 +417,11 @@ private function redirectToFile($fileId) {
$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
// and scroll to the entry
$params['scrollto'] = $file->getName();

if ($setOpenfile) {
// forward the openfile URL parameter.
$params['openfile'] = $fileId;
}
}

return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
Expand Down

0 comments on commit 3ced840

Please sign in to comment.