🐛 兼容新旧取件码并完善回收站复制

This commit is contained in:
orion committed 2026-09-11 08:59:34 +08:00
1 parent a5c5d1ae3b
commit b2e1928898
10 files changed
+69 -16

No files matched your search

+2 -2
View File
@@ -25,7 +25,7 @@
required
:aria-invalid="error"
:readonly="inputStatus.readonly"
maxlength="5"
maxlength="8"
@focus="isInputFocused = true"
@blur="isInputFocused = false"
/>
@@ -46,7 +46,7 @@
<button
type="submit"
class="group relative w-full overflow-hidden rounded-lg bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 px-4 py-3 font-bold text-white transition duration-300 hover:from-indigo-600 hover:via-purple-600 hover:to-pink-600 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 disabled:cursor-not-allowed disabled:opacity-50 motion-safe:hover:scale-[1.02] disabled:hover:scale-100"
:disabled="inputStatus.loading || code.trim().length !== 5"
:disabled="inputStatus.loading || ![5, 8].includes(code.trim().length)"
>
<span class="flex items-center justify-center relative z-10">
<span>{{ inputStatus.loading ? t('common.loading') : t('retrieve.submit') }}</span>
+1
View File
@@ -6,6 +6,7 @@ export { useAdminSession } from './useAdminSession'
export { useAppShell } from './useAppShell'
export { useDashboardStats } from './useDashboardStats'
export { useInjectedDarkMode } from './useInjectedDarkMode'
export { useClipboard } from './useClipboard'
export { usePresignedUpload } from './usePresignedUpload'
export { usePublicConfigBootstrap } from './usePublicConfigBootstrap'
export { useRetrieveFlow } from './useRetrieveFlow'
+6
View File
@@ -0,0 +1,6 @@
import { copyToClipboard as copy } from '@/utils/clipboard'
export function useClipboard() {
const copyToClipboard = (value: string) => copy(value)
return { copyToClipboard }
}
+3 -2
View File
@@ -9,6 +9,7 @@ import { copyToClipboard } from '@/utils/clipboard'
import { getErrorMessage } from '@/utils/common'
import { renderMarkdownPreview } from '@/utils/content-preview'
import { downloadReceivedRecord } from '@/utils/download-action'
import { isValidRetrievalCode } from '@/utils/retrieval-code'
type InputStatus = {
readonly: boolean
@@ -36,7 +37,7 @@ export function useRetrieveFlow() {
const renderedContent = ref('')
const normalizedCode = computed(() => code.value.trim())
const isWorking = computed(() => isInspecting.value || isRetrieving.value)
const hasValidCode = computed(() => normalizedCode.value.length === 5)
const hasValidCode = computed(() => isValidRetrievalCode(normalizedCode.value))
const formatFileSize = (bytes: number) => {
if (bytes === 0) return '0 ' + t('fileSize.bytes')
@@ -214,7 +215,7 @@ export function useRetrieveFlow() {
resetInspection()
}
if (nextCode.length < 5 && error.value) {
if (!isValidRetrievalCode(nextCode) && error.value) {
error.value = ''
}
})
+1 -1
View File
@@ -244,7 +244,7 @@ export default {
retrieve: {
title: 'File Retrieval',
codeInput: {
placeholder: 'Enter 5-digit retrieval code',
placeholder: 'Enter 5- or 8-character retrieval code',
label: 'Retrieval Code'
},
submit: 'Retrieve',
+1 -2
View File
@@ -244,8 +244,7 @@ export default {
retrieve: {
title: '文件取件',
codeInput: {
placeholder: '请输入5位取件码',
label: '取件码'
placeholder: '输入 5 位或 8 位取件码',
},
submit: '取件',
needSendFile: '需要发送文件?点击这里',
+25
View File
@@ -0,0 +1,25 @@
const CODE_PATTERN = /^[A-Za-z0-9]+$/
export const isValidRetrievalCode = (value: string): boolean => {
const code = value.trim()
return (code.length === 5 || code.length === 8) && CODE_PATTERN.test(code)
}
export const parseRetrievalCode = (value: string): string => {
const raw = value.trim()
if (isValidRetrievalCode(raw)) return raw
try {
const url = new URL(raw)
const queryCode = url.searchParams.get('code') || ''
if (queryCode) return isValidRetrievalCode(queryCode) ? queryCode : ''
if (url.hash) {
const hash = url.hash.startsWith('#') ? url.hash.slice(1) : url.hash
const query = hash.includes('?') ? hash.slice(hash.indexOf('?') + 1) : hash
const hashCode = new URLSearchParams(query).get('code') || ''
return isValidRetrievalCode(hashCode) ? hashCode : ''
}
return ''
} catch {
return ''
}
}
+3 -6
View File
@@ -67,6 +67,7 @@ import FileDetailModal from '@/components/common/FileDetailModal.vue'
import FileRecordList from '@/components/common/FileRecordList.vue'
import ContentPreviewModal from '@/components/common/ContentPreviewModal.vue'
import { useRetrieveFlow } from '@/composables'
import { parseRetrievalCode } from '@/utils/retrieval-code'
import { useConfigStore } from '@/stores/configStore'
const isDarkMode = inject('isDarkMode')
@@ -101,13 +102,9 @@ const toSend = () => {
onMounted(() => {
const queryCode = route.query.code
if (queryCode && typeof queryCode === 'string') {
code.value = queryCode
code.value = parseRetrievalCode(queryCode)
}
})
watch(code, (newCode) => {
if (newCode.length === 5) {
void handleSubmit()
}
})
</script>
+3 -3
View File
@@ -82,14 +82,14 @@ import { EraserIcon, FileX2Icon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Set
import BaseButton from '@/components/common/BaseButton.vue'
import BaseModal from '@/components/common/BaseModal.vue'
import DataPagination from '@/components/common/DataPagination.vue'
import { useAdminTrash, useInjectedDarkMode } from '@/composables'
import { useAdminTrash, useInjectedDarkMode, useClipboard } from '@/composables'
import type { TrashFileItem } from '@/types'
import { formatFileSize, formatTimestamp } from '@/utils/common'
import { copyRetrieveCode } from '@/utils/clipboard'
const isDarkMode = useInjectedDarkMode()
const router = useRouter()
const { fetchTrash, purgeTrashItem, restoreTrashItem, updateTrashRetention } = useAdminTrash()
const { copyToClipboard } = useClipboard()
const items = ref<TrashFileItem[]>([])
const page = ref(1)
const size = ref(20)
@@ -120,7 +120,7 @@ const makePermanent = (item: TrashFileItem) => run(item, 'retention', () => upda
const purge = (item: TrashFileItem) => { if (busyId.value === null) { pendingPurge.value = item; showPurgeModal.value = true } }
const closePurgeModal = () => { if (busyId.value === null) { showPurgeModal.value = false; pendingPurge.value = null } }
const confirmPurge = () => { if (!pendingPurge.value) return; const item = pendingPurge.value; closePurgeModal(); void run(item, 'purge', () => purgeTrashItem(item.id)) }
const copyCode = () => { if (restoredCode.value) void copyRetrieveCode(restoredCode.value) }
const copyCode = () => { if (restoredCode.value) void copyToClipboard(restoredCode.value) }
const changePage = (nextPage: number) => { page.value = nextPage; void loadTrash() }
const changePageSize = (nextSize: number) => { size.value = nextSize; page.value = 1; void loadTrash() }
void loadTrash()
+24
View File
@@ -0,0 +1,24 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import ts from 'typescript'
const root = new URL('../', import.meta.url)
test('entry must not truncate new codes or submit before typing is complete', () => {
const form = readFileSync(new URL('src/components/common/RetrieveForm.vue', root), 'utf8')
const view = readFileSync(new URL('src/views/RetrievewFileView.vue', root), 'utf8')
assert.ok(!form.includes('maxlength="5"'), '8-character code is truncated')
assert.ok(!view.includes('watch(code,'), 'typing a legacy prefix must not consume a retrieval')
})
test('legacy/new codes and URL extraction preserve literal code', async () => {
const source = readFileSync(new URL('src/utils/retrieval-code.ts', root), 'utf8')
const js = ts.transpile(source, {module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022})
const {parseRetrievalCode, isValidRetrievalCode} = await import('data:text/javascript;base64,'+Buffer.from(js).toString('base64'))
for (const code of ['01234','aB12C','00123456','Ab12Cd34']) {
assert.equal(parseRetrievalCode(' '+code+' '),code)
assert.equal(parseRetrievalCode('https://files.example/#/?code='+code),code)
assert.equal(parseRetrievalCode('https://files.example/?code='+code),code)
assert.equal(isValidRetrievalCode(code),true)
}
for (const code of ['1234','123456','1234567','123456789','12 34','../../foo']) assert.equal(isValidRetrievalCode(code),false)
assert.equal(parseRetrievalCode('https://files.example/?code=bad#/?code=01234'),'')
})