mirror of
https://github.com/vastsa/FileCodeBoxFronted.git
synced 2026-11-24 21:58:01 +08:00
refactor: organize upload and file management flows
This commit is contained in:
1 parent
30637620da
commit
bf979924a5
24 files changed
+1925
-359
No files matched your search
@@ -10,7 +10,9 @@
|
||||
"build-only": "vite build",
|
||||
"type-check": "vue-tsc --build --force",
|
||||
"check:architecture": "node scripts/check-architecture.mjs",
|
||||
"test": "vitest run",
|
||||
"lint": "eslint . --fix",
|
||||
"lint:check": "eslint .",
|
||||
"format": "prettier --write src/"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -42,11 +44,13 @@
|
||||
"@vitejs/plugin-vue-jsx": "^5.0.1",
|
||||
"@vue/eslint-config-prettier": "^10.2.0",
|
||||
"@vue/eslint-config-typescript": "^14.6.0",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-vue": "^10.4.0",
|
||||
"glob": "^13.0.0",
|
||||
"jsdom": "^27.2.0",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"postcss": "^8.5.6",
|
||||
"prettier": "^3.6.2",
|
||||
@@ -54,6 +58,7 @@
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.3.0",
|
||||
"vitest": "^4.0.15",
|
||||
"vue-tsc": "^3.0.4"
|
||||
}
|
||||
}
|
||||
Generated
+716
-17
File diff suppressed because it is too large.
Load diff
@@ -230,7 +230,7 @@ for (const rule of rules) {
|
||||
cwd: rootDir,
|
||||
absolute: true,
|
||||
nodir: true,
|
||||
ignore: ['node_modules/**', 'dist/**'],
|
||||
ignore: ['node_modules/**', 'dist/**', 'src/**/*.test.ts', 'src/**/*.spec.ts', 'src/**/__tests__/**'],
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<section
|
||||
v-if="visible"
|
||||
class="mb-4 flex flex-col gap-3 rounded-lg border px-4 py-3 sm:flex-row sm:items-center sm:justify-between"
|
||||
:class="[panelClass]"
|
||||
>
|
||||
<label class="inline-flex items-center gap-2 text-sm" :class="[primaryTextClass]">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 rounded border-gray-300 text-zinc-600 focus:ring-zinc-500"
|
||||
:checked="isAllCurrentPageSelected"
|
||||
:disabled="isBatchActionRunning"
|
||||
:indeterminate="isCurrentPagePartiallySelected"
|
||||
@change="$emit('toggle-current-page-selection')"
|
||||
/>
|
||||
<span>
|
||||
{{
|
||||
hasSelectedFiles
|
||||
? t('fileManage.selectedCount', { count: selectedCount })
|
||||
: t('fileManage.selectCurrentPage')
|
||||
}}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<BaseButton
|
||||
v-if="hasSelectedFiles"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="isBatchActionRunning"
|
||||
@click="$emit('clear-selection')"
|
||||
>
|
||||
<template #icon>
|
||||
<XIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.clearSelection') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-for="option in batchPolicyActionOptions"
|
||||
:key="option.action"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:title="option.description"
|
||||
:disabled="!hasSelectedFiles || isBatchDeleting || isBatchUpdating"
|
||||
:loading="isBatchPolicyActionRunning"
|
||||
@click="$emit('apply-policy-action', option.action)"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="getPolicyActionIcon(option.action)" class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ option.label }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
:disabled="!hasSelectedFiles || isBatchDeleting || isBatchPolicyActionRunning"
|
||||
:loading="isBatchUpdating"
|
||||
@click="$emit('open-batch-edit')"
|
||||
>
|
||||
<template #icon>
|
||||
<ClockIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.batchEdit') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
variant="danger"
|
||||
size="sm"
|
||||
:disabled="!hasSelectedFiles || isBatchUpdating || isBatchPolicyActionRunning"
|
||||
:loading="isBatchDeleting"
|
||||
@click="$emit('delete-selected')"
|
||||
>
|
||||
<template #icon>
|
||||
<TrashIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.batchDelete') }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Component } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ClockIcon, InfinityIcon, RotateCcwIcon, TrashIcon, XIcon } from 'lucide-vue-next'
|
||||
import type { AdminFilePolicyAction } from '@/types'
|
||||
import BaseButton from './BaseButton.vue'
|
||||
|
||||
type BatchPolicyActionOption = {
|
||||
action: AdminFilePolicyAction
|
||||
label: string
|
||||
description: string
|
||||
}
|
||||
|
||||
defineProps<{
|
||||
visible: boolean
|
||||
panelClass: string
|
||||
primaryTextClass: string
|
||||
isAllCurrentPageSelected: boolean
|
||||
isCurrentPagePartiallySelected: boolean
|
||||
isBatchActionRunning: boolean
|
||||
hasSelectedFiles: boolean
|
||||
selectedCount: number
|
||||
isBatchDeleting: boolean
|
||||
isBatchUpdating: boolean
|
||||
isBatchPolicyActionRunning: boolean
|
||||
batchPolicyActionOptions: BatchPolicyActionOption[]
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
'toggle-current-page-selection': []
|
||||
'clear-selection': []
|
||||
'apply-policy-action': [action: AdminFilePolicyAction]
|
||||
'open-batch-edit': []
|
||||
'delete-selected': []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const policyActionIconMap: Record<AdminFilePolicyAction, Component> = {
|
||||
extend_24h: ClockIcon,
|
||||
extend_7d: ClockIcon,
|
||||
make_permanent: InfinityIcon,
|
||||
reset_download_limit: RotateCcwIcon
|
||||
}
|
||||
|
||||
const getPolicyActionIcon = (action: AdminFilePolicyAction) => policyActionIconMap[action]
|
||||
</script>
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useAdminFileSelection } from './useAdminFileSelection'
|
||||
|
||||
describe('useAdminFileSelection', () => {
|
||||
it('tracks selected files and current page selection state', () => {
|
||||
const files = ref([{ id: 1 }, { id: 2 }, { id: 3 }])
|
||||
const selection = useAdminFileSelection(files)
|
||||
|
||||
expect(selection.hasSelectedFiles.value).toBe(false)
|
||||
expect(selection.isAllCurrentPageSelected.value).toBe(false)
|
||||
|
||||
selection.toggleFileSelection(1)
|
||||
|
||||
expect(selection.selectedFileIds.value).toEqual(new Set([1]))
|
||||
expect(selection.selectedCount.value).toBe(1)
|
||||
expect(selection.hasSelectedFiles.value).toBe(true)
|
||||
expect(selection.isCurrentPagePartiallySelected.value).toBe(true)
|
||||
|
||||
selection.toggleCurrentPageSelection()
|
||||
|
||||
expect(selection.selectedFileIds.value).toEqual(new Set([1, 2, 3]))
|
||||
expect(selection.isAllCurrentPageSelected.value).toBe(true)
|
||||
expect(selection.isCurrentPagePartiallySelected.value).toBe(false)
|
||||
|
||||
selection.toggleCurrentPageSelection()
|
||||
|
||||
expect(selection.selectedFileIds.value.size).toBe(0)
|
||||
})
|
||||
|
||||
it('removes selected ids that are no longer visible on the current page', () => {
|
||||
const files = ref([{ id: 1 }, { id: 2 }, { id: 3 }])
|
||||
const selection = useAdminFileSelection(files)
|
||||
|
||||
selection.toggleCurrentPageSelection()
|
||||
files.value = [{ id: 2 }, { id: 4 }]
|
||||
selection.syncSelectedFilesWithCurrentPage()
|
||||
|
||||
expect(selection.selectedFileIds.value).toEqual(new Set([2]))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { computed, ref, type Ref } from 'vue'
|
||||
|
||||
type SelectableFile = {
|
||||
id: number
|
||||
}
|
||||
|
||||
export function useAdminFileSelection<T extends SelectableFile>(tableData: Ref<T[]>) {
|
||||
const selectedFileIds = ref<Set<number>>(new Set())
|
||||
const currentPageSelectedCount = computed(
|
||||
() => tableData.value.filter((file) => selectedFileIds.value.has(file.id)).length
|
||||
)
|
||||
const selectedCount = computed(() => selectedFileIds.value.size)
|
||||
const hasSelectedFiles = computed(() => selectedCount.value > 0)
|
||||
const isAllCurrentPageSelected = computed(
|
||||
() => tableData.value.length > 0 && currentPageSelectedCount.value === tableData.value.length
|
||||
)
|
||||
const isCurrentPagePartiallySelected = computed(
|
||||
() => currentPageSelectedCount.value > 0 && !isAllCurrentPageSelected.value
|
||||
)
|
||||
|
||||
const syncSelectedFilesWithCurrentPage = () => {
|
||||
const visibleIds = new Set(tableData.value.map((file) => file.id))
|
||||
selectedFileIds.value = new Set(
|
||||
Array.from(selectedFileIds.value).filter((id) => visibleIds.has(id))
|
||||
)
|
||||
}
|
||||
|
||||
const clearSelection = () => {
|
||||
selectedFileIds.value = new Set()
|
||||
}
|
||||
|
||||
const toggleFileSelection = (id: number) => {
|
||||
const nextSelectedIds = new Set(selectedFileIds.value)
|
||||
if (nextSelectedIds.has(id)) {
|
||||
nextSelectedIds.delete(id)
|
||||
} else {
|
||||
nextSelectedIds.add(id)
|
||||
}
|
||||
selectedFileIds.value = nextSelectedIds
|
||||
}
|
||||
|
||||
const toggleCurrentPageSelection = () => {
|
||||
if (isAllCurrentPageSelected.value) {
|
||||
clearSelection()
|
||||
return
|
||||
}
|
||||
|
||||
selectedFileIds.value = new Set(tableData.value.map((file) => file.id))
|
||||
}
|
||||
|
||||
return {
|
||||
selectedFileIds,
|
||||
currentPageSelectedCount,
|
||||
selectedCount,
|
||||
hasSelectedFiles,
|
||||
isAllCurrentPageSelected,
|
||||
isCurrentPagePartiallySelected,
|
||||
syncSelectedFilesWithCurrentPage,
|
||||
clearSelection,
|
||||
toggleFileSelection,
|
||||
toggleCurrentPageSelection
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,20 @@ import {
|
||||
exportAdminTextFile,
|
||||
getSafeFilename
|
||||
} from '@/utils/download-action'
|
||||
import {
|
||||
buildDefaultViewPresetParams,
|
||||
normalizeViewPresetParams
|
||||
} from '@/utils/admin-file-view-preset'
|
||||
import {
|
||||
getRemainingDownloads,
|
||||
inferIsChunked,
|
||||
inferIsExpired,
|
||||
inferIsText,
|
||||
normalizeCount,
|
||||
normalizeSummary
|
||||
} from '@/utils/admin-file-summary'
|
||||
import { buildRetrieveUrl } from '@/utils/share-url'
|
||||
import { useAdminFileSelection } from './useAdminFileSelection'
|
||||
|
||||
const emptySummary = (): AdminFileSummary => ({
|
||||
totalFiles: 0,
|
||||
@@ -58,14 +71,6 @@ const emptySummary = (): AdminFileSummary => ({
|
||||
usedCount: 0
|
||||
})
|
||||
|
||||
const normalizeCount = (value: number | string | null | undefined) => Number(value || 0)
|
||||
|
||||
const isExpiredByDate = (value: string | null | undefined) => {
|
||||
if (!value) return false
|
||||
const timestamp = new Date(value).getTime()
|
||||
return Number.isFinite(timestamp) && timestamp < Date.now()
|
||||
}
|
||||
|
||||
type ErrorWithResponse = {
|
||||
response?: {
|
||||
status?: number
|
||||
@@ -121,87 +126,6 @@ const formatLocalDateTime = (date: Date) => {
|
||||
}
|
||||
|
||||
const builtInAllViewPresetId = 'built_in_all'
|
||||
const adminFileStatusFilters: AdminFileStatusFilter[] = ['all', 'active', 'expired']
|
||||
const adminFileTypeFilters: AdminFileTypeFilter[] = ['all', 'file', 'text', 'chunked']
|
||||
const adminFileHealthFilters: AdminFileHealthFilter[] = [
|
||||
'all',
|
||||
'attention',
|
||||
'danger',
|
||||
'warning',
|
||||
'healthy',
|
||||
'expired',
|
||||
'expiring_soon',
|
||||
'storage_issue',
|
||||
'never_retrieved',
|
||||
'permanent'
|
||||
]
|
||||
const adminFileSortFields = [
|
||||
'created_at',
|
||||
'expired_at',
|
||||
'name',
|
||||
'size',
|
||||
'used_count',
|
||||
'code'
|
||||
] as const
|
||||
const adminFileSortOrders = ['asc', 'desc'] as const
|
||||
|
||||
type RawViewPresetParams = Partial<
|
||||
Record<keyof AdminFileViewPresetParams | 'sort_by' | 'sort_order', unknown>
|
||||
>
|
||||
|
||||
const normalizePresetChoice = <T extends string>(
|
||||
value: unknown,
|
||||
allowedValues: readonly T[],
|
||||
fallback: T
|
||||
): T => {
|
||||
const normalizedValue = String(value ?? fallback)
|
||||
.replace('-', '_')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
return allowedValues.includes(normalizedValue as T) ? (normalizedValue as T) : fallback
|
||||
}
|
||||
|
||||
const normalizePresetSize = (value: unknown) => {
|
||||
const normalizedSize = Number(value)
|
||||
if (!Number.isFinite(normalizedSize)) return 10
|
||||
return Math.min(Math.max(Math.trunc(normalizedSize), 1), 100)
|
||||
}
|
||||
|
||||
const buildDefaultViewPresetParams = (): AdminFileViewPresetParams => ({
|
||||
keyword: '',
|
||||
status: 'all',
|
||||
type: 'all',
|
||||
health: 'all',
|
||||
sortBy: 'created_at',
|
||||
sortOrder: 'desc',
|
||||
size: 10
|
||||
})
|
||||
|
||||
const normalizeViewPresetParams = (params: unknown): AdminFileViewPresetParams => {
|
||||
const defaults = buildDefaultViewPresetParams()
|
||||
const rawParams =
|
||||
params && typeof params === 'object'
|
||||
? (params as RawViewPresetParams)
|
||||
: ({} as RawViewPresetParams)
|
||||
|
||||
return {
|
||||
keyword: String(rawParams.keyword ?? defaults.keyword).trim(),
|
||||
status: normalizePresetChoice(rawParams.status, adminFileStatusFilters, defaults.status),
|
||||
type: normalizePresetChoice(rawParams.type, adminFileTypeFilters, defaults.type),
|
||||
health: normalizePresetChoice(rawParams.health, adminFileHealthFilters, defaults.health),
|
||||
sortBy: normalizePresetChoice(
|
||||
rawParams.sortBy ?? rawParams.sort_by,
|
||||
adminFileSortFields,
|
||||
defaults.sortBy
|
||||
),
|
||||
sortOrder: normalizePresetChoice(
|
||||
rawParams.sortOrder ?? rawParams.sort_order,
|
||||
adminFileSortOrders,
|
||||
defaults.sortOrder
|
||||
),
|
||||
size: normalizePresetSize(rawParams.size ?? defaults.size)
|
||||
}
|
||||
}
|
||||
|
||||
export function useAdminFiles() {
|
||||
const { t } = useI18n()
|
||||
@@ -248,7 +172,6 @@ export function useAdminFiles() {
|
||||
const isDetailMetadataSaving = ref(false)
|
||||
const detailMetadataForm = ref(emptyDetailMetadataForm())
|
||||
const downloadingFileId = ref<number | null>(null)
|
||||
const selectedFileIds = ref<Set<number>>(new Set())
|
||||
const isBatchDeleting = ref(false)
|
||||
const isBatchUpdating = ref(false)
|
||||
const isBatchPolicyActionRunning = ref(false)
|
||||
@@ -263,17 +186,17 @@ export function useAdminFiles() {
|
||||
)
|
||||
const totalPages = computed(() => Math.max(Math.ceil(params.value.total / params.value.size), 1))
|
||||
const storageUsedText = computed(() => formatFileSize(summary.value.storageUsed))
|
||||
const currentPageSelectedCount = computed(
|
||||
() => tableData.value.filter((file) => selectedFileIds.value.has(file.id)).length
|
||||
)
|
||||
const selectedCount = computed(() => selectedFileIds.value.size)
|
||||
const hasSelectedFiles = computed(() => selectedCount.value > 0)
|
||||
const isAllCurrentPageSelected = computed(
|
||||
() => tableData.value.length > 0 && currentPageSelectedCount.value === tableData.value.length
|
||||
)
|
||||
const isCurrentPagePartiallySelected = computed(
|
||||
() => currentPageSelectedCount.value > 0 && !isAllCurrentPageSelected.value
|
||||
)
|
||||
const {
|
||||
selectedFileIds,
|
||||
selectedCount,
|
||||
hasSelectedFiles,
|
||||
isAllCurrentPageSelected,
|
||||
isCurrentPagePartiallySelected,
|
||||
syncSelectedFilesWithCurrentPage,
|
||||
clearSelection,
|
||||
toggleFileSelection,
|
||||
toggleCurrentPageSelection
|
||||
} = useAdminFileSelection(tableData)
|
||||
|
||||
const requestParams = computed<AdminFileListParams>(() => ({
|
||||
page: params.value.page,
|
||||
@@ -424,104 +347,6 @@ export function useAdminFiles() {
|
||||
() => detailPolicyActionOptions.value
|
||||
)
|
||||
|
||||
const inferIsText = (file: FileListItem) => {
|
||||
if (typeof file.isText === 'boolean') return file.isText
|
||||
if (typeof file.is_text === 'boolean') return file.is_text
|
||||
if (file.type) return file.type === 'text'
|
||||
return Boolean(file.text)
|
||||
}
|
||||
|
||||
const inferIsExpired = (file: FileListItem) => {
|
||||
if (typeof file.isExpired === 'boolean') return file.isExpired
|
||||
if (typeof file.is_expired === 'boolean') return file.is_expired
|
||||
if (
|
||||
file.expired_count !== null &&
|
||||
file.expired_count !== undefined &&
|
||||
file.expired_count === 0
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return isExpiredByDate(file.expired_at)
|
||||
}
|
||||
|
||||
const inferIsChunked = (file: FileListItem) => Boolean(file.isChunked ?? file.is_chunked)
|
||||
|
||||
const getRemainingDownloads = (file: FileListItem) => {
|
||||
if (file.remainingDownloads !== undefined) return file.remainingDownloads
|
||||
if (file.remaining_downloads !== undefined) return file.remaining_downloads
|
||||
if (
|
||||
file.expired_count !== null &&
|
||||
file.expired_count !== undefined &&
|
||||
file.expired_count >= 0
|
||||
) {
|
||||
return Math.max(file.expired_count, 0)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const buildFallbackSummary = (files: AdminFileViewItem[], total: number): AdminFileSummary => ({
|
||||
totalFiles: total,
|
||||
activeCount: files.filter((file) => !file.isExpiredFile).length,
|
||||
expiredCount: files.filter((file) => file.isExpiredFile).length,
|
||||
textCount: files.filter((file) => file.isTextFile).length,
|
||||
fileCount: files.filter((file) => !file.isTextFile).length,
|
||||
chunkedCount: files.filter((file) => file.isChunkedFile).length,
|
||||
healthAttentionCount: files.filter((file) =>
|
||||
['danger', 'warning'].includes(file.statusInsightSeverity)
|
||||
).length,
|
||||
healthDangerCount: files.filter((file) => file.statusInsightSeverity === 'danger').length,
|
||||
healthWarningCount: files.filter((file) => file.statusInsightSeverity === 'warning').length,
|
||||
expiringSoonCount: files.filter((file) => file.statusInsightReasons.includes('expires_soon'))
|
||||
.length,
|
||||
storageIssueCount: files.filter((file) =>
|
||||
file.statusInsightReasons.includes('storage_metadata_incomplete')
|
||||
).length,
|
||||
neverRetrievedCount: files.filter((file) =>
|
||||
file.statusInsightReasons.includes('never_retrieved')
|
||||
).length,
|
||||
healthyCount: files.filter((file) => file.statusInsightSeverity === 'success').length,
|
||||
permanentCount: files.filter((file) => file.statusInsightState === 'permanent').length,
|
||||
storageUsed: files.reduce((totalSize, file) => totalSize + normalizeCount(file.size), 0),
|
||||
usedCount: files.reduce(
|
||||
(totalUsed, file) => totalUsed + normalizeCount(file.usedCount ?? file.used_count),
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
const normalizeSummary = (
|
||||
rawSummary: Partial<AdminFileSummary> | undefined,
|
||||
files: AdminFileViewItem[],
|
||||
total: number
|
||||
): AdminFileSummary => {
|
||||
const fallback = buildFallbackSummary(files, total)
|
||||
if (!rawSummary) return fallback
|
||||
|
||||
return {
|
||||
totalFiles: normalizeCount(rawSummary.totalFiles ?? fallback.totalFiles),
|
||||
activeCount: normalizeCount(rawSummary.activeCount ?? fallback.activeCount),
|
||||
expiredCount: normalizeCount(rawSummary.expiredCount ?? fallback.expiredCount),
|
||||
textCount: normalizeCount(rawSummary.textCount ?? fallback.textCount),
|
||||
fileCount: normalizeCount(rawSummary.fileCount ?? fallback.fileCount),
|
||||
chunkedCount: normalizeCount(rawSummary.chunkedCount ?? fallback.chunkedCount),
|
||||
healthAttentionCount: normalizeCount(
|
||||
rawSummary.healthAttentionCount ?? fallback.healthAttentionCount
|
||||
),
|
||||
healthDangerCount: normalizeCount(rawSummary.healthDangerCount ?? fallback.healthDangerCount),
|
||||
healthWarningCount: normalizeCount(
|
||||
rawSummary.healthWarningCount ?? fallback.healthWarningCount
|
||||
),
|
||||
expiringSoonCount: normalizeCount(rawSummary.expiringSoonCount ?? fallback.expiringSoonCount),
|
||||
storageIssueCount: normalizeCount(rawSummary.storageIssueCount ?? fallback.storageIssueCount),
|
||||
neverRetrievedCount: normalizeCount(
|
||||
rawSummary.neverRetrievedCount ?? fallback.neverRetrievedCount
|
||||
),
|
||||
healthyCount: normalizeCount(rawSummary.healthyCount ?? fallback.healthyCount),
|
||||
permanentCount: normalizeCount(rawSummary.permanentCount ?? fallback.permanentCount),
|
||||
storageUsed: normalizeCount(rawSummary.storageUsed ?? fallback.storageUsed),
|
||||
usedCount: normalizeCount(rawSummary.usedCount ?? fallback.usedCount)
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeInsightSeverity = (
|
||||
severity: AdminFileInsightSeverity | undefined
|
||||
): AdminFileInsightSeverity => {
|
||||
@@ -733,36 +558,6 @@ export function useAdminFiles() {
|
||||
syncDetailMetadataForm(nextFile)
|
||||
}
|
||||
|
||||
const syncSelectedFilesWithCurrentPage = () => {
|
||||
const visibleIds = new Set(tableData.value.map((file) => file.id))
|
||||
selectedFileIds.value = new Set(
|
||||
Array.from(selectedFileIds.value).filter((id) => visibleIds.has(id))
|
||||
)
|
||||
}
|
||||
|
||||
const clearSelection = () => {
|
||||
selectedFileIds.value = new Set()
|
||||
}
|
||||
|
||||
const toggleFileSelection = (id: number) => {
|
||||
const nextSelectedIds = new Set(selectedFileIds.value)
|
||||
if (nextSelectedIds.has(id)) {
|
||||
nextSelectedIds.delete(id)
|
||||
} else {
|
||||
nextSelectedIds.add(id)
|
||||
}
|
||||
selectedFileIds.value = nextSelectedIds
|
||||
}
|
||||
|
||||
const toggleCurrentPageSelection = () => {
|
||||
if (isAllCurrentPageSelected.value) {
|
||||
clearSelection()
|
||||
return
|
||||
}
|
||||
|
||||
selectedFileIds.value = new Set(tableData.value.map((file) => file.id))
|
||||
}
|
||||
|
||||
const resetEditForm = () => {
|
||||
editForm.value = {
|
||||
id: null,
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
|
||||
import { PresignUploadService } from '@/services'
|
||||
import { usePresignedUpload } from './usePresignedUpload'
|
||||
|
||||
vi.mock('@/services', () => ({
|
||||
PresignUploadService: {
|
||||
initUpload: vi.fn(),
|
||||
directUploadToS3: vi.fn(),
|
||||
confirmUpload: vi.fn(),
|
||||
proxyUpload: vi.fn(),
|
||||
cancelUpload: vi.fn(),
|
||||
getUploadStatus: vi.fn()
|
||||
}
|
||||
}))
|
||||
|
||||
const mockedPresignUploadService = vi.mocked(PresignUploadService)
|
||||
|
||||
const createFile = () =>
|
||||
new File(['hello'], 'hello.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: 1
|
||||
})
|
||||
|
||||
describe('usePresignedUpload', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('uploads through direct mode and confirms the upload', async () => {
|
||||
mockedPresignUploadService.initUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
upload_id: 'direct-1',
|
||||
upload_url: 'https://storage.example/upload',
|
||||
mode: 'direct',
|
||||
expires_in: 900
|
||||
}
|
||||
})
|
||||
mockedPresignUploadService.directUploadToS3.mockImplementation(
|
||||
async (_uploadUrl, file, onProgress) => {
|
||||
onProgress?.({
|
||||
loaded: file.size,
|
||||
total: file.size,
|
||||
percentage: 100
|
||||
})
|
||||
return true
|
||||
}
|
||||
)
|
||||
mockedPresignUploadService.confirmUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
code: '12345',
|
||||
name: 'hello.txt'
|
||||
}
|
||||
})
|
||||
|
||||
const notify = vi.fn()
|
||||
const onProgress = vi.fn()
|
||||
const upload = usePresignedUpload({
|
||||
getMaxFileSize: () => 1024,
|
||||
notify
|
||||
})
|
||||
|
||||
const code = await upload.uploadFile(createFile(), {
|
||||
expireValue: 2,
|
||||
expireStyle: 'day',
|
||||
onProgress
|
||||
})
|
||||
|
||||
expect(code).toBe('12345')
|
||||
expect(mockedPresignUploadService.initUpload).toHaveBeenCalledWith({
|
||||
file_name: 'hello.txt',
|
||||
file_size: 5,
|
||||
expire_value: 2,
|
||||
expire_style: 'day'
|
||||
})
|
||||
expect(mockedPresignUploadService.directUploadToS3).toHaveBeenCalledWith(
|
||||
'https://storage.example/upload',
|
||||
expect.any(File),
|
||||
expect.any(Function)
|
||||
)
|
||||
expect(mockedPresignUploadService.confirmUpload).toHaveBeenCalledWith('direct-1', {
|
||||
expire_value: 2,
|
||||
expire_style: 'day'
|
||||
})
|
||||
expect(onProgress).toHaveBeenCalledWith({
|
||||
loaded: 5,
|
||||
total: 5,
|
||||
percentage: 100
|
||||
})
|
||||
expect(upload.presignStatus.value).toBe('success')
|
||||
expect(upload.uploadProgress.value).toEqual({
|
||||
loaded: 5,
|
||||
total: 5,
|
||||
percentage: 100
|
||||
})
|
||||
expect(notify).toHaveBeenCalledWith('文件上传成功!', 'success')
|
||||
})
|
||||
|
||||
it('uploads through proxy mode using the proxy upload url', async () => {
|
||||
mockedPresignUploadService.initUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
upload_id: 'proxy-1',
|
||||
upload_url: '/presign/upload/proxy/proxy-1',
|
||||
proxy_upload_url: '/presign/upload/proxy/proxy-1',
|
||||
legacy_proxy_upload_url: '/api/presign/upload/proxy/proxy-1',
|
||||
mode: 'proxy',
|
||||
expires_in: 900
|
||||
}
|
||||
})
|
||||
mockedPresignUploadService.proxyUpload.mockImplementation(
|
||||
async (_uploadId, file, onProgress) => {
|
||||
onProgress?.({
|
||||
loaded: file.size,
|
||||
total: file.size,
|
||||
percentage: 100
|
||||
})
|
||||
return {
|
||||
code: 200,
|
||||
detail: {
|
||||
code: '54321',
|
||||
name: 'hello.txt'
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const upload = usePresignedUpload({
|
||||
getMaxFileSize: () => 1024,
|
||||
notify: vi.fn()
|
||||
})
|
||||
|
||||
const code = await upload.uploadFile(createFile(), {
|
||||
expireValue: 1,
|
||||
expireStyle: 'hour'
|
||||
})
|
||||
|
||||
expect(code).toBe('54321')
|
||||
expect(mockedPresignUploadService.proxyUpload).toHaveBeenCalledWith(
|
||||
'proxy-1',
|
||||
expect.any(File),
|
||||
expect.any(Function),
|
||||
'/presign/upload/proxy/proxy-1'
|
||||
)
|
||||
expect(mockedPresignUploadService.confirmUpload).not.toHaveBeenCalled()
|
||||
expect(upload.presignStatus.value).toBe('success')
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,11 @@ import type { SendType, SentFileRecord, UploadProgress } from '@/types'
|
||||
import { getClipboardFile, insertTextAtSelection } from '@/utils/clipboard-paste'
|
||||
import { getErrorMessage } from '@/utils/common'
|
||||
import { getStorageUnit } from '@/utils/convert'
|
||||
import {
|
||||
buildAcceptedFileTypes,
|
||||
isFileTypeAllowed,
|
||||
normalizeAllowedFileTypes
|
||||
} from '@/utils/file-type'
|
||||
import { calculateFileHash } from '@/utils/file-processing'
|
||||
import { buildSentRecord, isExpirationWithinLimit } from '@/utils/send-record'
|
||||
import { createSentRecordActions } from '@/utils/sent-record-actions'
|
||||
@@ -43,20 +48,9 @@ export function useSendFlow() {
|
||||
)
|
||||
const allowedFileTypes = computed(() => {
|
||||
const types = config.value.allowedFileTypes || config.value.allowed_file_types || ['*']
|
||||
const normalized = types.map((type) => String(type).trim()).filter(Boolean)
|
||||
return normalized.length > 0 ? normalized : ['*']
|
||||
})
|
||||
const acceptedTypes = computed(() => {
|
||||
if (allowedFileTypes.value.some((type) => type === '*' || type === '*/*')) return '*'
|
||||
|
||||
return allowedFileTypes.value
|
||||
.map((type) => {
|
||||
const normalizedType = type.toLowerCase()
|
||||
if (normalizedType.includes('/')) return normalizedType
|
||||
return normalizedType.startsWith('.') ? normalizedType : `.${normalizedType}`
|
||||
})
|
||||
.join(',')
|
||||
return normalizeAllowedFileTypes(types)
|
||||
})
|
||||
const acceptedTypes = computed(() => buildAcceptedFileTypes(allowedFileTypes.value))
|
||||
const expirationOptions = computed(() =>
|
||||
config.value.expireStyle.map((value) => ({
|
||||
value,
|
||||
@@ -130,33 +124,15 @@ export function useSendFlow() {
|
||||
}
|
||||
|
||||
const checkFileType = (file: File) => {
|
||||
if (allowedFileTypes.value.some((type) => type === '*' || type === '*/*')) {
|
||||
return true
|
||||
}
|
||||
|
||||
const fileName = file.name.toLowerCase()
|
||||
const mimeType = file.type.toLowerCase()
|
||||
const isAllowed = allowedFileTypes.value.some((type) => {
|
||||
const rule = type.toLowerCase()
|
||||
if (rule.includes('/')) {
|
||||
if (rule.endsWith('/*')) {
|
||||
return mimeType.startsWith(rule.slice(0, -1))
|
||||
}
|
||||
return mimeType === rule
|
||||
}
|
||||
|
||||
const extension = rule.startsWith('.') ? rule : `.${rule}`
|
||||
return fileName.endsWith(extension)
|
||||
})
|
||||
|
||||
if (!isAllowed) {
|
||||
if (!isFileTypeAllowed(file, allowedFileTypes.value)) {
|
||||
alertStore.showAlert(
|
||||
t('send.messages.fileTypeNotAllowed', { types: allowedFileTypes.value.join(', ') }),
|
||||
'error'
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
return isAllowed
|
||||
return true
|
||||
}
|
||||
|
||||
const checkExpirationTime = (method: string, value: string): boolean =>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { uploadChunkedFile } from './upload-strategy'
|
||||
import { FileService } from './file'
|
||||
|
||||
vi.mock('@/utils/file-processing', () => ({
|
||||
calculateFileHash: vi.fn(async () => 'file-hash')
|
||||
}))
|
||||
|
||||
vi.mock('./file', () => ({
|
||||
FileService: {
|
||||
initChunkUpload: vi.fn(),
|
||||
uploadChunk: vi.fn(),
|
||||
completeChunkUpload: vi.fn()
|
||||
}
|
||||
}))
|
||||
|
||||
const mockedFileService = vi.mocked(FileService)
|
||||
|
||||
const createLargeFile = () => {
|
||||
const sixMb = 6 * 1024 * 1024
|
||||
return new File([new Uint8Array(sixMb)], 'video.mp4', {
|
||||
type: 'video/mp4',
|
||||
lastModified: 1
|
||||
})
|
||||
}
|
||||
|
||||
describe('uploadChunkedFile', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('skips uploaded chunks and reports progress from completed bytes', async () => {
|
||||
mockedFileService.initChunkUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
upload_id: 'upload-1',
|
||||
uploaded_chunks: [0]
|
||||
}
|
||||
})
|
||||
mockedFileService.uploadChunk.mockImplementation(async (_uploadId, _index, chunk, onProgress) => {
|
||||
onProgress?.({
|
||||
loaded: chunk.size,
|
||||
total: chunk.size,
|
||||
percentage: 100
|
||||
})
|
||||
return {
|
||||
code: 200,
|
||||
detail: null
|
||||
}
|
||||
})
|
||||
mockedFileService.completeChunkUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
code: '12345',
|
||||
name: 'video.mp4'
|
||||
}
|
||||
})
|
||||
|
||||
const progress = vi.fn()
|
||||
const result = await uploadChunkedFile(createLargeFile(), {
|
||||
expireValue: 2,
|
||||
expireStyle: 'day',
|
||||
onProgress: progress
|
||||
})
|
||||
|
||||
expect(mockedFileService.initChunkUpload).toHaveBeenCalledWith({
|
||||
file_name: 'video.mp4',
|
||||
file_size: 6 * 1024 * 1024,
|
||||
chunk_size: 5 * 1024 * 1024,
|
||||
file_hash: 'file-hash'
|
||||
})
|
||||
expect(mockedFileService.uploadChunk).toHaveBeenCalledTimes(1)
|
||||
expect(mockedFileService.uploadChunk.mock.calls[0][1]).toBe(1)
|
||||
expect(progress).toHaveBeenCalledWith({
|
||||
loaded: 6 * 1024 * 1024,
|
||||
total: 6 * 1024 * 1024,
|
||||
percentage: 99
|
||||
})
|
||||
expect(mockedFileService.completeChunkUpload).toHaveBeenCalledWith('upload-1', {
|
||||
expire_value: 2,
|
||||
expire_style: 'day'
|
||||
})
|
||||
expect(result.detail).toEqual({
|
||||
code: '12345',
|
||||
name: 'video.mp4'
|
||||
})
|
||||
})
|
||||
|
||||
it('returns early when the backend reports an existing uploaded file', async () => {
|
||||
mockedFileService.initChunkUpload.mockResolvedValue({
|
||||
code: 200,
|
||||
detail: {
|
||||
existed: true,
|
||||
code: '54321',
|
||||
name: 'video.mp4'
|
||||
}
|
||||
})
|
||||
|
||||
const result = await uploadChunkedFile(createLargeFile(), {
|
||||
expireValue: 1,
|
||||
expireStyle: 'day'
|
||||
})
|
||||
|
||||
expect(mockedFileService.uploadChunk).not.toHaveBeenCalled()
|
||||
expect(mockedFileService.completeChunkUpload).not.toHaveBeenCalled()
|
||||
expect(result.detail).toEqual({
|
||||
existed: true,
|
||||
code: '54321',
|
||||
name: 'video.mp4'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,140 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type { AdminFileViewItem, FileListItem } from '@/types'
|
||||
import {
|
||||
buildFallbackSummary,
|
||||
getRemainingDownloads,
|
||||
inferIsChunked,
|
||||
inferIsExpired,
|
||||
inferIsText,
|
||||
normalizeCount,
|
||||
normalizeSummary
|
||||
} from './admin-file-summary'
|
||||
|
||||
const buildFile = (overrides: Partial<FileListItem> = {}): FileListItem => ({
|
||||
id: 1,
|
||||
code: '12345',
|
||||
prefix: 'report',
|
||||
suffix: '.txt',
|
||||
size: 100,
|
||||
expired_at: null,
|
||||
expired_count: -1,
|
||||
created_at: '2026-06-06T00:00:00',
|
||||
...overrides
|
||||
})
|
||||
|
||||
const buildViewItem = (overrides: Partial<AdminFileViewItem> = {}): AdminFileViewItem => ({
|
||||
...buildFile(overrides),
|
||||
displayName: 'report.txt',
|
||||
displaySize: '100 B',
|
||||
displayExpiredAt: '-',
|
||||
displayUsage: '0',
|
||||
displayHealthState: 'healthy',
|
||||
displayHealthAction: 'monitor',
|
||||
isTextFile: false,
|
||||
isExpiredFile: false,
|
||||
isChunkedFile: false,
|
||||
remainingDownloadsValue: null,
|
||||
canPreviewText: false,
|
||||
statusInsightSeverity: 'success',
|
||||
statusInsightState: 'available',
|
||||
statusInsightNextAction: 'monitor',
|
||||
statusInsightReasons: [],
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('admin file summary helpers', () => {
|
||||
it('normalizes numeric values from mixed input', () => {
|
||||
expect(normalizeCount('12')).toBe(12)
|
||||
expect(normalizeCount(null)).toBe(0)
|
||||
expect(normalizeCount(undefined)).toBe(0)
|
||||
})
|
||||
|
||||
it('infers file flags from legacy and current fields', () => {
|
||||
expect(inferIsText(buildFile({ isText: true }))).toBe(true)
|
||||
expect(inferIsText(buildFile({ is_text: true }))).toBe(true)
|
||||
expect(inferIsText(buildFile({ type: 'text' }))).toBe(true)
|
||||
expect(inferIsText(buildFile({ text: 'hello' }))).toBe(true)
|
||||
|
||||
expect(inferIsExpired(buildFile({ isExpired: true }))).toBe(true)
|
||||
expect(inferIsExpired(buildFile({ is_expired: true }))).toBe(true)
|
||||
expect(inferIsExpired(buildFile({ expired_count: 0 }))).toBe(true)
|
||||
expect(inferIsExpired(buildFile({ expired_at: '2000-01-01T00:00:00Z' }))).toBe(true)
|
||||
expect(inferIsExpired(buildFile({ expired_at: '2999-01-01T00:00:00Z' }))).toBe(false)
|
||||
|
||||
expect(inferIsChunked(buildFile({ isChunked: true }))).toBe(true)
|
||||
expect(inferIsChunked(buildFile({ is_chunked: true }))).toBe(true)
|
||||
})
|
||||
|
||||
it('normalizes remaining download counts', () => {
|
||||
expect(getRemainingDownloads(buildFile({ remainingDownloads: 3 }))).toBe(3)
|
||||
expect(getRemainingDownloads(buildFile({ remaining_downloads: 2 }))).toBe(2)
|
||||
expect(getRemainingDownloads(buildFile({ expired_count: 4 }))).toBe(4)
|
||||
expect(getRemainingDownloads(buildFile({ expired_count: -1 }))).toBeNull()
|
||||
})
|
||||
|
||||
it('builds fallback summary from current page data', () => {
|
||||
const files = [
|
||||
buildViewItem({
|
||||
id: 1,
|
||||
size: 100,
|
||||
usedCount: 2,
|
||||
statusInsightSeverity: 'success',
|
||||
statusInsightState: 'available'
|
||||
}),
|
||||
buildViewItem({
|
||||
id: 2,
|
||||
isExpiredFile: true,
|
||||
isTextFile: true,
|
||||
isChunkedFile: true,
|
||||
size: 200,
|
||||
used_count: 3,
|
||||
statusInsightSeverity: 'warning',
|
||||
statusInsightState: 'permanent',
|
||||
statusInsightReasons: [
|
||||
'expires_soon',
|
||||
'storage_metadata_incomplete',
|
||||
'never_retrieved'
|
||||
]
|
||||
})
|
||||
]
|
||||
|
||||
expect(buildFallbackSummary(files, 10)).toMatchObject({
|
||||
totalFiles: 10,
|
||||
activeCount: 1,
|
||||
expiredCount: 1,
|
||||
textCount: 1,
|
||||
fileCount: 1,
|
||||
chunkedCount: 1,
|
||||
healthAttentionCount: 1,
|
||||
healthWarningCount: 1,
|
||||
expiringSoonCount: 1,
|
||||
storageIssueCount: 1,
|
||||
neverRetrievedCount: 1,
|
||||
healthyCount: 1,
|
||||
permanentCount: 1,
|
||||
storageUsed: 300,
|
||||
usedCount: 5
|
||||
})
|
||||
})
|
||||
|
||||
it('uses backend summary fields while falling back for missing values', () => {
|
||||
const files = [buildViewItem({ size: 100, usedCount: 2 })]
|
||||
|
||||
expect(
|
||||
normalizeSummary(
|
||||
{
|
||||
totalFiles: '8' as unknown as number,
|
||||
activeCount: 7
|
||||
},
|
||||
files,
|
||||
1
|
||||
)
|
||||
).toMatchObject({
|
||||
totalFiles: 8,
|
||||
activeCount: 7,
|
||||
storageUsed: 100,
|
||||
usedCount: 2
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,110 @@
|
||||
import type { AdminFileSummary, AdminFileViewItem, FileListItem } from '@/types'
|
||||
|
||||
export const normalizeCount = (value: number | string | null | undefined) => Number(value || 0)
|
||||
|
||||
export const isExpiredByDate = (value: string | null | undefined) => {
|
||||
if (!value) return false
|
||||
const timestamp = new Date(value).getTime()
|
||||
return Number.isFinite(timestamp) && timestamp < Date.now()
|
||||
}
|
||||
|
||||
export const inferIsText = (file: FileListItem) => {
|
||||
if (typeof file.isText === 'boolean') return file.isText
|
||||
if (typeof file.is_text === 'boolean') return file.is_text
|
||||
if (file.type) return file.type === 'text'
|
||||
return Boolean(file.text)
|
||||
}
|
||||
|
||||
export const inferIsExpired = (file: FileListItem) => {
|
||||
if (typeof file.isExpired === 'boolean') return file.isExpired
|
||||
if (typeof file.is_expired === 'boolean') return file.is_expired
|
||||
if (
|
||||
file.expired_count !== null &&
|
||||
file.expired_count !== undefined &&
|
||||
file.expired_count === 0
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return isExpiredByDate(file.expired_at)
|
||||
}
|
||||
|
||||
export const inferIsChunked = (file: FileListItem) => Boolean(file.isChunked ?? file.is_chunked)
|
||||
|
||||
export const getRemainingDownloads = (file: FileListItem) => {
|
||||
if (file.remainingDownloads !== undefined) return file.remainingDownloads
|
||||
if (file.remaining_downloads !== undefined) return file.remaining_downloads
|
||||
if (
|
||||
file.expired_count !== null &&
|
||||
file.expired_count !== undefined &&
|
||||
file.expired_count >= 0
|
||||
) {
|
||||
return Math.max(file.expired_count, 0)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const buildFallbackSummary = (
|
||||
files: AdminFileViewItem[],
|
||||
total: number
|
||||
): AdminFileSummary => ({
|
||||
totalFiles: total,
|
||||
activeCount: files.filter((file) => !file.isExpiredFile).length,
|
||||
expiredCount: files.filter((file) => file.isExpiredFile).length,
|
||||
textCount: files.filter((file) => file.isTextFile).length,
|
||||
fileCount: files.filter((file) => !file.isTextFile).length,
|
||||
chunkedCount: files.filter((file) => file.isChunkedFile).length,
|
||||
healthAttentionCount: files.filter((file) =>
|
||||
['danger', 'warning'].includes(file.statusInsightSeverity)
|
||||
).length,
|
||||
healthDangerCount: files.filter((file) => file.statusInsightSeverity === 'danger').length,
|
||||
healthWarningCount: files.filter((file) => file.statusInsightSeverity === 'warning').length,
|
||||
expiringSoonCount: files.filter((file) => file.statusInsightReasons.includes('expires_soon'))
|
||||
.length,
|
||||
storageIssueCount: files.filter((file) =>
|
||||
file.statusInsightReasons.includes('storage_metadata_incomplete')
|
||||
).length,
|
||||
neverRetrievedCount: files.filter((file) =>
|
||||
file.statusInsightReasons.includes('never_retrieved')
|
||||
).length,
|
||||
healthyCount: files.filter((file) => file.statusInsightSeverity === 'success').length,
|
||||
permanentCount: files.filter((file) => file.statusInsightState === 'permanent').length,
|
||||
storageUsed: files.reduce((totalSize, file) => totalSize + normalizeCount(file.size), 0),
|
||||
usedCount: files.reduce(
|
||||
(totalUsed, file) => totalUsed + normalizeCount(file.usedCount ?? file.used_count),
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
export const normalizeSummary = (
|
||||
rawSummary: Partial<AdminFileSummary> | undefined,
|
||||
files: AdminFileViewItem[],
|
||||
total: number
|
||||
): AdminFileSummary => {
|
||||
const fallback = buildFallbackSummary(files, total)
|
||||
if (!rawSummary) return fallback
|
||||
|
||||
return {
|
||||
totalFiles: normalizeCount(rawSummary.totalFiles ?? fallback.totalFiles),
|
||||
activeCount: normalizeCount(rawSummary.activeCount ?? fallback.activeCount),
|
||||
expiredCount: normalizeCount(rawSummary.expiredCount ?? fallback.expiredCount),
|
||||
textCount: normalizeCount(rawSummary.textCount ?? fallback.textCount),
|
||||
fileCount: normalizeCount(rawSummary.fileCount ?? fallback.fileCount),
|
||||
chunkedCount: normalizeCount(rawSummary.chunkedCount ?? fallback.chunkedCount),
|
||||
healthAttentionCount: normalizeCount(
|
||||
rawSummary.healthAttentionCount ?? fallback.healthAttentionCount
|
||||
),
|
||||
healthDangerCount: normalizeCount(rawSummary.healthDangerCount ?? fallback.healthDangerCount),
|
||||
healthWarningCount: normalizeCount(
|
||||
rawSummary.healthWarningCount ?? fallback.healthWarningCount
|
||||
),
|
||||
expiringSoonCount: normalizeCount(rawSummary.expiringSoonCount ?? fallback.expiringSoonCount),
|
||||
storageIssueCount: normalizeCount(rawSummary.storageIssueCount ?? fallback.storageIssueCount),
|
||||
neverRetrievedCount: normalizeCount(
|
||||
rawSummary.neverRetrievedCount ?? fallback.neverRetrievedCount
|
||||
),
|
||||
healthyCount: normalizeCount(rawSummary.healthyCount ?? fallback.healthyCount),
|
||||
permanentCount: normalizeCount(rawSummary.permanentCount ?? fallback.permanentCount),
|
||||
storageUsed: normalizeCount(rawSummary.storageUsed ?? fallback.storageUsed),
|
||||
usedCount: normalizeCount(rawSummary.usedCount ?? fallback.usedCount)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
buildDefaultViewPresetParams,
|
||||
normalizeViewPresetParams
|
||||
} from './admin-file-view-preset'
|
||||
|
||||
describe('admin file view preset helpers', () => {
|
||||
it('builds default params for the all-files view', () => {
|
||||
expect(buildDefaultViewPresetParams()).toEqual({
|
||||
keyword: '',
|
||||
status: 'all',
|
||||
type: 'all',
|
||||
health: 'all',
|
||||
sortBy: 'created_at',
|
||||
sortOrder: 'desc',
|
||||
size: 10
|
||||
})
|
||||
})
|
||||
|
||||
it('normalizes legacy and unsafe preset values', () => {
|
||||
expect(
|
||||
normalizeViewPresetParams({
|
||||
keyword: ' report ',
|
||||
status: 'ACTIVE',
|
||||
type: 'chunked',
|
||||
health: 'storage-issue',
|
||||
sort_by: 'used_count',
|
||||
sort_order: 'ASC',
|
||||
size: 250
|
||||
})
|
||||
).toEqual({
|
||||
keyword: 'report',
|
||||
status: 'active',
|
||||
type: 'chunked',
|
||||
health: 'storage_issue',
|
||||
sortBy: 'used_count',
|
||||
sortOrder: 'asc',
|
||||
size: 100
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back when preset params are invalid', () => {
|
||||
expect(
|
||||
normalizeViewPresetParams({
|
||||
status: 'deleted',
|
||||
type: 'folder',
|
||||
health: 'unknown',
|
||||
sortBy: 'createdAt',
|
||||
sortOrder: 'latest',
|
||||
size: 'bad'
|
||||
})
|
||||
).toEqual(buildDefaultViewPresetParams())
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,90 @@
|
||||
import type {
|
||||
AdminFileHealthFilter,
|
||||
AdminFileSortBy,
|
||||
AdminFileSortOrder,
|
||||
AdminFileStatusFilter,
|
||||
AdminFileTypeFilter,
|
||||
AdminFileViewPresetParams
|
||||
} from '@/types'
|
||||
|
||||
export const adminFileStatusFilters: AdminFileStatusFilter[] = ['all', 'active', 'expired']
|
||||
export const adminFileTypeFilters: AdminFileTypeFilter[] = ['all', 'file', 'text', 'chunked']
|
||||
export const adminFileHealthFilters: AdminFileHealthFilter[] = [
|
||||
'all',
|
||||
'attention',
|
||||
'danger',
|
||||
'warning',
|
||||
'healthy',
|
||||
'expired',
|
||||
'expiring_soon',
|
||||
'storage_issue',
|
||||
'never_retrieved',
|
||||
'permanent'
|
||||
]
|
||||
export const adminFileSortFields: AdminFileSortBy[] = [
|
||||
'created_at',
|
||||
'expired_at',
|
||||
'name',
|
||||
'size',
|
||||
'used_count',
|
||||
'code'
|
||||
]
|
||||
export const adminFileSortOrders: AdminFileSortOrder[] = ['asc', 'desc']
|
||||
|
||||
type RawViewPresetParams = Partial<
|
||||
Record<keyof AdminFileViewPresetParams | 'sort_by' | 'sort_order', unknown>
|
||||
>
|
||||
|
||||
const normalizePresetChoice = <T extends string>(
|
||||
value: unknown,
|
||||
allowedValues: readonly T[],
|
||||
fallback: T
|
||||
): T => {
|
||||
const normalizedValue = String(value ?? fallback)
|
||||
.replace('-', '_')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
return allowedValues.includes(normalizedValue as T) ? (normalizedValue as T) : fallback
|
||||
}
|
||||
|
||||
const normalizePresetSize = (value: unknown) => {
|
||||
const normalizedSize = Number(value)
|
||||
if (!Number.isFinite(normalizedSize)) return 10
|
||||
return Math.min(Math.max(Math.trunc(normalizedSize), 1), 100)
|
||||
}
|
||||
|
||||
export const buildDefaultViewPresetParams = (): AdminFileViewPresetParams => ({
|
||||
keyword: '',
|
||||
status: 'all',
|
||||
type: 'all',
|
||||
health: 'all',
|
||||
sortBy: 'created_at',
|
||||
sortOrder: 'desc',
|
||||
size: 10
|
||||
})
|
||||
|
||||
export const normalizeViewPresetParams = (params: unknown): AdminFileViewPresetParams => {
|
||||
const defaults = buildDefaultViewPresetParams()
|
||||
const rawParams =
|
||||
params && typeof params === 'object'
|
||||
? (params as RawViewPresetParams)
|
||||
: ({} as RawViewPresetParams)
|
||||
|
||||
return {
|
||||
keyword: String(rawParams.keyword ?? defaults.keyword).trim(),
|
||||
status: normalizePresetChoice(rawParams.status, adminFileStatusFilters, defaults.status),
|
||||
type: normalizePresetChoice(rawParams.type, adminFileTypeFilters, defaults.type),
|
||||
health: normalizePresetChoice(rawParams.health, adminFileHealthFilters, defaults.health),
|
||||
sortBy: normalizePresetChoice(
|
||||
rawParams.sortBy ?? rawParams.sort_by,
|
||||
adminFileSortFields,
|
||||
defaults.sortBy
|
||||
),
|
||||
sortOrder: normalizePresetChoice(
|
||||
rawParams.sortOrder ?? rawParams.sort_order,
|
||||
adminFileSortOrders,
|
||||
defaults.sortOrder
|
||||
),
|
||||
size: normalizePresetSize(rawParams.size ?? defaults.size)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { renderMarkdownPreview } from './content-preview'
|
||||
|
||||
describe('renderMarkdownPreview', () => {
|
||||
it('renders markdown and removes unsafe html', async () => {
|
||||
const html = await renderMarkdownPreview(
|
||||
'# Title\n\n[ok](https://example.com)\n\n<script>alert(1)</script><img src="x" onerror="alert(1)">'
|
||||
)
|
||||
|
||||
expect(html).toContain('<h1>Title</h1>')
|
||||
expect(html).toContain('href="https://example.com"')
|
||||
expect(html).toContain('<img src="x">')
|
||||
expect(html).not.toContain('<script>')
|
||||
expect(html).not.toContain('onerror')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,103 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { AdminFileViewItem, ReceivedFileRecord } from '@/types'
|
||||
import { downloadAdminManagedFile, downloadReceivedRecord, getSafeFilename } from './download-action'
|
||||
|
||||
const fileSaverMock = vi.hoisted(() => ({
|
||||
saveAs: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('file-saver', () => ({
|
||||
saveAs: fileSaverMock.saveAs
|
||||
}))
|
||||
|
||||
const buildReceivedRecord = (
|
||||
overrides: Partial<ReceivedFileRecord> = {}
|
||||
): ReceivedFileRecord => ({
|
||||
id: 1,
|
||||
code: '12345',
|
||||
filename: 'note',
|
||||
size: '1 KB',
|
||||
downloadUrl: null,
|
||||
content: 'hello',
|
||||
date: '2026-06-06',
|
||||
type: 'text',
|
||||
...overrides
|
||||
})
|
||||
|
||||
const buildAdminFile = (overrides: Partial<AdminFileViewItem> = {}): AdminFileViewItem => ({
|
||||
id: 1,
|
||||
code: '12345',
|
||||
prefix: 'report',
|
||||
suffix: '.txt',
|
||||
size: 10,
|
||||
expired_at: null,
|
||||
expired_count: null,
|
||||
created_at: '2026-06-06T00:00:00',
|
||||
displayName: 'report.txt',
|
||||
displaySize: '10 B',
|
||||
displayExpiredAt: '-',
|
||||
displayUsage: '0',
|
||||
displayHealthState: 'healthy',
|
||||
displayHealthAction: '',
|
||||
isTextFile: false,
|
||||
isExpiredFile: false,
|
||||
isChunkedFile: false,
|
||||
remainingDownloadsValue: null,
|
||||
canPreviewText: false,
|
||||
statusInsightSeverity: 'success',
|
||||
statusInsightState: 'healthy',
|
||||
statusInsightNextAction: '',
|
||||
statusInsightReasons: [],
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('download action helpers', () => {
|
||||
beforeEach(() => {
|
||||
fileSaverMock.saveAs.mockClear()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('opens received file records through an absolute download url', async () => {
|
||||
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null)
|
||||
|
||||
await downloadReceivedRecord(
|
||||
buildReceivedRecord({
|
||||
downloadUrl: '/share/download?code=12345',
|
||||
content: null,
|
||||
type: 'file'
|
||||
})
|
||||
)
|
||||
|
||||
expect(openSpy).toHaveBeenCalledWith(
|
||||
`${window.location.origin}/share/download?code=12345`,
|
||||
'_blank'
|
||||
)
|
||||
expect(fileSaverMock.saveAs).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('saves received text records as plain text', async () => {
|
||||
await downloadReceivedRecord(buildReceivedRecord({ filename: 'memo', content: 'hello' }))
|
||||
|
||||
expect(fileSaverMock.saveAs).toHaveBeenCalledTimes(1)
|
||||
expect(fileSaverMock.saveAs.mock.calls[0][1]).toBe('memo.txt')
|
||||
})
|
||||
|
||||
it('sanitizes unsafe filenames', () => {
|
||||
expect(getSafeFilename(' ../a:b*c?.txt\n ')).toBe('.._a_b_c_.txt')
|
||||
expect(getSafeFilename('')).toBe('download')
|
||||
})
|
||||
|
||||
it('uses content-disposition filenames for managed binary files', async () => {
|
||||
const blob = new Blob(['file'])
|
||||
|
||||
await downloadAdminManagedFile(buildAdminFile(), {
|
||||
data: blob,
|
||||
headers: {
|
||||
'content-disposition': "attachment; filename*=UTF-8''%E6%8A%A5%E5%91%8A.pdf"
|
||||
}
|
||||
})
|
||||
|
||||
expect(fileSaverMock.saveAs).toHaveBeenCalledWith(blob, '报告.pdf')
|
||||
})
|
||||
})
|
||||
@@ -34,6 +34,7 @@ export async function downloadReceivedRecord(record: ReceivedFileRecord): Promis
|
||||
|
||||
export const getSafeFilename = (name: string) =>
|
||||
name
|
||||
.trim()
|
||||
.replace(unsafeFilenamePattern, '_')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { buildAcceptedFileTypes, isFileTypeAllowed, normalizeAllowedFileTypes } from './file-type'
|
||||
|
||||
describe('file type helpers', () => {
|
||||
it('normalizes configured file type rules', () => {
|
||||
expect(normalizeAllowedFileTypes(' rar, .zip; image/* ')).toEqual([
|
||||
'rar',
|
||||
'.zip',
|
||||
'image/*'
|
||||
])
|
||||
expect(normalizeAllowedFileTypes([])).toEqual(['*'])
|
||||
expect(normalizeAllowedFileTypes(null)).toEqual(['*'])
|
||||
})
|
||||
|
||||
it('builds input accept attribute values', () => {
|
||||
expect(buildAcceptedFileTypes(['*'])).toBe('*')
|
||||
expect(buildAcceptedFileTypes(['rar', '.zip', 'image/*'])).toBe('.rar,.zip,image/*')
|
||||
})
|
||||
|
||||
it('allows files by extension, exact mime type, and mime wildcard', () => {
|
||||
expect(isFileTypeAllowed({ name: 'backup.RAR' }, ['rar'])).toBe(true)
|
||||
expect(isFileTypeAllowed({ name: 'archive.zip' }, ['.zip'])).toBe(true)
|
||||
expect(isFileTypeAllowed({ name: 'avatar.bin', type: 'image/png' }, ['image/*'])).toBe(true)
|
||||
expect(isFileTypeAllowed({ name: 'readme.md', type: 'text/markdown' }, ['text/markdown'])).toBe(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects files that do not match configured rules', () => {
|
||||
expect(isFileTypeAllowed({ name: 'payload.exe', type: 'application/octet-stream' }, ['rar'])).toBe(
|
||||
false
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
type FileLike = {
|
||||
name: string
|
||||
type?: string
|
||||
}
|
||||
|
||||
export const normalizeAllowedFileTypes = (types: unknown): string[] => {
|
||||
const rawTypes =
|
||||
typeof types === 'string'
|
||||
? types.replace(/;/g, ',').split(',')
|
||||
: Array.isArray(types)
|
||||
? types
|
||||
: []
|
||||
const normalized = rawTypes.map((type) => String(type).trim()).filter(Boolean)
|
||||
return normalized.length > 0 ? normalized : ['*']
|
||||
}
|
||||
|
||||
export const buildAcceptedFileTypes = (allowedTypes: string[]) => {
|
||||
if (allowedTypes.some((type) => type === '*' || type === '*/*')) return '*'
|
||||
|
||||
return allowedTypes
|
||||
.map((type) => {
|
||||
const normalizedType = type.toLowerCase()
|
||||
if (normalizedType.includes('/')) return normalizedType
|
||||
return normalizedType.startsWith('.') ? normalizedType : `.${normalizedType}`
|
||||
})
|
||||
.join(',')
|
||||
}
|
||||
|
||||
export const isFileTypeAllowed = (file: FileLike, allowedTypes: string[]) => {
|
||||
if (allowedTypes.some((type) => type === '*' || type === '*/*')) {
|
||||
return true
|
||||
}
|
||||
|
||||
const fileName = file.name.toLowerCase()
|
||||
const mimeType = String(file.type || '').toLowerCase()
|
||||
return allowedTypes.some((type) => {
|
||||
const rule = type.toLowerCase()
|
||||
if (rule.includes('/')) {
|
||||
if (rule.endsWith('/*')) {
|
||||
return mimeType.startsWith(rule.slice(0, -1))
|
||||
}
|
||||
return mimeType === rule
|
||||
}
|
||||
|
||||
const extension = rule.startsWith('.') ? rule : `.${rule}`
|
||||
return fileName.endsWith(extension)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { isExpirationWithinLimit } from './send-record'
|
||||
|
||||
describe('isExpirationWithinLimit', () => {
|
||||
it('allows forever and count based expirations regardless of max seconds', () => {
|
||||
expect(isExpirationWithinLimit('forever', '9999', 60)).toBe(true)
|
||||
expect(isExpirationWithinLimit('count', '9999', 60)).toBe(true)
|
||||
})
|
||||
|
||||
it('allows any time based expiration when max seconds is disabled', () => {
|
||||
expect(isExpirationWithinLimit('day', '365', 0)).toBe(true)
|
||||
})
|
||||
|
||||
it('checks minute, hour, and day values against max seconds', () => {
|
||||
expect(isExpirationWithinLimit('minute', '30', 3600)).toBe(true)
|
||||
expect(isExpirationWithinLimit('hour', '2', 3600)).toBe(false)
|
||||
expect(isExpirationWithinLimit('day', '2', 86400)).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects unsupported expiration methods', () => {
|
||||
expect(isExpirationWithinLimit('week', '1', 604800)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -53,6 +53,7 @@
|
||||
:record="selectedRecord"
|
||||
@close="closeDetails"
|
||||
@preview-content="showContentPreview"
|
||||
@preview-file="showFilePreview"
|
||||
/>
|
||||
|
||||
<ContentPreviewModal
|
||||
@@ -61,6 +62,12 @@
|
||||
@close="closeContentPreview"
|
||||
@copy-content="copyContent"
|
||||
/>
|
||||
|
||||
<MediaPreviewModal
|
||||
:visible="showMediaPreview"
|
||||
:record="previewMediaRecord"
|
||||
@close="closeFilePreview"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -75,6 +82,7 @@ import SideDrawer from '@/components/common/SideDrawer.vue'
|
||||
import FileDetailModal from '@/components/common/FileDetailModal.vue'
|
||||
import FileRecordList from '@/components/common/FileRecordList.vue'
|
||||
import ContentPreviewModal from '@/components/common/ContentPreviewModal.vue'
|
||||
import MediaPreviewModal from '@/components/common/MediaPreviewModal.vue'
|
||||
import { useRetrieveFlow } from '@/composables'
|
||||
import { useInjectedDarkMode } from '@/composables'
|
||||
|
||||
@@ -88,15 +96,19 @@ const {
|
||||
error,
|
||||
records,
|
||||
selectedRecord,
|
||||
previewMediaRecord,
|
||||
showDrawer,
|
||||
showPreview,
|
||||
showMediaPreview,
|
||||
renderedContent,
|
||||
closeFilePreview,
|
||||
closeContentPreview,
|
||||
closeDetails,
|
||||
copyContent,
|
||||
deleteRecord,
|
||||
downloadRecord,
|
||||
handleSubmit,
|
||||
showFilePreview,
|
||||
showContentPreview,
|
||||
toggleDrawer,
|
||||
viewDetails
|
||||
|
||||
@@ -240,83 +240,25 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section
|
||||
v-if="tableData.length > 0"
|
||||
class="mb-4 flex flex-col gap-3 rounded-lg border px-4 py-3 sm:flex-row sm:items-center sm:justify-between"
|
||||
:class="[panelClass]"
|
||||
>
|
||||
<label class="inline-flex items-center gap-2 text-sm" :class="[primaryTextClass]">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 rounded border-gray-300 text-zinc-600 focus:ring-zinc-500"
|
||||
:checked="isAllCurrentPageSelected"
|
||||
:disabled="isBatchActionRunning"
|
||||
:indeterminate="isCurrentPagePartiallySelected"
|
||||
@change="toggleCurrentPageSelection"
|
||||
/>
|
||||
<span>
|
||||
{{
|
||||
hasSelectedFiles
|
||||
? t('fileManage.selectedCount', { count: selectedCount })
|
||||
: t('fileManage.selectCurrentPage')
|
||||
}}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<BaseButton
|
||||
v-if="hasSelectedFiles"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="isBatchActionRunning"
|
||||
@click="clearSelection"
|
||||
>
|
||||
<template #icon>
|
||||
<XIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.clearSelection') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-for="option in batchPolicyActionOptions"
|
||||
:key="option.action"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:title="option.description"
|
||||
:disabled="!hasSelectedFiles || isBatchDeleting || isBatchUpdating"
|
||||
:loading="isBatchPolicyActionRunning"
|
||||
@click="applySelectedPolicyAction(option.action)"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="getDetailPolicyActionIcon(option.action)" class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ option.label }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
:disabled="!hasSelectedFiles || isBatchDeleting || isBatchPolicyActionRunning"
|
||||
:loading="isBatchUpdating"
|
||||
@click="openBatchEditModal"
|
||||
>
|
||||
<template #icon>
|
||||
<ClockIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.batchEdit') }}
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
variant="danger"
|
||||
size="sm"
|
||||
:disabled="!hasSelectedFiles || isBatchUpdating || isBatchPolicyActionRunning"
|
||||
:loading="isBatchDeleting"
|
||||
@click="deleteSelectedFiles"
|
||||
>
|
||||
<template #icon>
|
||||
<TrashIcon class="mr-2 h-4 w-4" />
|
||||
</template>
|
||||
{{ t('fileManage.batchDelete') }}
|
||||
</BaseButton>
|
||||
</div>
|
||||
</section>
|
||||
<AdminBatchActionBar
|
||||
:visible="tableData.length > 0"
|
||||
:panel-class="panelClass"
|
||||
:primary-text-class="primaryTextClass"
|
||||
:is-all-current-page-selected="isAllCurrentPageSelected"
|
||||
:is-current-page-partially-selected="isCurrentPagePartiallySelected"
|
||||
:is-batch-action-running="isBatchActionRunning"
|
||||
:has-selected-files="hasSelectedFiles"
|
||||
:selected-count="selectedCount"
|
||||
:is-batch-deleting="isBatchDeleting"
|
||||
:is-batch-updating="isBatchUpdating"
|
||||
:is-batch-policy-action-running="isBatchPolicyActionRunning"
|
||||
:batch-policy-action-options="batchPolicyActionOptions"
|
||||
@toggle-current-page-selection="toggleCurrentPageSelection"
|
||||
@clear-selection="clearSelection"
|
||||
@apply-policy-action="applySelectedPolicyAction"
|
||||
@open-batch-edit="openBatchEditModal"
|
||||
@delete-selected="deleteSelectedFiles"
|
||||
/>
|
||||
|
||||
<DataTable :title="t('fileManage.allFiles')" :headers="fileTableHeaders">
|
||||
<template #body>
|
||||
@@ -1215,6 +1157,7 @@ import DataPagination from '@/components/common/DataPagination.vue'
|
||||
import FileEditField from '@/components/common/FileEditField.vue'
|
||||
import BaseModal from '@/components/common/BaseModal.vue'
|
||||
import BaseButton from '@/components/common/BaseButton.vue'
|
||||
import AdminBatchActionBar from '@/components/common/AdminBatchActionBar.vue'
|
||||
import { useAdminFiles, useInjectedDarkMode } from '@/composables'
|
||||
import { formatTimestamp } from '@/utils/common'
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
|
||||
"exclude": ["src/**/__tests__/*"],
|
||||
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/**/__tests__/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
include: ['src/**/*.{test,spec}.ts']
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user