fix: redirect to proper directory if file not found

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2023-09-19 21:00:21 +02:00 committed by John Molakvoæ
parent 529bce24b4
commit b05719c8e9
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF

View file

@ -231,6 +231,19 @@ class ViewController extends Controller {
$favElements['folders'] = [];
}
// If the file doesn't exists in the folder and
// exists in only one occurrence, redirect to that file
// in the correct folder
if ($fileid && $dir !== '') {
$baseFolder = $this->rootFolder->getUserFolder($userId);
$nodes = $baseFolder->getById((int) $fileid);
$relativePath = dirname($baseFolder->getRelativePath($nodes[0]->getPath()));
// If the requested path is different from the file path
if (count($nodes) === 1 && $relativePath !== $dir) {
return $this->redirectToFile((int) $fileid);
}
}
try {
// If view is files, we use the directory, otherwise we use the root storage
$storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/');
@ -380,7 +393,7 @@ class ViewController extends Controller {
$uid = $this->userSession->getUser()->getUID();
$baseFolder = $this->rootFolder->getUserFolder($uid);
$nodes = $baseFolder->getById($fileId);
$params = [];
$params = ['view' => 'files'];
try {
$this->redirectToFileIfInTrashbin($fileId);