fix: handle webkitdirectory paths with variable depth

This commit is contained in:
tian 2026-05-08 10:15:12 +08:00
parent 1b018d1f5d
commit ca6edafbce

View File

@ -4032,13 +4032,13 @@ func (u *UI) actionFaceGalleryImport(w http.ResponseWriter, r *http.Request) {
count := 0
for _, files := range r.MultipartForm.File {
for _, hdr := range files {
// webkitdirectory sends files with relative paths like "person_name/photo.jpg"
parts := strings.SplitN(filepath.ToSlash(hdr.Filename), "/", 2)
// webkitdirectory paths can have varying depth, extract last dir as person name
parts := strings.Split(strings.ReplaceAll(hdr.Filename, "\\", "/"), "/")
if len(parts) < 2 {
continue
}
personName := strings.TrimSpace(parts[0])
fileName := filepath.Base(parts[1])
personName := strings.TrimSpace(parts[len(parts)-2])
fileName := filepath.Base(parts[len(parts)-1])
if personName == "" || fileName == "" {
continue
}