From 245f5fb68a83274b0f4227ddefa8a1c6a040583e Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 31 Aug 2022 13:59:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/file.go | 14 +++ backend/app/dto/file.go | 6 + backend/app/service/file.go | 5 + backend/router/ro_file.go | 1 + frontend/src/api/interface/file.ts | 6 + frontend/src/api/modules/files.ts | 3 + frontend/src/global/mimetype.ts | 17 +++ frontend/src/lang/modules/zh.ts | 4 +- .../index.vue} | 0 .../{compress.vue => compress/index.vue} | 4 +- .../{create.vue => create/index.vue} | 0 .../file-management/decompress/index.vue | 107 ++++++++++++++++++ frontend/src/views/file-management/index.vue | 64 ++++++++--- 13 files changed, 210 insertions(+), 21 deletions(-) create mode 100644 frontend/src/global/mimetype.ts rename frontend/src/views/file-management/{change-role.vue => change-role/index.vue} (100%) rename frontend/src/views/file-management/{compress.vue => compress/index.vue} (97%) rename frontend/src/views/file-management/{create.vue => create/index.vue} (100%) create mode 100644 frontend/src/views/file-management/decompress/index.vue diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index 620075791..19e6b3e26 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -90,3 +90,17 @@ func (b *BaseApi) CompressFile(c *gin.Context) { } helper.SuccessWithData(c, nil) } + +func (b *BaseApi) DeCompressFile(c *gin.Context) { + var req dto.FileDeCompress + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + err := fileService.DeCompress(req) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} diff --git a/backend/app/dto/file.go b/backend/app/dto/file.go index e7d420941..aefebed12 100644 --- a/backend/app/dto/file.go +++ b/backend/app/dto/file.go @@ -38,3 +38,9 @@ type FileCompress struct { Name string Replace bool } + +type FileDeCompress struct { + Dst string + Type string + Path string +} diff --git a/backend/app/service/file.go b/backend/app/service/file.go index 29c915518..1afae647a 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -85,6 +85,11 @@ func (f FileService) Compress(c dto.FileCompress) error { return fo.Compress(c.Files, c.Dst, c.Name, files.CompressType(c.Type)) } +func (f FileService) DeCompress(c dto.FileDeCompress) error { + fo := files.NewFileOp() + return fo.Decompress(c.Path, c.Dst, files.CompressType(c.Type)) +} + func getUuid() string { b := make([]byte, 16) io.ReadFull(rand.Reader, b) diff --git a/backend/router/ro_file.go b/backend/router/ro_file.go index 6fa85b8d3..3b3125947 100644 --- a/backend/router/ro_file.go +++ b/backend/router/ro_file.go @@ -21,6 +21,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) { fileRouter.POST("/del", baseApi.DeleteFile) fileRouter.POST("/mode", baseApi.ChangeFileMode) fileRouter.POST("/compress", baseApi.CompressFile) + fileRouter.POST("/decompress", baseApi.DeCompressFile) } } diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index ed9863667..d2f2c5245 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -49,4 +49,10 @@ export namespace File { name: string; replace: boolean; } + + export interface FileDeCompress { + path: string; + dst: string; + type: string; + } } diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 1d119fed8..52d1783dc 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -24,3 +24,6 @@ export const ChangeFileMode = (form: File.FileCreate) => { export const CompressFile = (form: File.FileCompress) => { return http.post('files/compress', form); }; +export const DeCompressFile = (form: File.FileDeCompress) => { + return http.post('files/decompress', form); +}; diff --git a/frontend/src/global/mimetype.ts b/frontend/src/global/mimetype.ts new file mode 100644 index 000000000..38b3d46b5 --- /dev/null +++ b/frontend/src/global/mimetype.ts @@ -0,0 +1,17 @@ +import { CompressType } from '@/enums/files'; + +export const Mimetypes = new Map([ + ['application/zip', CompressType.Zip], + ['application/x-zip', CompressType.Zip], + ['application/x-zip-compressed', CompressType.Zip], + ['application/x-tar', CompressType.Tar], + ['application/x-bzip2', CompressType.Bz2], + ['application/gzip', CompressType.TarGz], + ['application/x-gzip', CompressType.TarGz], + ['application/x-gunzip', CompressType.TarGz], + ['application/gzipped', CompressType.TarGz], + ['application/gzip-compressed', CompressType.TarGz], + ['application/x-gzip-compressed', CompressType.TarGz], + ['gzip/document', CompressType.TarGz], + ['application/x-xz', CompressType.Xz], +]); diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index e13736afd..a779099ad 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -33,7 +33,6 @@ export default { sureLogOut: '您是否确认退出登录?', createSuccess: '新建成功', updateSuccess: '更新成功', - compressSuccess: '压缩成功', }, login: { captchaHelper: '请输入验证码', @@ -190,5 +189,8 @@ export default { compressType: '压缩格式', compressDst: '压缩路径', replace: '覆盖已存在的文件', + compressSuccess: '压缩成功', + deCompressSuccess: '解压成功', + deCompressDst: '解压路径', }, }; diff --git a/frontend/src/views/file-management/change-role.vue b/frontend/src/views/file-management/change-role/index.vue similarity index 100% rename from frontend/src/views/file-management/change-role.vue rename to frontend/src/views/file-management/change-role/index.vue diff --git a/frontend/src/views/file-management/compress.vue b/frontend/src/views/file-management/compress/index.vue similarity index 97% rename from frontend/src/views/file-management/compress.vue rename to frontend/src/views/file-management/compress/index.vue index 013a358d5..57b4f5720 100644 --- a/frontend/src/views/file-management/compress.vue +++ b/frontend/src/views/file-management/compress/index.vue @@ -110,10 +110,10 @@ const submit = async (formEl: FormInstance | undefined) => { let addItem = {}; Object.assign(addItem, form.value); addItem['name'] = form.value.name + extension.value; - + loading.value = true; CompressFile(addItem as File.FileCompress) .then(() => { - ElMessage.success(i18n.global.t('commons.msg.compressSuccess')); + ElMessage.success(i18n.global.t('file.compressSuccess')); handleClose(); }) .finally(() => { diff --git a/frontend/src/views/file-management/create.vue b/frontend/src/views/file-management/create/index.vue similarity index 100% rename from frontend/src/views/file-management/create.vue rename to frontend/src/views/file-management/create/index.vue diff --git a/frontend/src/views/file-management/decompress/index.vue b/frontend/src/views/file-management/decompress/index.vue new file mode 100644 index 000000000..5d0b9f658 --- /dev/null +++ b/frontend/src/views/file-management/decompress/index.vue @@ -0,0 +1,107 @@ + + + diff --git a/frontend/src/views/file-management/index.vue b/frontend/src/views/file-management/index.vue index 6bf76a6d6..92bad70b2 100644 --- a/frontend/src/views/file-management/index.vue +++ b/frontend/src/views/file-management/index.vue @@ -96,8 +96,8 @@ /> - - + + + @@ -119,9 +127,10 @@ import { dateFromat } from '@/utils/util'; import { File } from '@/api/interface/file'; import BreadCrumbs from '@/components/bread-crumbs/index.vue'; import BreadCrumbItem from '@/components/bread-crumbs/bread-crumbs-item.vue'; -import CreateFile from './create.vue'; -import ChangeRole from './change-role.vue'; -import Compress from './compress.vue'; +import CreateFile from './create/index.vue'; +import ChangeRole from './change-role/index.vue'; +import Compress from './compress/index.vue'; +import Decompress from './decompress/index.vue'; import { useDeleteData } from '@/hooks/use-delete-data'; let data = ref(); @@ -132,12 +141,11 @@ let treeLoading = ref(false); let paths = ref([]); let fileTree = ref([]); let expandKeys = ref([]); -let openCreate = ref(false); -let fileCreate = ref({ path: '/', isDir: false, mode: 0o755 }); -let openModePage = ref(false); -let modeForm = ref({ path: '/', isDir: false, mode: 0o755 }); +let filePage = reactive({ open: false, createForm: { path: '/', isDir: false, mode: 0o755 } }); +let modePage = reactive({ open: false, modeForm: { path: '/', isDir: false, mode: 0o755 } }); let compressPage = reactive({ open: false, files: [''], name: '', dst: '' }); +let deCompressPage = reactive({ open: false, path: '', name: '', dst: '', mimeType: '' }); const defaultProps = { children: 'children', @@ -234,12 +242,12 @@ const loadNode = (node: any, resolve: (data: File.FileTree[]) => void) => { }; const handleCreate = (commnad: string) => { - fileCreate.value.path = req.path; - fileCreate.value.isDir = false; + filePage.createForm.path = req.path; + filePage.createForm.isDir = false; if (commnad === 'dir') { - fileCreate.value.isDir = true; + filePage.createForm.isDir = true; } - openCreate.value = true; + filePage.open = true; }; const delFile = async (row: File.File | null) => { @@ -248,17 +256,17 @@ const delFile = async (row: File.File | null) => { }; const closeCreate = () => { - openCreate.value = false; + filePage.open = false; search(req); }; const openMode = (item: File.File) => { - modeForm.value = item; - openModePage.value = true; + modePage.modeForm = item; + modePage.open = true; }; const closeMode = () => { - openModePage.value = false; + modePage.open = false; search(req); }; @@ -273,10 +281,26 @@ const closeCompress = () => { compressPage.open = false; search(req); }; + +const openDeCompress = (item: File.File) => { + deCompressPage.open = true; + deCompressPage.name = item.name; + deCompressPage.path = item.path; + deCompressPage.dst = req.path; + deCompressPage.mimeType = item.mimeType; +}; + +const closeDeCompress = () => { + deCompressPage.open = false; + search(req); +}; + onMounted(() => { search(req); }); +//TODO button增加v-if判断 +//openDeCompress 增加是否可以解压判断 const buttons = [ { label: i18n.global.t('file.open'), @@ -287,9 +311,13 @@ const buttons = [ click: openMode, }, { - label: i18n.global.t('file.zip'), + label: i18n.global.t('file.compress'), click: openCompress, }, + { + label: i18n.global.t('file.deCompress'), + click: openDeCompress, + }, { label: i18n.global.t('file.rename'), },