refactor: reusable fullFilename and personNameFromPath helpers

This commit is contained in:
tian 2026-05-08 10:56:25 +08:00
parent f10ec45590
commit 003d50bcc6

View File

@ -6,6 +6,8 @@ import (
"fmt"
"html/template"
"io"
"mime"
"mime/multipart"
"io/fs"
"net/http"
"net/url"
@ -4110,3 +4112,26 @@ func (u *UI) rebuildFaceGallery() {
}
builder.Build()
}
// fullFilename extracts the full relative path from a webkitdirectory file upload,
// bypassing Go 1.20+ sanitization that strips directory components.
func fullFilename(hdr *multipart.FileHeader) string {
cd := hdr.Header.Get("Content-Disposition")
_, params, err := mime.ParseMediaType(cd)
if err == nil {
if name := params["filename"]; name != "" {
return name
}
}
return hdr.Filename
}
// personNameFromPath extracts the person name from a webkitdirectory path like "李清/photo.jpg".
func personNameFromPath(path string) string {
path = strings.ReplaceAll(path, "\\", "/")
parts := strings.Split(path, "/")
if len(parts) < 2 {
return ""
}
return strings.TrimSpace(parts[len(parts)-2])
}