diff --git a/internal/web/ui.go b/internal/web/ui.go index 823172d..3d5fe95 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -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]) +}