diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index b3943956e..0b862e191 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -154,3 +154,16 @@ func (b *BaseApi) UploadFiles(c *gin.Context) { } helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success)) } + +func (b *BaseApi) ChangeName(c *gin.Context) { + var req dto.FileRename + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := fileService.ChangeName(req); 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 1ed800c92..7f3973c33 100644 --- a/backend/app/dto/file.go +++ b/backend/app/dto/file.go @@ -52,3 +52,8 @@ type FileEdit struct { Path string Content string } + +type FileRename struct { + OldName string + NewName string +} diff --git a/backend/app/service/file.go b/backend/app/service/file.go index a8fc7ad1e..336acfa95 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -115,6 +115,11 @@ func (f FileService) SaveContent(c dto.FileEdit) error { return fo.WriteFile(c.Path, strings.NewReader(c.Content), info.FileMode) } +func (f FileService) ChangeName(c dto.FileRename) error { + fo := files.NewFileOp() + return fo.Rename(c.OldName, c.NewName) +} + 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 a568ce29e..7aa7453a1 100644 --- a/backend/router/ro_file.go +++ b/backend/router/ro_file.go @@ -25,6 +25,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) { fileRouter.POST("/content", baseApi.GetContent) fileRouter.POST("/save", baseApi.SaveContent) fileRouter.POST("/upload", baseApi.UploadFiles) + fileRouter.POST("/rename", baseApi.ChangeName) } } diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index cd82f3f1a..a3c9203ff 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -77,6 +77,10 @@ func (f FileOp) Chmod(dst string, mode fs.FileMode) error { return f.Fs.Chmod(dst, mode) } +func (f FileOp) Rename(oldName string, newName string) error { + return f.Fs.Rename(oldName, newName) +} + type CompressType string const ( diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index c039df342..b45aded48 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -64,4 +64,9 @@ export namespace File { path: string; content: string; } + + export interface FileRename { + oldName: string; + newName: string; + } } diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 05005a233..b163d0624 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -40,3 +40,7 @@ export const SaveFileContent = (params: File.FileEdit) => { export const UploadFileData = (params: FormData) => { return http.post('files/upload', params); }; + +export const RenameRile = (params: File.FileRename) => { + return http.post('files/rename', params); +}; diff --git a/frontend/src/components/file-role/index.vue b/frontend/src/components/file-role/index.vue index 3763364f4..132fce99b 100644 --- a/frontend/src/components/file-role/index.vue +++ b/frontend/src/components/file-role/index.vue @@ -152,11 +152,6 @@ const changeMode = (val: String) => { getRoleNum(val[3], form.value.public); }; -// onMounted(() => { -// form.value.mode = mode.value; -// changeMode(form.value.mode); -// }); - onUpdated(() => { form.value.mode = mode.value; changeMode(form.value.mode); diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 30df7147c..477f83126 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -32,6 +32,7 @@ export default { sureLogOut: 'Are you sure you want to log out?', createSuccess: 'Create Success', updateSuccess: 'Update Success', + uploadSuccess: 'Update Success', }, login: { captchaHelper: 'Please enter the verification code', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 73fe00ad5..b9d1c856f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -32,6 +32,7 @@ export default { sureLogOut: '您是否确认退出登录?', createSuccess: '新建成功', updateSuccess: '更新成功', + uploadSuccess: '上传成功', }, login: { captchaHelper: '请输入验证码', diff --git a/frontend/src/views/file-management/file-rename/index.vue b/frontend/src/views/file-management/file-rename/index.vue new file mode 100644 index 000000000..bd4dc2f1c --- /dev/null +++ b/frontend/src/views/file-management/file-rename/index.vue @@ -0,0 +1,95 @@ + + + diff --git a/frontend/src/views/file-management/index.vue b/frontend/src/views/file-management/index.vue index df155cef7..1338ccd1f 100644 --- a/frontend/src/views/file-management/index.vue +++ b/frontend/src/views/file-management/index.vue @@ -124,6 +124,12 @@ @qsave="quickSave" @save="saveContent" > + @@ -144,6 +150,7 @@ import ChangeRole from './change-role/index.vue'; import Compress from './compress/index.vue'; import Decompress from './decompress/index.vue'; import Upload from './upload/index.vue'; +import FileRename from './file-rename/index.vue'; import { useDeleteData } from '@/hooks/use-delete-data'; import CodeEditor from './code-editor/index.vue'; import { ElMessage } from 'element-plus'; @@ -157,13 +164,14 @@ let paths = ref([]); let fileTree = ref([]); let expandKeys = ref([]); -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: '' }); -let editorPage = reactive({ open: false, content: '', loading: false }); -let codeReq = reactive({ path: '', expand: false }); +const filePage = reactive({ open: false, createForm: { path: '/', isDir: false, mode: 0o755 } }); +const modePage = reactive({ open: false, modeForm: { path: '/', isDir: false, mode: 0o755 } }); +const compressPage = reactive({ open: false, files: [''], name: '', dst: '' }); +const deCompressPage = reactive({ open: false, path: '', name: '', dst: '', mimeType: '' }); +const editorPage = reactive({ open: false, content: '', loading: false }); +const codeReq = reactive({ path: '', expand: false }); const uploadPage = reactive({ open: false, path: '' }); +const renamePage = reactive({ open: false, path: '', oldName: '' }); const defaultProps = { children: 'children', @@ -338,6 +346,17 @@ const closeUpload = () => { search(req); }; +const openRename = (item: File.File) => { + renamePage.open = true; + renamePage.path = req.path; + renamePage.oldName = item.name; +}; + +const closeRename = () => { + renamePage.open = false; + search(req); +}; + const saveContent = (content: string) => { editorPage.loading = true; SaveFileContent({ path: codeReq.path, content: content }).finally(() => { @@ -380,6 +399,7 @@ const buttons = [ }, { label: i18n.global.t('file.rename'), + click: openRename, }, { label: i18n.global.t('commons.button.delete'),