Skip to content

Commit 0b87025

Browse files
authored
feat: 面板目录禁止删除 (#7029)
Refs #7008
1 parent 7d4230e commit 0b87025

File tree

9 files changed

+23
-1
lines changed

9 files changed

+23
-1
lines changed

backend/app/service/file.go

+4
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ func (f *FileService) Create(op request.FileCreate) error {
211211
}
212212

213213
func (f *FileService) Delete(op request.FileDelete) error {
214+
excludeDir := global.CONF.System.DataDir
215+
if strings.Contains(op.Path, ".1panel_clash") || op.Path == excludeDir {
216+
return buserr.New(constant.ErrPathNotDelete)
217+
}
214218
fo := files.NewFileOp()
215219
recycleBinStatus, _ := settingRepo.Get(settingRepo.WithByKey("FileRecycleBin"))
216220
if recycleBinStatus.Value == "disable" {

backend/constant/errs.go

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ var (
100100
ErrFileDownloadDir = "ErrFileDownloadDir"
101101
ErrCmdNotFound = "ErrCmdNotFound"
102102
ErrFavoriteExist = "ErrFavoriteExist"
103+
ErrPathNotDelete = "ErrPathNotDelete"
103104
)
104105

105106
// mysql

backend/i18n/lang/en.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ ErrCmdNotFound: "{{ .name}} command does not exist, please install this command
8181
ErrSourcePathNotFound: "Source directory does not exist"
8282
ErrFavoriteExist: "This path has been collected"
8383
ErrInvalidChar: "Illegal characters are prohibited"
84+
ErrPathNotDelete: "The selected directory cannot be deleted"
85+
8486

8587
#website
8688
ErrDomainIsExist: "Domain is already exist"

backend/i18n/lang/zh-Hant.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ErrFileDownloadDir: "不支持下載文件夾"
8181
ErrCmdNotFound: "{{ .name}} 命令不存在,請先在宿主機安裝此命令"
8282
ErrSourcePathNotFound: "源目錄不存在"
8383
ErrFavoriteExist: "已收藏此路徑"
84+
ErrPathNotDelete: "所選目錄不可删除"
8485

8586
#website
8687
ErrDomainIsExist: "域名已存在"

backend/i18n/lang/zh.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ ErrCmdNotFound: "{{ .name}} 命令不存在,请先在宿主机安装此命令"
8181
ErrSourcePathNotFound: "源目录不存在"
8282
ErrFavoriteExist: "已收藏此路径"
8383
ErrInvalidChar: "禁止使用非法字符"
84+
ErrPathNotDelete: "所选目录不可删除"
85+
8486

8587
#website
8688
ErrDomainIsExist: "域名已存在"

frontend/src/lang/modules/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ const message = {
12981298
noNameFile: 'Untitled File',
12991299
minimap: 'Code Mini Map',
13001300
fileCanNotRead: 'File can not read',
1301+
panelInstallDir: '1Panel installation directory cannot be deleted',
13011302
},
13021303
ssh: {
13031304
autoStart: 'Auto Start',

frontend/src/lang/modules/tw.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ const message = {
12281228
noNameFile: '未命名檔案',
12291229
minimap: '縮略圖',
12301230
fileCanNotRead: '此文件不支持預覽',
1231+
panelInstallDir: '1Panel 安裝目錄不能删除',
12311232
},
12321233
ssh: {
12331234
autoStart: '開機自啟',

frontend/src/lang/modules/zh.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ const message = {
12301230
noNameFile: '未命名文件',
12311231
minimap: '缩略图',
12321232
fileCanNotRead: '此文件不支持预览',
1233+
panelInstallDir: '1Panel 安装目录不能删除',
12331234
},
12341235
ssh: {
12351236
autoStart: '开机自启',

frontend/src/views/host/file-management/delete/index.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { File } from '@/api/interface/file';
6060
import { getIcon } from '@/utils/util';
6161
import { DeleteFile, GetRecycleStatus } from '@/api/modules/files';
6262
import { MsgSuccess, MsgWarning } from '@/utils/message';
63+
import { loadBaseDir } from '@/api/modules/setting';
6364
6465
const open = ref(false);
6566
const files = ref();
@@ -85,13 +86,21 @@ const getStatus = async () => {
8586
} catch (error) {}
8687
};
8788
88-
const onConfirm = () => {
89+
const onConfirm = async () => {
8990
const pros = [];
9091
for (const s of files.value) {
9192
if (s['path'].indexOf('.1panel_clash') > -1) {
9293
MsgWarning(i18n.global.t('file.clashDeleteAlert'));
9394
return;
9495
}
96+
if (s['isDir']) {
97+
const pathRes = await loadBaseDir();
98+
if (s['path'] === pathRes.data) {
99+
MsgWarning(i18n.global.t('file.panelInstallDir'));
100+
return;
101+
}
102+
}
103+
95104
pros.push(DeleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }));
96105
}
97106
loading.value = true;

0 commit comments

Comments
 (0)