feat: block upload file replace other system file

This commit is contained in:
Methapon2001 2024-01-12 13:53:15 +07:00
parent fb70e5174a
commit b100da112d
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
4 changed files with 12 additions and 19 deletions

View file

@ -10,7 +10,7 @@ const props = withDefaults(
defineProps<{ defineProps<{
open: boolean open: boolean
error: { error: {
fileExistMetadata?: boolean externalFileExist?: boolean
fileExist?: boolean fileExist?: boolean
fileName2Long?: boolean fileName2Long?: boolean
} }
@ -189,12 +189,12 @@ const file = ref<File | undefined>()
: 'เลือกไฟล์' : 'เลือกไฟล์'
" "
:error=" :error="
!!error.fileExistMetadata || !!error.externalFileExist ||
!!error.fileExist || !!error.fileExist ||
!!error.fileName2Long !!error.fileName2Long
" "
:error-message=" :error-message="
error.fileExistMetadata error.externalFileExist
? 'พบไฟล์ชื่อซ้ำในระบบอื่น' ? 'พบไฟล์ชื่อซ้ำในระบบอื่น'
: error.fileExist : error.fileExist
? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ' ? 'พบไฟล์ชื่อซ้ำในระบบ ไฟล์ชื่อนี้ภายในระบบจะถูกเขียนทับ'

View file

@ -22,12 +22,12 @@ const fileFormData = ref<{
}>({}) }>({})
const fileFormType = ref<'edit' | 'create'>('create') const fileFormType = ref<'edit' | 'create'>('create')
const fileFormError = ref<{ const fileFormError = ref<{
fileExistMetadata?: boolean externalFileExist?: boolean
fileExist?: boolean fileExist?: boolean
fileName2Long?: boolean fileName2Long?: boolean
}>({}) }>({})
const fileExistNotification = ref<boolean>(false) const fileExistNotification = ref<boolean>(false)
const errorState = ref<'fileExist' | 'fileExistMetadata'>('fileExist') const errorState = ref<'fileExist' | 'externalFileExist'>('fileExist')
const fileFormComponent = ref<InstanceType<typeof FileForm>>() const fileFormComponent = ref<InstanceType<typeof FileForm>>()
const fileNameLabel = ref<string>() const fileNameLabel = ref<string>()
@ -114,7 +114,7 @@ async function submitFileForm(
if (fileInfo?.metadata && Object.keys(fileInfo.metadata).length > 0) { if (fileInfo?.metadata && Object.keys(fileInfo.metadata).length > 0) {
fileExistNotification.value = true fileExistNotification.value = true
errorState.value = 'fileExistMetadata' errorState.value = 'externalFileExist'
return return
} }
@ -178,7 +178,7 @@ async function submitFileForm(
@reset="() => (fileFormError = {})" @reset="() => (fileFormError = {})"
@filechange=" @filechange="
(name: string) => { (name: string) => {
fileFormError.fileExistMetadata = checkFileExistMetadata(name) fileFormError.externalFileExist = checkFileExistMetadata(name)
;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)), ;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)),
(fileFormError.fileName2Long = checkFileName2Long( (fileFormError.fileName2Long = checkFileName2Long(
name, name,

View file

@ -377,14 +377,7 @@ const onRowClick = ((_, row) => {
@click.stop=" @click.stop="
() => () =>
fileFormComponent?.triggerFileEdit( fileFormComponent?.triggerFileEdit(
{ data.row,
title: data.row.title,
description: data.row.description,
keyword: data.row.keyword,
category: data.row.category,
author: data.row.author,
metadata: data.row.metadata,
},
data.row.pathname, data.row.pathname,
data.row.fileName, data.row.fileName,
) )

View file

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
defineProps<{ defineProps<{
notification: boolean notification: boolean
errorState: 'fileExist' | 'fileExistMetadata' errorState: 'fileExist' | 'externalFileExist'
}>() }>()
defineEmits(['update:notification', 'confirm', 'cancel']) defineEmits(['update:notification', 'confirm', 'cancel'])
@ -25,14 +25,14 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
<div> <div>
<h6 class="q-my-none"> <h6 class="q-my-none">
{{ {{
errorState === 'fileExistMetadata' errorState === 'externalFileExist'
? 'พบไฟล์ชื่อช้ำในระบบอื่น' ? 'พบไฟล์ชื่อช้ำในระบบอื่น'
: 'ยืนยันการเพิ่มข้อมูล' : 'ยืนยันการเพิ่มข้อมูล'
}} }}
</h6> </h6>
<p class="q-my-none"> <p class="q-my-none">
{{ {{
errorState === 'fileExistMetadata' errorState === 'externalFileExist'
? 'พบไฟล์ชื่อช้ำในระบบอื่น จะไม่สามารถอัปโหลดไฟล์นี้ได้' ? 'พบไฟล์ชื่อช้ำในระบบอื่น จะไม่สามารถอัปโหลดไฟล์นี้ได้'
: 'ไฟล์ที่มีอยู่จะถูกแทนที่ด้วยไฟล์ใหม่ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่' : 'ไฟล์ที่มีอยู่จะถูกแทนที่ด้วยไฟล์ใหม่ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่'
}} }}
@ -55,7 +55,7 @@ defineEmits(['update:notification', 'confirm', 'cancel'])
color="warning" color="warning"
@click=" @click="
() => () =>
errorState === 'fileExistMetadata' errorState === 'externalFileExist'
? $emit('cancel') ? $emit('cancel')
: $emit('confirm') : $emit('confirm')
" "