diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-12-06 09:59:40 +0100 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-12-12 20:32:40 +0100 |
commit | 9cd52975d21188ae50bb11d3c425b0b1f13f4c94 (patch) | |
tree | e217aa80feea50668d3d371bd7c0887a26121f81 /apps | |
parent | 87cba94401c94a0594d140f31e17901dfbf443ab (diff) | |
download | nextcloud-server-9cd52975d21188ae50bb11d3c425b0b1f13f4c94.tar.gz nextcloud-server-9cd52975d21188ae50bb11d3c425b0b1f13f4c94.zip |
fix(files): failsafe when executing actions methods
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/src/components/FileEntry/FileEntryActions.vue | 39 | ||||
-rw-r--r-- | apps/files/src/components/FileEntryMixin.ts | 26 |
2 files changed, 48 insertions, 17 deletions
diff --git a/apps/files/src/components/FileEntry/FileEntryActions.vue b/apps/files/src/components/FileEntry/FileEntryActions.vue index 06b447295eb..a3e469f144b 100644 --- a/apps/files/src/components/FileEntry/FileEntryActions.vue +++ b/apps/files/src/components/FileEntry/FileEntryActions.vue @@ -163,7 +163,14 @@ export default defineComponent({ if (this.filesListWidth < 768 || this.gridMode) { return [] } - return this.enabledFileActions.filter(action => action?.inline?.(this.source, this.currentView)) + return this.enabledFileActions.filter(action => { + try { + return action?.inline?.(this.source, this.currentView) + } catch (error) { + logger.error('Error while checking if action is inline', { action, error }) + return false + } + }) }, // Enabled action that are displayed inline with a custom render function @@ -236,13 +243,19 @@ export default defineComponent({ methods: { actionDisplayName(action: FileAction) { - if ((this.gridMode || (this.filesListWidth < 768 && action.inline)) && typeof action.title === 'function') { - // if an inline action is rendered in the menu for - // lack of space we use the title first if defined - const title = action.title([this.source], this.currentView) - if (title) return title + try { + if ((this.gridMode || (this.filesListWidth < 768 && action.inline)) && typeof action.title === 'function') { + // if an inline action is rendered in the menu for + // lack of space we use the title first if defined + const title = action.title([this.source], this.currentView) + if (title) return title + } + return action.displayName([this.source], this.currentView) + } catch (error) { + logger.error('Error while getting action display name', { action, error }) + // Not ideal, but better than nothing + return action.id } - return action.displayName([this.source], this.currentView) }, async onActionClick(action, isSubmenu = false) { @@ -257,7 +270,13 @@ export default defineComponent({ return } - const displayName = action.displayName([this.source], this.currentView) + let displayName = action.id + try { + displayName = action.displayName([this.source], this.currentView) + } catch (error) { + logger.error('Error while getting action display name', { action, error }) + } + try { // Set the loading marker this.$emit('update:loading', action.id) @@ -275,8 +294,8 @@ export default defineComponent({ return } showError(t('files', '"{displayName}" action failed', { displayName })) - } catch (e) { - logger.error('Error while executing action', { action, e }) + } catch (error) { + logger.error('Error while executing action', { action, error }) showError(t('files', '"{displayName}" action failed', { displayName })) } finally { // Reset the loading marker diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts index e325d97b8f8..06fc2d906db 100644 --- a/apps/files/src/components/FileEntryMixin.ts +++ b/apps/files/src/components/FileEntryMixin.ts @@ -2,23 +2,22 @@ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ - import type { PropType } from 'vue' import type { FileSource } from '../types.ts' -import { showError } from '@nextcloud/dialogs' +import { extname } from 'path' import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, getFileActions } from '@nextcloud/files' -import { translate as t } from '@nextcloud/l10n' import { generateUrl } from '@nextcloud/router' +import { showError } from '@nextcloud/dialogs' +import { translate as t } from '@nextcloud/l10n' import { vOnClickOutside } from '@vueuse/components' -import { extname } from 'path' import Vue, { defineComponent } from 'vue' import { action as sidebarAction } from '../actions/sidebarAction.ts' +import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts' import { getDragAndDropPreview } from '../utils/dragUtils.ts' import { hashCode } from '../utils/hashUtils.ts' -import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts' -import logger from '../logger.ts' +import logger from '../logger.js' Vue.directive('onClickOutside', vOnClickOutside) @@ -198,7 +197,20 @@ export default defineComponent({ } return actions - .filter(action => !action.enabled || action.enabled([this.source], this.currentView)) + .filter(action => { + if (!action.enabled) { + return true + } + + // In case something goes wrong, since we don't want to break + // the entire list, we filter out actions that throw an error. + try { + return action.enabled([this.source], this.currentView) + } catch (error) { + logger.error('Error while checking action', { action, error }) + return false + } + }) .sort((a, b) => (a.order || 0) - (b.order || 0)) }, |