From 003d50bcc61dfae6f5e58f23575449192876f848 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 8 May 2026 10:56:25 +0800 Subject: [PATCH] refactor: reusable fullFilename and personNameFromPath helpers --- internal/web/ui.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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]) +}