removed utils package
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package utils
|
||||
|
||||
const (
|
||||
TOKEN_COOKIE_NAME = "jwt-yt-dlp-webui"
|
||||
)
|
||||
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user