2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 13:47:15 +08:00

feat: 编码URL,解决一些极端问题

This commit is contained in:
2025-09-18 01:49:48 +08:00
parent 5632a5aa1d
commit 6916c02752
7 changed files with 9 additions and 47 deletions

View File

@@ -480,42 +480,6 @@ func (s *FileService) formatDir(base string, entries []stdos.DirEntry) []any {
return paths
}
// formatInfo 格式化文件信息
func (s *FileService) formatInfo(infos map[string]stdos.FileInfo) []map[string]any {
var paths []map[string]any
for path, info := range infos {
stat := info.Sys().(*syscall.Stat_t)
paths = append(paths, map[string]any{
"name": info.Name(),
"full": path,
"size": tools.FormatBytes(float64(info.Size())),
"mode_str": info.Mode().String(),
"mode": fmt.Sprintf("%04o", info.Mode().Perm()),
"owner": os.GetUser(stat.Uid),
"group": os.GetGroup(stat.Gid),
"uid": stat.Uid,
"gid": stat.Gid,
"hidden": io.IsHidden(info.Name()),
"symlink": io.IsSymlink(info.Mode()),
"link": io.GetSymlink(path),
"dir": info.IsDir(),
"modify": info.ModTime().Format(time.DateTime),
})
}
slices.SortFunc(paths, func(a, b map[string]any) int {
if cast.ToBool(a["dir"]) && !cast.ToBool(b["dir"]) {
return -1
}
if !cast.ToBool(a["dir"]) && cast.ToBool(b["dir"]) {
return 1
}
return strings.Compare(strings.ToLower(cast.ToString(a["name"])), strings.ToLower(cast.ToString(b["name"])))
})
return paths
}
// setPermission 设置权限
func (s *FileService) setPermission(path string, mode stdos.FileMode, owner, group string) {
_ = io.Chmod(path, mode)

View File

@@ -49,7 +49,7 @@ func SearchX(path, keyword string, sub bool) ([]os.DirEntry, error) {
if line == "" || line == path {
continue
}
entry, err := newDirEntryFromPath(line)
entry, err := newSearchEntryFromPath(line)
if err != nil {
continue // 直接跳过,不返回错误,不然很烦人的
}
@@ -65,9 +65,9 @@ type SearchEntry struct {
info os.FileInfo
}
// newDirEntryFromPath 根据文件路径创建 SearchEntry
func newDirEntryFromPath(path string) (*SearchEntry, error) {
info, err := os.Stat(path)
// newSearchEntryFromPath 根据文件路径创建 SearchEntry
func newSearchEntryFromPath(path string) (*SearchEntry, error) {
info, err := os.Lstat(path) // 不跟随符号链接
if err != nil {
return nil, err
}

View File

@@ -30,9 +30,6 @@ export default {
http.Post('/file/compress', { dir, paths, file }),
// 解压文件
unCompress: (file: string, path: string): any => http.Post('/file/un_compress', { file, path }),
// 搜索文件
search: (path: string, keyword: string, sub: boolean, page: number, limit: number): any =>
http.Get('/file/search', { params: { path, keyword, sub, page, limit } }),
// 获取文件列表
list: (
path: string,

View File

@@ -21,7 +21,7 @@ const disabled = ref(false) // 在出现错误的情况下禁用保存
const content = ref('')
const get = () => {
useRequest(file.content(props.path))
useRequest(file.content(encodeURIComponent(props.path)))
.onSuccess(({ data }) => {
content.value = decodeBase64(data.content)
window.$message.success($gettext('Retrieved successfully'))

View File

@@ -391,7 +391,8 @@ const rowProps = (row: any) => {
}
const { loading, data, page, total, pageSize, pageCount, refresh } = usePagination(
(page, pageSize) => file.list(path.value, keyword.value, sub.value, sort.value, page, pageSize),
(page, pageSize) =>
file.list(encodeURIComponent(path.value), keyword.value, sub.value, sort.value, page, pageSize),
{
initialData: { total: 0, list: [] },
initialPageSize: 100,

View File

@@ -16,7 +16,7 @@ watch(
() => path.value,
() => {
content.value = ''
useRequest(file.content(path.value)).onSuccess(({ data }) => {
useRequest(file.content(encodeURIComponent(path.value))).onSuccess(({ data }) => {
mime.value = data.mime
content.value = data.content
})

View File

@@ -180,7 +180,7 @@ const handleStatusChange = (row: any) => {
const handleEdit = (row: any) => {
useRequest(cron.get(row.id)).onSuccess(({ data }) => {
useRequest(file.content(data.shell)).onSuccess(({ data }) => {
useRequest(file.content(encodeURIComponent(data.shell))).onSuccess(({ data }) => {
editTask.value.id = row.id
editTask.value.name = row.name
editTask.value.time = row.time