From 89b95e0d456e37293da9726dd2c7ed450bdea74e Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Sat, 3 Sep 2022 18:41:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=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 | 23 +++++++ backend/app/api/v1/helper/helper.go | 9 +++ backend/router/ro_file.go | 1 + frontend/package-lock.json | 68 ++++++++++++++++++- frontend/src/api/modules/files.ts | 4 ++ frontend/src/lang/modules/zh.ts | 3 +- .../file-management/code-editor/index.vue | 34 ++++++++-- .../views/file-management/compress/index.vue | 6 +- .../views/file-management/create/index.vue | 8 +-- .../file-management/decompress/index.vue | 2 +- frontend/src/views/file-management/index.vue | 36 ++++++++-- .../views/file-management/upload/index.vue | 64 +++++++++++++++++ 12 files changed, 236 insertions(+), 22 deletions(-) create mode 100644 frontend/src/views/file-management/upload/index.vue diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index 66b8b19b9..b3943956e 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -1,10 +1,13 @@ package v1 import ( + "fmt" "github.com/1Panel-dev/1Panel/app/api/v1/helper" "github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/constant" + "github.com/1Panel-dev/1Panel/global" "github.com/gin-gonic/gin" + "path" ) func (b *BaseApi) ListFiles(c *gin.Context) { @@ -131,3 +134,23 @@ func (b *BaseApi) SaveContent(c *gin.Context) { } helper.SuccessWithData(c, nil) } + +func (b *BaseApi) UploadFiles(c *gin.Context) { + form, err := c.MultipartForm() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + files := form.File["file"] + paths := form.Value["path"] + success := 0 + for _, file := range files { + err := c.SaveUploadedFile(file, path.Join(paths[0], file.Filename)) + if err != nil { + global.LOG.Errorf("upload [%s] file failed, err: %v", file.Filename, err) + continue + } + success++ + } + helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success)) +} diff --git a/backend/app/api/v1/helper/helper.go b/backend/app/api/v1/helper/helper.go index dab2f5861..bfba943ee 100644 --- a/backend/app/api/v1/helper/helper.go +++ b/backend/app/api/v1/helper/helper.go @@ -68,6 +68,15 @@ func SuccessWithData(ctx *gin.Context, data interface{}) { ctx.Abort() } +func SuccessWithMsg(ctx *gin.Context, msg string) { + res := dto.Response{ + Code: constant.CodeSuccess, + Msg: msg, + } + ctx.JSON(http.StatusOK, res) + ctx.Abort() +} + func GetParamID(c *gin.Context) (uint, error) { idParam, ok := c.Params.Get("id") if !ok { diff --git a/backend/router/ro_file.go b/backend/router/ro_file.go index a17e139ee..a568ce29e 100644 --- a/backend/router/ro_file.go +++ b/backend/router/ro_file.go @@ -24,6 +24,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) { fileRouter.POST("/decompress", baseApi.DeCompressFile) fileRouter.POST("/content", baseApi.GetContent) fileRouter.POST("/save", baseApi.SaveContent) + fileRouter.POST("/upload", baseApi.UploadFiles) } } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 12e86e8ae..9b3a9b72f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,6 +15,7 @@ "echarts-liquidfill": "^3.1.0", "element-plus": "^2.2.13", "fit2cloud-ui-plus": "^0.0.1-beta.15", + "js-base64": "^3.7.2", "js-md5": "^0.7.3", "monaco-editor": "^0.34.0", "nprogress": "^0.2.0", @@ -22,12 +23,16 @@ "pinia-plugin-persistedstate": "^1.6.1", "qs": "^6.10.3", "sass-loader": "^13.0.2", + "screenfull": "^6.0.2", "unplugin-vue-define-options": "^0.7.3", "vite-plugin-monaco-editor": "^1.1.0", "vue": "^3.2.25", "vue-i18n": "^9.1.9", "vue-router": "^4.0.12", - "vue3-seamless-scroll": "^1.2.0" + "vue3-seamless-scroll": "^1.2.0", + "xterm": "^4.19.0", + "xterm-addon-attach": "^0.6.0", + "xterm-addon-fit": "^0.5.0" }, "devDependencies": { "@commitlint/cli": "^17.0.1", @@ -5863,6 +5868,11 @@ "node": ">=10" } }, + "node_modules/js-base64": { + "version": "3.7.2", + "resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.2.tgz", + "integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==" + }, "node_modules/js-md5": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz", @@ -7806,6 +7816,14 @@ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "peer": true }, + "node_modules/screenfull": { + "version": "6.0.2", + "resolved": "https://registry.npmmirror.com/screenfull/-/screenfull-6.0.2.tgz", + "integrity": "sha512-AQdy8s4WhNvUZ6P8F6PB21tSPIYKniic+Ogx0AacBMjKP1GUHN2E9URxQHtCusiwxudnCKkdy4GrHXPPJSkCCw==", + "engines": { + "node": "^14.13.1 || >=16.0.0" + } + }, "node_modules/select": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", @@ -9774,6 +9792,27 @@ "node": ">=0.4" } }, + "node_modules/xterm": { + "version": "4.19.0", + "resolved": "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz", + "integrity": "sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==" + }, + "node_modules/xterm-addon-attach": { + "version": "0.6.0", + "resolved": "https://registry.npmmirror.com/xterm-addon-attach/-/xterm-addon-attach-0.6.0.tgz", + "integrity": "sha512-Mo8r3HTjI/EZfczVCwRU6jh438B4WLXxdFO86OB7bx0jGhwh2GdF4ifx/rP+OB+Cb2vmLhhVIZ00/7x3YSP3dg==", + "peerDependencies": { + "xterm": "^4.0.0" + } + }, + "node_modules/xterm-addon-fit": { + "version": "0.5.0", + "resolved": "https://registry.npmmirror.com/xterm-addon-fit/-/xterm-addon-fit-0.5.0.tgz", + "integrity": "sha512-DsS9fqhXHacEmsPxBJZvfj2la30Iz9xk+UKjhQgnYNkrUIN5CYLbw7WEfz117c7+S86S/tpHPfvNxJsF5/G8wQ==", + "peerDependencies": { + "xterm": "^4.0.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -14390,6 +14429,11 @@ } } }, + "js-base64": { + "version": "3.7.2", + "resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.2.tgz", + "integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==" + }, "js-md5": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz", @@ -15942,6 +15986,11 @@ } } }, + "screenfull": { + "version": "6.0.2", + "resolved": "https://registry.npmmirror.com/screenfull/-/screenfull-6.0.2.tgz", + "integrity": "sha512-AQdy8s4WhNvUZ6P8F6PB21tSPIYKniic+Ogx0AacBMjKP1GUHN2E9URxQHtCusiwxudnCKkdy4GrHXPPJSkCCw==" + }, "select": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", @@ -17428,6 +17477,23 @@ "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", "dev": true }, + "xterm": { + "version": "4.19.0", + "resolved": "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz", + "integrity": "sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==" + }, + "xterm-addon-attach": { + "version": "0.6.0", + "resolved": "https://registry.npmmirror.com/xterm-addon-attach/-/xterm-addon-attach-0.6.0.tgz", + "integrity": "sha512-Mo8r3HTjI/EZfczVCwRU6jh438B4WLXxdFO86OB7bx0jGhwh2GdF4ifx/rP+OB+Cb2vmLhhVIZ00/7x3YSP3dg==", + "requires": {} + }, + "xterm-addon-fit": { + "version": "0.5.0", + "resolved": "https://registry.npmmirror.com/xterm-addon-fit/-/xterm-addon-fit-0.5.0.tgz", + "integrity": "sha512-DsS9fqhXHacEmsPxBJZvfj2la30Iz9xk+UKjhQgnYNkrUIN5CYLbw7WEfz117c7+S86S/tpHPfvNxJsF5/G8wQ==", + "requires": {} + }, "y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 21c2acaa6..05005a233 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -36,3 +36,7 @@ export const GetFileContent = (params: File.ReqFile) => { export const SaveFileContent = (params: File.FileEdit) => { return http.post('files/save', params); }; + +export const UploadFileData = (params: FormData) => { + return http.post('files/upload', params); +}; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 7dba2bf3c..73fe00ad5 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2,14 +2,12 @@ export default { commons: { button: { create: '新建', - create: '创建', add: '添加', delete: '删除', edit: '编辑', confirm: '确认', cancel: '取消', reset: '重置', - login: '登陆', conn: '连接', login: '登录', }, @@ -197,5 +195,6 @@ export default { softLink: '软链接', hardLink: '硬链接', linkPath: '链接路径', + selectFile: '选择文件', }, }; diff --git a/frontend/src/views/file-management/code-editor/index.vue b/frontend/src/views/file-management/code-editor/index.vue index 639b5d52f..8618dabcc 100644 --- a/frontend/src/views/file-management/code-editor/index.vue +++ b/frontend/src/views/file-management/code-editor/index.vue @@ -1,12 +1,22 @@ - {{ $t('file.upload') }} + {{ $t('file.upload') }} {{ $t('file.search') }} {{ $t('file.remoteFile') }}