ีupdate: ระบบอัปโหลด ถ้าชื่อไฟล์ซ้ำที่มาจากระบบอื่นจะไม่สามารถ อัปโหลดได้

This commit is contained in:
net 2024-01-12 13:44:22 +07:00
parent dbab045c49
commit 3bbacf78d6
3 changed files with 64 additions and 14 deletions

View file

@ -21,8 +21,13 @@ const fileFormData = ref<{
metadata?: Record<string, unknown>
}>({})
const fileFormType = ref<'edit' | 'create'>('create')
const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({})
const fileFormError = ref<{
fileExistMetadata?: boolean
fileExist?: boolean
fileName2Long?: boolean
}>({})
const fileExistNotification = ref<boolean>(false)
const errorState = ref<'fileExist' | 'fileExistMetadata'>('fileExist')
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
const fileNameLabel = ref<string>()
@ -65,6 +70,18 @@ defineExpose({
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
function checkFileExistMetadata(name: string) {
const fileInfo = file.value[currentInfo.value.path].find(
(v) => v.fileName === name,
)
if (fileInfo?.metadata && Object.keys(fileInfo?.metadata).length > 0) {
return Boolean(true)
}
return Boolean(false)
}
function checkFileExist(name: string, except?: string) {
return Boolean(
file.value[currentInfo.value.path].find(
@ -91,6 +108,16 @@ async function submitFileForm(
) {
currentParam.value = value
const fileInfo = file.value[currentInfo.value.path].find(
(v) => v.fileName === value.file?.name,
)
if (fileInfo?.metadata && Object.keys(fileInfo.metadata).length > 0) {
fileExistNotification.value = true
errorState.value = 'fileExistMetadata'
return
}
if (
value.file &&
file.value[currentInfo.value.path].find(
@ -99,6 +126,7 @@ async function submitFileForm(
!force
) {
fileExistNotification.value = true
errorState.value = 'fileExist'
return
}
@ -150,6 +178,7 @@ async function submitFileForm(
@reset="() => (fileFormError = {})"
@filechange="
(name: string) => {
fileFormError.fileExistMetadata = checkFileExistMetadata(name)
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
(fileFormError.fileName2Long = checkFileName2Long(
name,
@ -161,6 +190,7 @@ async function submitFileForm(
/>
<upload-exist-dialog
v-model:notification="fileExistNotification"
v-model:errorState="errorState"
@confirm="() => currentParam && submitFileForm(currentParam, true)"
@cancel="() => (currentParam = undefined)"
/>