diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index dae54cfe8..72dc008db 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -410,11 +410,20 @@ func (b *BaseApi) CheckFile(c *gin.Context) { if err := helper.CheckBindAndValidate(&req, c); err != nil { return } - if _, err := os.Stat(req.Path); err != nil { - helper.SuccessWithData(c, false) + fileOp := files.NewFileOp() + if fileOp.Stat(req.Path) { + helper.SuccessWithData(c, true) return } - helper.SuccessWithData(c, true) + if req.WithInit { + if err := fileOp.CreateDir(req.Path, 0644); err != nil { + helper.SuccessWithData(c, false) + return + } + helper.SuccessWithData(c, true) + return + } + helper.SuccessWithData(c, false) } // @Tags File diff --git a/backend/app/dto/request/file.go b/backend/app/dto/request/file.go index 6a31b611a..4cc20a737 100644 --- a/backend/app/dto/request/file.go +++ b/backend/app/dto/request/file.go @@ -76,7 +76,8 @@ type FileRename struct { } type FilePathCheck struct { - Path string `json:"path" validate:"required"` + Path string `json:"path" validate:"required"` + WithInit bool `json:"withInit"` } type FilePathsCheck struct { diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index c914669e3..5ca20c121 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -49,8 +49,8 @@ export const SaveFileContent = (params: File.FileEdit) => { return http.post('files/save', params); }; -export const CheckFile = (path: string) => { - return http.post('files/check', { path: path }); +export const CheckFile = (path: string, withInit: boolean) => { + return http.post('files/check', { path: path, withInit: withInit }); }; export const BatchCheckFiles = (paths: string[]) => { diff --git a/frontend/src/components/upload/index.vue b/frontend/src/components/upload/index.vue index eceffa52f..e4df52838 100644 --- a/frontend/src/components/upload/index.vue +++ b/frontend/src/components/upload/index.vue @@ -308,7 +308,7 @@ const onSubmit = async () => { MsgError(i18n.global.t('commons.msg.fileNameErr')); return; } - const res = await CheckFile(baseDir.value + file.raw.name); + const res = await CheckFile(baseDir.value + file.raw.name, false); if (res.data) { MsgError(i18n.global.t('commons.msg.fileExist')); return; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index b317d8d65..b254e23c0 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1385,6 +1385,7 @@ const message = { existFileHelper: 'The uploaded file contains a file with the same name, do you want to overwrite it?', existFileSize: 'File size (new -> old)', existFileDirHelper: 'The selected file/folder has a duplicate name. Please proceed with caution!', + noSuchFile: 'The file or directory was not found. Please check and try again.', }, ssh: { setting: 'Setting', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index a6240e971..64909448c 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -1363,6 +1363,7 @@ const message = { existFileHelper: 'アップロードしたファイルに同じ名前のファイルが含まれています。上書きしますか?', existFileSize: 'ファイルサイズ(新しい -> 古い)', existFileDirHelper: '選択したファイル/フォルダーには同じ名前のものが既に存在します。慎重に操作してください!', + noSuchFile: 'ファイルまたはディレクトリが見つかりませんでした。確認して再試行してください。', }, ssh: { setting: '設定', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index e7f19f255..ed271d07f 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -1349,6 +1349,7 @@ const message = { existFileHelper: '업로드한 파일에 동일한 이름의 파일이 포함되어 있습니다. 덮어쓰시겠습니까?', existFileSize: '파일 크기 (새로운 -> 오래된)', existFileDirHelper: '선택한 파일/폴더에 동일한 이름이 이미 존재합니다. 신중하게 작업하세요!', + noSuchFile: '파일 또는 디렉터리를 찾을 수 없습니다. 확인 후 다시 시도하세요.', }, ssh: { setting: '설정', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index ca4860358..ff5443654 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -1406,6 +1406,7 @@ const message = { existFileHelper: 'Fail yang dimuat naik mengandungi fail dengan nama yang sama. Adakah anda mahu menimpanya?', existFileSize: 'Saiz fail (baru -> lama)', existFileDirHelper: 'Fail/folder yang dipilih mempunyai nama yang sama. Sila berhati-hati!', + noSuchFile: 'Fail atau direktori tidak ditemui. Sila periksa dan cuba lagi.', }, ssh: { setting: 'tetapan', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index d6ca6c570..5b5143827 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -1393,6 +1393,7 @@ const message = { existFileHelper: 'O arquivo enviado contém um arquivo com o mesmo nome. Deseja substituí-lo?', existFileSize: 'Tamanho do arquivo (novo -> antigo)', existFileDirHelper: 'O arquivo/pasta selecionado tem um nome duplicado. Por favor, prossiga com cautela!', + noSuchFile: 'O arquivo ou diretório não foi encontrado. Por favor, verifique e tente novamente.', }, ssh: { setting: 'configuração', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index fb0386934..4bd46e8d3 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -1395,6 +1395,7 @@ const message = { existFileHelper: 'Загруженный файл содержит файл с таким же именем. Заменить его?', existFileSize: 'Размер файла (новый -> старый)', existFileDirHelper: 'Выбранный файл/папка имеет дублирующееся имя. Пожалуйста, действуйте осторожно!', + noSuchFile: 'Файл или каталог не найдены. Пожалуйста, проверьте и повторите попытку.', }, ssh: { setting: 'настройка', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index c09f85a48..76bd54bca 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1319,6 +1319,7 @@ const message = { existFileHelper: '上傳的檔案存在同名檔案,是否覆蓋?', existFileSize: '文件大小(新->舊)', existFileDirHelper: '選擇的檔案/資料夾存在同名,請謹慎操作!', + noSuchFile: '找不到該檔案或目錄,請檢查後重試。', }, ssh: { setting: '設定', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 145e5e515..877a12ed7 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1321,6 +1321,7 @@ const message = { existFileHelper: '上传的文件存在同名文件,是否覆盖?', existFileSize: '文件大小 (新 -> 旧)', existFileDirHelper: '选择的文件/文件夹存在同名,请谨慎操作!', + noSuchFile: '未能找到该文件或目录,请检查后重试', }, ssh: { setting: '配置', diff --git a/frontend/src/views/host/file-management/move/index.vue b/frontend/src/views/host/file-management/move/index.vue index a01d98e0c..6ed9bd55e 100644 --- a/frontend/src/views/host/file-management/move/index.vue +++ b/frontend/src/views/host/file-management/move/index.vue @@ -234,7 +234,7 @@ const acceptParams = async (props: MoveProps) => { type.value = props.type; if (props.name && props.name != '') { oldName.value = props.name; - const res = await CheckFile(props.path + '/' + props.name); + const res = await CheckFile(props.path + '/' + props.name, false); if (res.data) { changeName.value = true; addForm.cover = false; diff --git a/frontend/src/views/setting/snapshot/import/index.vue b/frontend/src/views/setting/snapshot/import/index.vue index 788f34a35..20f68827f 100644 --- a/frontend/src/views/setting/snapshot/import/index.vue +++ b/frontend/src/views/setting/snapshot/import/index.vue @@ -60,8 +60,9 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; import { snapshotImport } from '@/api/modules/setting'; import { getBackupList, getFilesFromBackup } from '@/api/modules/setting'; import { Rules } from '@/global/form-rules'; -import { MsgSuccess } from '@/utils/message'; +import { MsgError, MsgSuccess } from '@/utils/message'; import router from '@/routers'; +import { CheckFile } from '@/api/modules/files'; const drawerVisible = ref(false); const loading = ref(); @@ -109,7 +110,12 @@ const checkDisable = (val: string) => { return false; }; const toFolder = async () => { - router.push({ path: '/hosts/files', query: { path: backupPath.value } }); + const res = await CheckFile(backupPath.value, true); + if (res.data) { + router.push({ path: '/hosts/files', query: { path: backupPath.value } }); + } else { + MsgError(i18n.global.t('file.noSuchFile')); + } }; const submitImport = async (formEl: FormInstance | undefined) => {