From dbc5c10bc408fd5b50a81cddfc25ba226d02fec9 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 5 Feb 2025 17:56:22 +0100 Subject: 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 --- apps/files/src/router/router.ts | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'apps/files/src/router') 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 -Router.prototype.push = function push(to: RawLocation, onComplete?: ((route: Route) => void) | undefined, onAbort?: ErrorHandler | undefined): Promise { - 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) { + if (args.length > 1) { + return originalPush.call(this, ...args) + } + return originalPush.call>(this, args[0]).catch(ignoreDuplicateNavigation) +}) as typeof originalPush + +const originalReplace = Router.prototype.replace +Router.prototype.replace = (function(this: Router, ...args: Parameters) { + if (args.length > 1) { + return originalReplace.call(this, ...args) + } + return originalReplace.call>(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({ -- cgit v1.2.3