diff --git a/backend/app/dto/request/file.go b/backend/app/dto/request/file.go index a7082451c..a7c384ead 100644 --- a/backend/app/dto/request/file.go +++ b/backend/app/dto/request/file.go @@ -20,7 +20,7 @@ type FileCreate struct { IsDir bool `json:"isDir"` Mode int64 `json:"mode" validate:"required"` IsLink bool `json:"isLink"` - IsSymlink bool `json:"isSymlink "` + IsSymlink bool `json:"isSymlink"` LinkPath string `json:"linkPath"` } diff --git a/backend/app/service/file.go b/backend/app/service/file.go index a9a6dc600..3c61feb76 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -93,12 +93,15 @@ func (f FileService) GetFileTree(op request.FileOption) ([]response.FileTree, er func (f FileService) Create(op request.FileCreate) error { fo := files.NewFileOp() if fo.Stat(op.Path) { - return errors.New("file is exist") + return buserr.New(constant.ErrFileIsExit) } if op.IsDir { return fo.CreateDir(op.Path, fs.FileMode(op.Mode)) } else { if op.IsLink { + if !fo.Stat(op.Path) { + return buserr.New(constant.ErrLinkPathNotFound) + } return fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink) } else { return fo.CreateFile(op.Path) diff --git a/backend/constant/errs.go b/backend/constant/errs.go index d78af1791..2a9ce983b 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -79,8 +79,10 @@ var ( //file var ( - ErrPathNotFound = "ErrPathNotFound" - ErrMovePathFailed = "ErrMovePathFailed" + ErrPathNotFound = "ErrPathNotFound" + ErrMovePathFailed = "ErrMovePathFailed" + ErrLinkPathNotFound = "ErrLinkPathNotFound" + ErrFileIsExit = "ErrFileIsExit" ) //mysql diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index f67ec16f4..f11ee56cb 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -32,6 +32,8 @@ ErrFileCanNotRead: "File can not read" ErrFileToLarge: "file is too large" ErrPathNotFound: "Path is not found" ErrMovePathFailed: "The target path cannot contain the original path!" +ErrLinkPathNotFound: "Target path does not exist!" +ErrFileIsExit: "File already exists!" #website ErrDomainIsExist: "Domain is already exist" diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index e59bafd6d..169b5421f 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -32,6 +32,8 @@ ErrFileCanNotRead: "此文件不支持预览" ErrFileToLarge: "文件超过10M,无法打开" ErrPathNotFound: "目录不存在" ErrMovePathFailed: "目标路径不能包含原路径!" +ErrLinkPathNotFound: "目标路径不存在!" +ErrFileIsExit: "文件已存在!" #website ErrDomainIsExist: "域名已存在" diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index bfac51d84..33ca60dfa 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -151,7 +151,6 @@ func (w *WriteCounter) SaveProcess() { global.LOG.Errorf("save cache error, err %s", err.Error()) } } - } func (f FileOp) DownloadFileWithProcess(url, dst, key string) error { @@ -183,7 +182,6 @@ func (f FileOp) DownloadFileWithProcess(url, dst, key string) error { out.Close() resp.Body.Close() }() - return nil } @@ -205,7 +203,6 @@ func (f FileOp) DownloadFile(url, dst string) error { } out.Close() resp.Body.Close() - return nil }