diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-05 17:56:22 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-06 02:17:25 +0100 |
commit | dbc5c10bc408fd5b50a81cddfc25ba226d02fec9 (patch) | |
tree | 76686f1aa9b1da2dd6b6cad5fde6d985821f4163 /apps/files/src/router | |
parent | 24f2e933930fb4c06e312df0757bbaca26446011 (diff) | |
download | nextcloud-server-dbc5c10bc408fd5b50a81cddfc25ba226d02fec9.tar.gz nextcloud-server-dbc5c10bc408fd5b50a81cddfc25ba226d02fec9.zip |
fix(files): Do not download files with `openfile` query flag
Instead of downloading files, if there is no other default action,
we should just open the details tab.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files/src/router')
-rw-r--r-- | apps/files/src/router/router.ts | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/apps/files/src/router/router.ts b/apps/files/src/router/router.ts index de81755d234..13e74c26451 100644 --- a/apps/files/src/router/router.ts +++ b/apps/files/src/router/router.ts @@ -3,20 +3,41 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { RawLocation, Route } from 'vue-router' -import type { ErrorHandler } from 'vue-router/types/router.d.ts' - import { generateUrl } from '@nextcloud/router' import queryString from 'query-string' -import Router from 'vue-router' +import Router, { isNavigationFailure, NavigationFailureType } from 'vue-router' import Vue from 'vue' +import logger from '../logger' Vue.use(Router) // Prevent router from throwing errors when we're already on the page we're trying to go to -const originalPush = Router.prototype.push as (to, onComplete?, onAbort?) => Promise<Route> -Router.prototype.push = function push(to: RawLocation, onComplete?: ((route: Route) => void) | undefined, onAbort?: ErrorHandler | undefined): Promise<Route> { - if (onComplete || onAbort) return originalPush.call(this, to, onComplete, onAbort) - return originalPush.call(this, to).catch(err => err) +const originalPush = Router.prototype.push +Router.prototype.push = (function(this: Router, ...args: Parameters<typeof originalPush>) { + if (args.length > 1) { + return originalPush.call(this, ...args) + } + return originalPush.call<Router, [RawLocation], Promise<Route>>(this, args[0]).catch(ignoreDuplicateNavigation) +}) as typeof originalPush + +const originalReplace = Router.prototype.replace +Router.prototype.replace = (function(this: Router, ...args: Parameters<typeof originalReplace>) { + if (args.length > 1) { + return originalReplace.call(this, ...args) + } + return originalReplace.call<Router, [RawLocation], Promise<Route>>(this, args[0]).catch(ignoreDuplicateNavigation) +}) as typeof originalReplace + +/** + * Ignore duplicated-navigation error but forward real exceptions + * @param error The thrown error + */ +function ignoreDuplicateNavigation(error: unknown): void { + if (isNavigationFailure(error, NavigationFailureType.duplicated)) { + logger.debug('Ignoring duplicated navigation from vue-router', { error }) + } else { + throw error + } } const router = new Router({ |