fix: Fix the problem that jumping to a directory that does not exist … (#8353)
Some checks are pending
SonarCloud Scan / SonarCloud (push) Waiting to run

This commit is contained in:
ssongliu 2025-04-08 22:33:54 +08:00 committed by GitHub
parent f136d97941
commit 74eb2c8dd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 34 additions and 10 deletions

View file

@ -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

View file

@ -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 {

View file

@ -49,8 +49,8 @@ export const SaveFileContent = (params: File.FileEdit) => {
return http.post<File.File>('files/save', params);
};
export const CheckFile = (path: string) => {
return http.post<boolean>('files/check', { path: path });
export const CheckFile = (path: string, withInit: boolean) => {
return http.post<boolean>('files/check', { path: path, withInit: withInit });
};
export const BatchCheckFiles = (paths: string[]) => {

View file

@ -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;

View file

@ -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',

View file

@ -1363,6 +1363,7 @@ const message = {
existFileHelper: 'アップロードしたファイルに同じ名前のファイルが含まれています上書きしますか',
existFileSize: 'ファイルサイズ新しい -> 古い',
existFileDirHelper: '選択したファイル/フォルダーには同じ名前のものが既に存在します慎重に操作してください',
noSuchFile: 'ファイルまたはディレクトリが見つかりませんでした確認して再試行してください',
},
ssh: {
setting: '設定',

View file

@ -1349,6 +1349,7 @@ const message = {
existFileHelper: '업로드한 파일에 동일한 이름의 파일이 포함되어 있습니다. 덮어쓰시겠습니까?',
existFileSize: '파일 크기 (새로운 -> 오래된)',
existFileDirHelper: '선택한 파일/폴더에 동일한 이름이 이미 존재합니다. 신중하게 작업하세요!',
noSuchFile: '파일 또는 디렉터리를 찾을 없습니다. 확인 다시 시도하세요.',
},
ssh: {
setting: '설정',

View file

@ -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',

View file

@ -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',

View file

@ -1395,6 +1395,7 @@ const message = {
existFileHelper: 'Загруженный файл содержит файл с таким же именем. Заменить его?',
existFileSize: 'Размер файла (новый -> старый)',
existFileDirHelper: 'Выбранный файл/папка имеет дублирующееся имя. Пожалуйста, действуйте осторожно!',
noSuchFile: 'Файл или каталог не найдены. Пожалуйста, проверьте и повторите попытку.',
},
ssh: {
setting: 'настройка',

View file

@ -1319,6 +1319,7 @@ const message = {
existFileHelper: '上傳的檔案存在同名檔案是否覆蓋',
existFileSize: '文件大小->',
existFileDirHelper: '選擇的檔案/資料夾存在同名請謹慎操作',
noSuchFile: '找不到該檔案或目錄請檢查後重試',
},
ssh: {
setting: '設定',

View file

@ -1321,6 +1321,7 @@ const message = {
existFileHelper: '上传的文件存在同名文件是否覆盖',
existFileSize: '文件大小 ( -> )',
existFileDirHelper: '选择的文件/文件夹存在同名请谨慎操作',
noSuchFile: '未能找到该文件或目录请检查后重试',
},
ssh: {
setting: '配置',

View file

@ -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;

View file

@ -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) => {