mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
refactor: add enum for filename sanitization also in the frontend
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
805fe3e15b
commit
a42bd7a507
2 changed files with 22 additions and 6 deletions
|
|
@ -11,15 +11,16 @@ import { showError } from '@nextcloud/dialogs'
|
|||
import { loadState } from '@nextcloud/initial-state'
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
import { computed, ref, shallowRef } from 'vue'
|
||||
import NcButton from '@nextcloud/vue/components/NcButton'
|
||||
import NcInputField from '@nextcloud/vue/components/NcInputField'
|
||||
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
|
||||
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
|
||||
import NcProgressBar from '@nextcloud/vue/components/NcProgressBar'
|
||||
import { computed, ref, shallowRef } from 'vue'
|
||||
import { SanitizeFilenameStatus } from '../../models/SanitizeFilenameStatus.ts'
|
||||
import logger from '../../logger.ts'
|
||||
|
||||
type ApiStatus = { total: number, processed: number, errors?: Record<string, string[]>, status: 0 | 1 | 2 | 3 | 4 }
|
||||
type ApiStatus = { total: number, processed: number, errors?: Record<string, string[]>, status: SanitizeFilenameStatus }
|
||||
|
||||
const { status: initialStatus } = loadState<{ isRunningSanitization: boolean, status: ApiStatus }>('files', 'filesCompatibilitySettings')
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ const totalUsers = ref(initialStatus.total)
|
|||
const errors = shallowRef<ApiStatus['errors']>(initialStatus.errors || {})
|
||||
|
||||
const progress = computed(() => processedUsers.value > 0 ? Math.round((processedUsers.value * 100) / totalUsers.value) : 0)
|
||||
const isRunning = computed(() => status.value === 1 || status.value === 2)
|
||||
const isRunning = computed(() => status.value === SanitizeFilenameStatus.Scheduled || status.value === SanitizeFilenameStatus.Running)
|
||||
|
||||
/**
|
||||
* Start the sanitization process
|
||||
|
|
@ -46,7 +47,7 @@ async function startSanitization() {
|
|||
await axios.post(generateOcsUrl('apps/files/api/v1/filenames/sanitization'), {
|
||||
limit: renameLimit.value,
|
||||
})
|
||||
status.value = 1
|
||||
status.value = SanitizeFilenameStatus.Scheduled
|
||||
} catch (error) {
|
||||
logger.error('Failed to start filename sanitization.', { error })
|
||||
|
||||
|
|
@ -107,7 +108,7 @@ async function refreshStatus() {
|
|||
</div>
|
||||
</NcNoteCard>
|
||||
|
||||
<NcNoteCard v-else-if="status === 3" type="success">
|
||||
<NcNoteCard v-else-if="status === SanitizeFilenameStatus.Done" type="success">
|
||||
{{ t('files', 'All files have been santized for Windows filename support.') }}
|
||||
</NcNoteCard>
|
||||
|
||||
|
|
@ -115,7 +116,7 @@ async function refreshStatus() {
|
|||
class="sanitize-filenames__form"
|
||||
:disabled="loading"
|
||||
@submit.stop.prevent="startSanitization">
|
||||
<NcNoteCard v-if="status === 4" type="error">
|
||||
<NcNoteCard v-if="status === SanitizeFilenameStatus.Error" type="error">
|
||||
{{ t('files', 'Some files could not be sanitized, please check your logs.') }}
|
||||
<ul class="sanitize-filenames__errors" :aria-label="t('files', 'Sanitization errors')">
|
||||
<li v-for="[user, failedFiles] of Object.entries(errors)" :key="user">
|
||||
|
|
|
|||
15
apps/files/src/models/SanitizeFilenameStatus.ts
Normal file
15
apps/files/src/models/SanitizeFilenameStatus.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/*!
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/**
|
||||
* The current status of the filename sanitization
|
||||
*/
|
||||
export enum SanitizeFilenameStatus {
|
||||
Unknown = 0,
|
||||
Scheduled = 1,
|
||||
Running = 2,
|
||||
Done = 3,
|
||||
Error = 4,
|
||||
}
|
||||
Loading…
Reference in a new issue