settings section

This commit is contained in:
2026-07-04 18:34:30 +05:00
parent bbe5d219ad
commit 0c717101da
2867 changed files with 1118596 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
package auth
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
func imageStorageDir(publicRoot string) string {
return filepath.Join(publicRoot, "images")
}
func imagePublicPath(filename string) string {
return "/images/" + filename
}
func resolveImagePath(publicRoot, filename string) (string, error) {
if filename == "" || strings.Contains(filename, "..") || strings.ContainsAny(filename, `/\`) {
return "", fmt.Errorf("invalid file name")
}
base := filepath.Clean(imageStorageDir(publicRoot))
path := filepath.Clean(filepath.Join(base, filepath.Base(filename)))
if !strings.HasPrefix(path, base+string(os.PathSeparator)) && path != base {
return "", fmt.Errorf("invalid file path")
}
return path, nil
}
func newUploadFilename(original string) string {
return fmt.Sprintf("%d%s", time.Now().UnixNano(), filepath.Ext(original))
}