Skip to content

Commit

Permalink
fix(files): protect filelist actions with try...catch
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 12, 2024
1 parent 6a14eb5 commit 4a9fca3
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
force-name>
<NcActionButton v-for="action in enabledFileListActions"
:key="action.id"
:disabled="loadingAction"
close-after-click
@click="action.exec(currentView, dirContents, currentFolder)">
@click="execFileListAction(action)">
<template #icon>
<NcIconSvgWrapper v-if="action.iconSvgInline !== undefined"
<NcLoadingIcon v-if="loadingAction === action.id" :size="18" />
<NcIconSvgWrapper v-else-if="action.iconSvgInline !== undefined"
:svg="action.iconSvgInline(currentView)" />
</template>
{{ action.displayName(currentView) }}
{{ actionDisplayName(currentView) }}
</NcActionButton>
</NcActions>

Expand Down Expand Up @@ -132,7 +134,7 @@
</template>

<script lang="ts">
import type { ContentsWithRoot, Folder, INode } from '@nextcloud/files'
import type { ContentsWithRoot, FileListAction, Folder, INode } from '@nextcloud/files'
import type { Upload } from '@nextcloud/upload'
import type { CancelablePromise } from 'cancelable-promise'
import type { ComponentPublicInstance } from 'vue'
Expand All @@ -144,7 +146,7 @@ import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Node, Permission, sortNodes, getFileListActions } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { join, dirname, normalize } from 'path'
import { showError, showWarning } from '@nextcloud/dialogs'
import { showError, showSuccess, showWarning } from '@nextcloud/dialogs'
import { ShareType } from '@nextcloud/sharing'
import { UploadPicker, UploadStatus } from '@nextcloud/upload'
import { loadState } from '@nextcloud/initial-state'
Expand Down Expand Up @@ -258,6 +260,7 @@ export default defineComponent({
data() {
return {
loading: true,
loadingAction: null as string | null,
error: null as string | null,
promise: null as CancelablePromise<ContentsWithRoot> | Promise<ContentsWithRoot> | null,

Expand Down Expand Up @@ -714,6 +717,40 @@ export default defineComponent({
}
this.dirContentsFiltered = nodes
},

actionDisplayName(action: FileListAction): string {
let displayName = action.id
try {
displayName = action.displayName(this.currentView)
} catch (error) {
logger.error('Error while getting action display name', { action, error })
}
return displayName
},

async execFileListAction(action: FileListAction) {
this.loadingAction = action.id

const displayName = this.actionDisplayName(action)
try {
const success = await action.exec(this.source, this.currentView, this.currentDir)
// If the action returns null, we stay silent
if (success === null || success === undefined) {
return
}

if (success) {
showSuccess(t('files', '"{displayName}" action executed successfully', { displayName }))
return
}
showError(t('files', '"{displayName}" action failed', { displayName }))
} catch (error) {
logger.error('Error while executing action', { action, error })
showError(t('files', '"{displayName}" action failed', { displayName }))
} finally {
this.loadingAction = null
}
},
},
})
</script>
Expand Down

0 comments on commit 4a9fca3

Please sign in to comment.