re-use fileutil.Safe
This commit is contained in:
@@ -7,11 +7,12 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.senan.xyz/gonic/fileutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,7 +70,7 @@ type Playlist struct {
|
||||
}
|
||||
|
||||
func NewPath(userID int, playlistName string) string {
|
||||
playlistName = safeFilename(playlistName)
|
||||
playlistName = fileutil.Safe(playlistName)
|
||||
if playlistName == "" {
|
||||
playlistName = "pl"
|
||||
}
|
||||
@@ -219,13 +220,6 @@ func (s *Store) Delete(relPath string) error {
|
||||
return os.Remove(filepath.Join(s.basePath, relPath))
|
||||
}
|
||||
|
||||
var nonAlphaNum = regexp.MustCompile("[^a-zA-Z0-9_.]+")
|
||||
|
||||
func safeFilename(filename string) string {
|
||||
filename = nonAlphaNum.ReplaceAllString(filename, "")
|
||||
return filename
|
||||
}
|
||||
|
||||
func firstPathEl(path string) string {
|
||||
path = strings.TrimPrefix(path, string(filepath.Separator))
|
||||
parts := strings.Split(path, string(filepath.Separator))
|
||||
|
||||
Reference in New Issue
Block a user