feat: custom filename char mapping

fixes #2447 #2446 #2440 #2409 #2006 #1979 #1507 #324 #691 #518 #430
This commit is contained in:
Noah Hsu
2022-11-22 15:54:18 +08:00
parent 25fd343069
commit c09800790b
10 changed files with 43 additions and 18 deletions

View File

@ -140,7 +140,7 @@ func filterDirs(objs []model.Obj) []DirResp {
for _, obj := range objs {
if obj.IsDir() {
dirs = append(dirs, DirResp{
Name: obj.GetName(),
Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap),
Modified: obj.ModTime(),
})
}
@ -208,7 +208,7 @@ func toObjResp(objs []model.Obj, parent string, encrypt bool) []ObjResp {
tp = utils.GetFileType(obj.GetName())
}
resp = append(resp, ObjResp{
Name: obj.GetName(),
Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap),
Size: obj.GetSize(),
IsDir: obj.IsDir(),
Modified: obj.ModTime(),
@ -306,7 +306,7 @@ func FsGet(c *gin.Context) {
parentMeta, _ := db.GetNearestMeta(parentPath)
common.SuccessResp(c, FsGetResp{
ObjResp: ObjResp{
Name: obj.GetName(),
Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap),
Size: obj.GetSize(),
IsDir: obj.IsDir(),
Modified: obj.ModTime(),

View File

@ -10,9 +10,11 @@ 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
@ -99,7 +101,7 @@ func walkFS(ctx context.Context, depth int, name string, info model.Obj, walkFn
}
for _, fileInfo := range objs {
filename := path.Join(name, fileInfo.GetName())
filename := path.Join(name, utils.MappingName(fileInfo.GetName(), conf.FilenameCharMap))
if err != nil {
if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir {
return err

View File

@ -15,7 +15,9 @@ 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.
@ -197,7 +199,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, fi.GetName(), fi)
innerXML, err := prop.findFn(ctx, ls, utils.MappingName(fi.GetName(), conf.FilenameCharMap), fi)
if err != nil {
return nil, err
}
@ -373,7 +375,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(fi.GetName()), nil
return escapeXML(utils.MappingName(fi.GetName(), conf.FilenameCharMap)), nil
}
func findContentLength(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {