diff --git a/drivers/123/types.go b/drivers/123/types.go index 06456dce..1986c7f9 100644 --- a/drivers/123/types.go +++ b/drivers/123/types.go @@ -5,6 +5,7 @@ import ( "time" "github.com/alist-org/alist/v3/internal/model" + "github.com/alist-org/alist/v3/pkg/utils" ) //type BaseResp struct { @@ -39,7 +40,7 @@ func (f File) GetSize() int64 { } func (f File) GetName() string { - return f.FileName + return utils.MappingName(f.FileName) } func (f File) ModTime() time.Time { diff --git a/drivers/189pc/types.go b/drivers/189pc/types.go index 0a6d4f9f..a3c1a4ed 100644 --- a/drivers/189pc/types.go +++ b/drivers/189pc/types.go @@ -6,6 +6,8 @@ import ( "sort" "strings" "time" + + "github.com/alist-org/alist/v3/pkg/utils" ) // 居然有四种返回方式 @@ -134,7 +136,7 @@ type Cloud189File struct { } func (c *Cloud189File) GetSize() int64 { return c.Size } -func (c *Cloud189File) GetName() string { return c.Name } +func (c *Cloud189File) GetName() string { return utils.MappingName(c.Name) } func (c *Cloud189File) ModTime() time.Time { if c.parseTime == nil { c.parseTime = MustParseTime(c.LastOpTime) @@ -166,7 +168,7 @@ type Cloud189Folder struct { } func (c *Cloud189Folder) GetSize() int64 { return 0 } -func (c *Cloud189Folder) GetName() string { return c.Name } +func (c *Cloud189Folder) GetName() string { return utils.MappingName(c.Name) } func (c *Cloud189Folder) ModTime() time.Time { if c.parseTime == nil { c.parseTime = MustParseTime(c.LastOpTime) diff --git a/drivers/baidu_photo/types.go b/drivers/baidu_photo/types.go index 6dd03528..c20318e6 100644 --- a/drivers/baidu_photo/types.go +++ b/drivers/baidu_photo/types.go @@ -3,6 +3,8 @@ package baiduphoto import ( "fmt" "time" + + "github.com/alist-org/alist/v3/pkg/utils" ) type TokenErrResp struct { @@ -100,7 +102,7 @@ type ( ) func (a *Album) GetSize() int64 { return 0 } -func (a *Album) GetName() string { return fmt.Sprint(a.Title) } +func (a *Album) GetName() string { return utils.MappingName(a.Title) } func (a *Album) ModTime() time.Time { if a.parseTime == nil { a.parseTime = toTime(a.Mtime) diff --git a/drivers/thunder/types.go b/drivers/thunder/types.go index 0c60dc56..03a5b365 100644 --- a/drivers/thunder/types.go +++ b/drivers/thunder/types.go @@ -4,6 +4,8 @@ import ( "fmt" "strconv" "time" + + "github.com/alist-org/alist/v3/pkg/utils" ) type ErrResp struct { @@ -147,7 +149,7 @@ type Files struct { } func (c *Files) GetSize() int64 { size, _ := strconv.ParseInt(c.Size, 10, 64); return size } -func (c *Files) GetName() string { return c.Name } +func (c *Files) GetName() string { return utils.MappingName(c.Name) } func (c *Files) ModTime() time.Time { return c.ModifiedTime } func (c *Files) IsDir() bool { return c.Kind == FOLDER } func (c *Files) GetID() string { return c.ID } diff --git a/internal/model/object.go b/internal/model/object.go index 542485d4..8b0513a1 100644 --- a/internal/model/object.go +++ b/internal/model/object.go @@ -1,6 +1,10 @@ package model -import "time" +import ( + "time" + + "github.com/alist-org/alist/v3/pkg/utils" +) type Object struct { ID string @@ -12,7 +16,7 @@ type Object struct { } func (o *Object) GetName() string { - return o.Name + return utils.MappingName(o.Name) } func (o *Object) GetSize() int64 { diff --git a/internal/op/fs.go b/internal/op/fs.go index 0da4e1be..47fe558a 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -8,7 +8,6 @@ import ( "time" "github.com/Xhofe/go-cache" - "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" @@ -129,7 +128,7 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er } for _, f := range files { // TODO maybe copy obj here - if utils.MappingName(f.GetName(), conf.FilenameCharMap) == name { + if f.GetName() == name { // use path as id, why don't set id in List function? // because files maybe cache, set id here can reduce memory usage if f.GetPath() == "" { diff --git a/internal/search/search.go b/internal/search/search.go index 37148577..6f522967 100644 --- a/internal/search/search.go +++ b/internal/search/search.go @@ -9,7 +9,6 @@ import ( "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/search/searcher" - "github.com/alist-org/alist/v3/pkg/utils" log "github.com/sirupsen/logrus" ) @@ -54,7 +53,7 @@ func Index(ctx context.Context, parent string, obj model.Obj) error { } return instance.Index(ctx, model.SearchNode{ Parent: parent, - Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap), + Name: obj.GetName(), IsDir: obj.IsDir(), Size: obj.GetSize(), }) diff --git a/pkg/utils/str.go b/pkg/utils/str.go index f7ffb2fc..9b2d71d8 100644 --- a/pkg/utils/str.go +++ b/pkg/utils/str.go @@ -1,9 +1,13 @@ package utils -import "strings" +import ( + "strings" -func MappingName(name string, m map[string]string) string { - for k, v := range m { + "github.com/alist-org/alist/v3/internal/conf" +) + +func MappingName(name string) string { + for k, v := range conf.FilenameCharMap { name = strings.ReplaceAll(name, k, v) } return name diff --git a/server/handles/fsread.go b/server/handles/fsread.go index b13b8402..40ef2927 100644 --- a/server/handles/fsread.go +++ b/server/handles/fsread.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/fs" @@ -140,7 +139,7 @@ func filterDirs(objs []model.Obj) []DirResp { for _, obj := range objs { if obj.IsDir() { dirs = append(dirs, DirResp{ - Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap), + Name: obj.GetName(), Modified: obj.ModTime(), }) } @@ -187,7 +186,7 @@ func toObjsResp(objs []model.Obj, parent string, encrypt bool) []ObjResp { thumb = t.Thumb() } resp = append(resp, ObjResp{ - Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap), + Name: obj.GetName(), Size: obj.GetSize(), IsDir: obj.IsDir(), Modified: obj.ModTime(), @@ -285,7 +284,7 @@ func FsGet(c *gin.Context) { parentMeta, _ := db.GetNearestMeta(parentPath) common.SuccessResp(c, FsGetResp{ ObjResp: ObjResp{ - Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap), + Name: obj.GetName(), Size: obj.GetSize(), IsDir: obj.IsDir(), Modified: obj.ModTime(), diff --git a/server/webdav/file.go b/server/webdav/file.go index d3d8e319..4840f126 100644 --- a/server/webdav/file.go +++ b/server/webdav/file.go @@ -10,11 +10,9 @@ import ( "path" "path/filepath" - "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/fs" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/pkg/utils" ) // slashClean is equivalent to but slightly more efficient than @@ -101,7 +99,7 @@ func walkFS(ctx context.Context, depth int, name string, info model.Obj, walkFn } for _, fileInfo := range objs { - filename := path.Join(name, utils.MappingName(fileInfo.GetName(), conf.FilenameCharMap)) + filename := path.Join(name, fileInfo.GetName()) if err != nil { if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir { return err diff --git a/server/webdav/prop.go b/server/webdav/prop.go index fa7a15bc..73f92a2f 100644 --- a/server/webdav/prop.go +++ b/server/webdav/prop.go @@ -15,9 +15,7 @@ import ( "path" "strconv" - "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/pkg/utils" ) // Proppatch describes a property update instruction as defined in RFC 4918. @@ -199,7 +197,7 @@ func props(ctx context.Context, ls LockSystem, fi model.Obj, pnames []xml.Name) } // Otherwise, it must either be a live property or we don't know it. if prop := liveProps[pn]; prop.findFn != nil && (prop.dir || !isDir) { - innerXML, err := prop.findFn(ctx, ls, utils.MappingName(fi.GetName(), conf.FilenameCharMap), fi) + innerXML, err := prop.findFn(ctx, ls, fi.GetName(), fi) if err != nil { return nil, err } @@ -375,7 +373,7 @@ func findDisplayName(ctx context.Context, ls LockSystem, name string, fi model.O // Hide the real name of a possibly prefixed root directory. return "", nil } - return escapeXML(utils.MappingName(fi.GetName(), conf.FilenameCharMap)), nil + return escapeXML(fi.GetName()), nil } func findContentLength(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {