mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-08 22:46:51 +08:00
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
Some checks are pending
SonarCloud Scan / SonarCloud (push) Waiting to run
This commit is contained in:
parent
f136d97941
commit
74eb2c8dd6
14 changed files with 34 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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[]) => {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1363,6 +1363,7 @@ const message = {
|
|||
existFileHelper: 'アップロードしたファイルに同じ名前のファイルが含まれています。上書きしますか?',
|
||||
existFileSize: 'ファイルサイズ(新しい -> 古い)',
|
||||
existFileDirHelper: '選択したファイル/フォルダーには同じ名前のものが既に存在します。慎重に操作してください!',
|
||||
noSuchFile: 'ファイルまたはディレクトリが見つかりませんでした。確認して再試行してください。',
|
||||
},
|
||||
ssh: {
|
||||
setting: '設定',
|
||||
|
|
|
@ -1349,6 +1349,7 @@ const message = {
|
|||
existFileHelper: '업로드한 파일에 동일한 이름의 파일이 포함되어 있습니다. 덮어쓰시겠습니까?',
|
||||
existFileSize: '파일 크기 (새로운 -> 오래된)',
|
||||
existFileDirHelper: '선택한 파일/폴더에 동일한 이름이 이미 존재합니다. 신중하게 작업하세요!',
|
||||
noSuchFile: '파일 또는 디렉터리를 찾을 수 없습니다. 확인 후 다시 시도하세요.',
|
||||
},
|
||||
ssh: {
|
||||
setting: '설정',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1395,6 +1395,7 @@ const message = {
|
|||
existFileHelper: 'Загруженный файл содержит файл с таким же именем. Заменить его?',
|
||||
existFileSize: 'Размер файла (новый -> старый)',
|
||||
existFileDirHelper: 'Выбранный файл/папка имеет дублирующееся имя. Пожалуйста, действуйте осторожно!',
|
||||
noSuchFile: 'Файл или каталог не найдены. Пожалуйста, проверьте и повторите попытку.',
|
||||
},
|
||||
ssh: {
|
||||
setting: 'настройка',
|
||||
|
|
|
@ -1319,6 +1319,7 @@ const message = {
|
|||
existFileHelper: '上傳的檔案存在同名檔案,是否覆蓋?',
|
||||
existFileSize: '文件大小(新->舊)',
|
||||
existFileDirHelper: '選擇的檔案/資料夾存在同名,請謹慎操作!',
|
||||
noSuchFile: '找不到該檔案或目錄,請檢查後重試。',
|
||||
},
|
||||
ssh: {
|
||||
setting: '設定',
|
||||
|
|
|
@ -1321,6 +1321,7 @@ const message = {
|
|||
existFileHelper: '上传的文件存在同名文件,是否覆盖?',
|
||||
existFileSize: '文件大小 (新 -> 旧)',
|
||||
existFileDirHelper: '选择的文件/文件夹存在同名,请谨慎操作!',
|
||||
noSuchFile: '未能找到该文件或目录,请检查后重试',
|
||||
},
|
||||
ssh: {
|
||||
setting: '配置',
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue