diff --git a/server/handlers/archive.go b/server/handlers/archive.go index b49e515..765e900 100644 --- a/server/handlers/archive.go +++ b/server/handlers/archive.go @@ -6,10 +6,12 @@ import ( "encoding/base64" "encoding/json" "io" + "io/fs" "net/http" "net/url" "os" "path/filepath" + "regexp" "slices" "sort" "strings" @@ -18,7 +20,6 @@ import ( "github.com/go-chi/chi/v5" "github.com/marcopeocchi/yt-dlp-web-ui/server/config" "github.com/marcopeocchi/yt-dlp-web-ui/server/internal" - "github.com/marcopeocchi/yt-dlp-web-ui/server/utils" ) /* @@ -26,6 +27,20 @@ import ( a entirely self-contained package */ +var ( + videoRe = regexp.MustCompile(`(?i)/\.mov|\.mp4|\.webm|\.mvk|/gmi`) +) + +func isVideo(d fs.DirEntry) bool { + return videoRe.MatchString(d.Name()) +} + +func isValidEntry(d fs.DirEntry) bool { + return !strings.HasPrefix(d.Name(), ".") && + !strings.HasSuffix(d.Name(), ".part") && + !strings.HasSuffix(d.Name(), ".ytdl") +} + type DirectoryEntry struct { Name string `json:"name"` Path string `json:"path"` @@ -44,7 +59,7 @@ func walkDir(root string) (*[]DirectoryEntry, error) { var files []DirectoryEntry for _, d := range dirs { - if !utils.IsValidEntry(d) { + if !isValidEntry(d) { continue } @@ -59,7 +74,7 @@ func walkDir(root string) (*[]DirectoryEntry, error) { Path: path, Name: d.Name(), Size: info.Size(), - IsVideo: utils.IsVideo(d), + IsVideo: isVideo(d), IsDirectory: d.IsDir(), ModTime: info.ModTime(), }) diff --git a/server/handlers/login.go b/server/handlers/login.go index 750e858..ffb2ee5 100644 --- a/server/handlers/login.go +++ b/server/handlers/login.go @@ -8,9 +8,10 @@ import ( "github.com/golang-jwt/jwt/v5" "github.com/marcopeocchi/yt-dlp-web-ui/server/config" - "github.com/marcopeocchi/yt-dlp-web-ui/server/utils" ) +const TOKEN_COOKIE_NAME = "jwt-yt-dlp-webui" + type LoginRequest struct { Username string `json:"username"` Password string `json:"password"` @@ -55,7 +56,7 @@ func Login(w http.ResponseWriter, r *http.Request) { func Logout(w http.ResponseWriter, r *http.Request) { cookie := &http.Cookie{ - Name: utils.TOKEN_COOKIE_NAME, + Name: TOKEN_COOKIE_NAME, HttpOnly: true, Secure: false, Expires: time.Now(), diff --git a/server/internal/common.go b/server/internal/common_types.go similarity index 100% rename from server/internal/common.go rename to server/internal/common_types.go diff --git a/server/utils/cookie.go b/server/utils/cookie.go deleted file mode 100644 index 31f7853..0000000 --- a/server/utils/cookie.go +++ /dev/null @@ -1,5 +0,0 @@ -package utils - -const ( - TOKEN_COOKIE_NAME = "jwt-yt-dlp-webui" -) diff --git a/server/utils/file.go b/server/utils/file.go deleted file mode 100644 index 26e67c6..0000000 --- a/server/utils/file.go +++ /dev/null @@ -1,21 +0,0 @@ -package utils - -import ( - "io/fs" - "regexp" - "strings" -) - -var ( - videoRe = regexp.MustCompile(`(?i)/\.mov|\.mp4|\.webm|\.mvk|/gmi`) -) - -func IsVideo(d fs.DirEntry) bool { - return videoRe.MatchString(d.Name()) -} - -func IsValidEntry(d fs.DirEntry) bool { - return !strings.HasPrefix(d.Name(), ".") && - !strings.HasSuffix(d.Name(), ".part") && - !strings.HasSuffix(d.Name(), ".ytdl") -}