From 7bcd69dcdf9047de9c2dae968830acfe0e65c21f Mon Sep 17 00:00:00 2001 From: sentriz Date: Tue, 28 Nov 2023 18:18:23 +0000 Subject: [PATCH] re-use fileutil.Safe --- playlist/playlist.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/playlist/playlist.go b/playlist/playlist.go index 618af33..6f9f60e 100644 --- a/playlist/playlist.go +++ b/playlist/playlist.go @@ -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))