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

@ -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) {