$emit('delete')">
ลบ
@@ -34,10 +25,4 @@ defineEmits(['editname', 'deletename'])
-
- (confirmDelete = false)"
- />
diff --git a/Services/client/src/components/FolderForm.vue b/Services/client/src/components/FolderForm.vue
new file mode 100644
index 0000000..36d0551
--- /dev/null
+++ b/Services/client/src/components/FolderForm.vue
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+ สร้าง{{ tree }}
+
+
+ แก้ไข{{ tree }}
+
+
+ $emit('update:open', !open)"
+ />
+
+
+
+ ชื่อ{{ tree }}
+ $emit('update:name', v)"
+ />
+
+
+
+
+ ($emit('update:open', false), reset())"
+ />
+
+
+
+
+
+
diff --git a/Services/client/src/stores/tree-data.ts b/Services/client/src/stores/tree-data.ts
index 4046fba..d1fc866 100644
--- a/Services/client/src/stores/tree-data.ts
+++ b/Services/client/src/stores/tree-data.ts
@@ -244,8 +244,8 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
metadata: {
title: string
description: string
- keyword: string[]
- category: string[]
+ keyword: string
+ category: string
}
) {
loader.show()
@@ -261,35 +261,102 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
if (pathArray.length >= 4) requestPath += `/subfolder/${pathArray[3]}`
requestPath += '/file'
- const formData = new FormData()
+ const res = await axiosClient.post(
+ `${apiEndpoint}${requestPath}`,
+ {
+ file: file.name,
+ ...metadata,
+ }
+ )
- formData.append('file', file)
- formData.append('title', metadata.title)
- formData.append('description', metadata.description)
- formData.append('keyword', metadata.keyword.join(','))
- formData.append('category', metadata.category.join(','))
+ if (res && res.data.upload) {
+ await fetch(res.data.upload, {
+ method: 'PUT',
+ body: file,
+ })
- await axiosClient.post(`${apiEndpoint}${requestPath}`, formData)
+ loader.hide()
+ }
- if (currentDept.value === 0) await getCabinet()
- else await getFolder(currentPath.value)
+ if (currentDept.value === 0) {
+ await getCabinet()
+ } else await getFolder(currentPath.value)
+
+ await getFile(currentPath.value)
return loader.hide()
}
- function checkFile(nameFile: string) {
- const fileExists = currentFile.value.some((element) => {
- if (element.fileName === nameFile) {
- console.log(element.fileName + '===' + nameFile)
- return true
- }
- return false
- })
+ async function updateFile(
+ pathname: string,
+ metadata: {
+ title: string
+ description: string
+ keyword: string
+ category: string
+ },
+ file?: File
+ ) {
+ loader.show()
- if (fileExists) {
- return false
+ const pathArray: string[] = pathname.split('/').filter(Boolean)
+
+ if (pathArray.length < 4) return loader.hide()
+
+ let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
+ if (pathArray.length >= 4) requestPath += `/folder/${pathArray[2]}`
+ if (pathArray.length >= 5) requestPath += `/subfolder/${pathArray[3]}`
+ requestPath += `/file/${pathArray.at(-1)}`
+
+ const res = await axiosClient.patch<{ upload: string }>(
+ `${apiEndpoint}${requestPath}`,
+ { file: file?.name, ...metadata }
+ )
+
+ if (res && res.data.upload) {
+ await fetch(res.data.upload, {
+ method: 'PUT',
+ body: file,
+ })
+
+ loader.hide()
}
- return true
+
+ if (currentDept.value === 0) {
+ await getCabinet()
+ } else await getFolder(currentPath.value)
+
+ await getFile(currentPath.value)
+
+ return loader.hide()
+ }
+
+ async function deleteFile(pathname: string) {
+ loader.show()
+
+ const pathArray: string[] = pathname.split('/').filter(Boolean)
+
+ if (pathArray.length < 4) return loader.hide()
+
+ let requestPath = `cabinet/${pathArray[0]}/drawer/${pathArray[1]}`
+ if (pathArray.length >= 4) requestPath += `/folder/${pathArray[2]}`
+ if (pathArray.length >= 5) requestPath += `/subfolder/${pathArray[3]}`
+ requestPath += `/file/${pathArray.at(-1)}`
+
+ console.log(requestPath, pathArray)
+ await axiosClient.delete(`${apiEndpoint}${requestPath}`)
+
+ if (currentDept.value === 0) {
+ await getCabinet()
+ } else await getFolder(currentPath.value)
+
+ await getFile(currentPath.value)
+
+ return loader.hide()
+ }
+
+ function checkFile(fileName: string) {
+ return currentFile.value.some((element) => element.fileName === fileName)
}
return {
@@ -303,6 +370,8 @@ export const useTreeDataStore = defineStore('changeCabinet', () => {
getCabinet,
getFolder,
uploadFile,
+ updateFile,
+ deleteFile,
gotoParent,
createFolder,
deleteFolder,