feat(backend): user + library admin API, atomic sanitized upload
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package bookfile
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func FormatFromExt(name string) string {
|
||||
switch strings.ToLower(filepath.Ext(name)) {
|
||||
case ".cbz", ".zip":
|
||||
return "cbz"
|
||||
case ".pdf":
|
||||
return "pdf"
|
||||
case ".epub":
|
||||
return "epub"
|
||||
case ".txt":
|
||||
return "txt"
|
||||
case ".md":
|
||||
return "md"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func SafeName(s string) string {
|
||||
s = strings.Map(func(r rune) rune {
|
||||
if unicode.IsControl(r) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, s)
|
||||
s = strings.ReplaceAll(s, "\\", "/")
|
||||
s = filepath.Base(filepath.ToSlash(s))
|
||||
if s == "." || s == "/" {
|
||||
return ""
|
||||
}
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) > 200 {
|
||||
s = strings.TrimSpace(s[:200])
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user