Skip to content

Commit

Permalink
Merge pull request #47015 from nextcloud/fix/open-file
Browse files Browse the repository at this point in the history
fix(files): Correctly handle open file URL query
  • Loading branch information
juliushaertl authored Aug 3, 2024
2 parents bbdf69a + 926c095 commit 50e6108
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ private function redirectToFile(int $fileId) {
} else {
// set parent path as dir
$params['dir'] = $baseFolder->getRelativePath($node->getParent()->getPath());
// open the file by default (opening the viewer)
$params['openfile'] = 'true';
}
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params));
}
Expand Down
7 changes: 5 additions & 2 deletions apps/files/src/composables/useRouteParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useRouteParameters() {
const directory = computed<string>(
() => String(route.query.dir || '/')
// Remove any trailing slash but leave root slash
.replace(/^(.+)\/$/, '$1')
.replace(/^(.+)\/$/, '$1'),
)

/**
Expand All @@ -32,7 +32,10 @@ export function useRouteParameters() {
/**
* State of `openFile` route param
*/
const openFile = computed<boolean>(() => 'openFile' in route.params && route.params.openFile.toLocaleLowerCase() !== 'false')
const openFile = computed<boolean>(
// if `openfile` is set it is considered truthy, but allow to explicitly set it to 'false'
() => 'openfile' in route.query && (typeof route.query.openfile !== 'string' || route.query.openfile.toLocaleLowerCase() !== 'false'),
)

return {
/** Path of currently open directory */
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit 50e6108

Please sign in to comment.