mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-14 05:39:08 +02:00
- Rename `filepath` local var to `dest` in LocalStorage.Upload to avoid shadowing the path/filepath package import - Remove unused detectContentType and overrideContentType functions from util.go (no longer needed after ServeFile switched to http.ServeFile)
31 lines
872 B
Go
31 lines
872 B
Go
package storage
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// sanitizeFilename removes characters that could cause header injection in Content-Disposition.
|
|
func sanitizeFilename(name string) string {
|
|
var b strings.Builder
|
|
b.Grow(len(name))
|
|
for _, r := range name {
|
|
// Strip control chars, newlines, null bytes, quotes, semicolons, backslashes
|
|
if r < 0x20 || r == 0x7f || r == '"' || r == ';' || r == '\\' || r == '\x00' {
|
|
b.WriteRune('_')
|
|
} else {
|
|
b.WriteRune(r)
|
|
}
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// isInlineContentType returns true for media types that browsers should
|
|
// display inline (images, video, audio, PDF). Everything else triggers a
|
|
// download via Content-Disposition: attachment.
|
|
func isInlineContentType(ct string) bool {
|
|
return strings.HasPrefix(ct, "image/") ||
|
|
strings.HasPrefix(ct, "video/") ||
|
|
strings.HasPrefix(ct, "audio/") ||
|
|
ct == "application/pdf"
|
|
}
|