From 51971feb87e6fd57a0a8eb40279ef5b3d5c880e2 Mon Sep 17 00:00:00 2001 From: Seednode Date: Mon, 11 Sep 2023 12:59:40 -0500 Subject: [PATCH] Rearranged source files for consistency --- cmd/errors.go | 6 ++++++ cmd/files.go | 4 ---- cmd/root.go | 5 ----- cmd/web.go | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/errors.go b/cmd/errors.go index c1faa30..3d1d77d 100644 --- a/cmd/errors.go +++ b/cmd/errors.go @@ -5,6 +5,7 @@ Copyright © 2023 Seednode package cmd import ( + "errors" "fmt" "io" "net/http" @@ -14,6 +15,11 @@ import ( "github.com/yosssi/gohtml" ) +var ( + ErrIncorrectRefreshInterval = errors.New("refresh interval must be a duration string >= 500ms") + ErrNoMediaFound = errors.New("no supported media formats found which match all criteria") +) + func newErrorPage(title, body string) string { var htmlBody strings.Builder diff --git a/cmd/files.go b/cmd/files.go index 4291eae..3278497 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -35,10 +35,6 @@ type Concurrency struct { fileScans chan int } -var ( - ErrNoMediaFound = errors.New("no supported media formats found which match all criteria") -) - type Files struct { mutex sync.RWMutex list map[string][]string diff --git a/cmd/root.go b/cmd/root.go index 5022380..0812fa7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,17 +5,12 @@ Copyright © 2023 Seednode package cmd import ( - "errors" "log" "time" "github.com/spf13/cobra" ) -var ( - ErrIncorrectRefreshInterval = errors.New("refresh interval must be a duration string >= 500ms") -) - const ( Version string = "0.65.0" ) diff --git a/cmd/web.go b/cmd/web.go index 6e443b3..5c78a31 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -214,13 +214,13 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat sortOrder := SortOrder(r) - path := strings.TrimPrefix(r.URL.Path, MediaPrefix) + filePath := strings.TrimPrefix(r.URL.Path, MediaPrefix) if runtime.GOOS == "windows" { - path = strings.TrimPrefix(path, "/") + filePath = strings.TrimPrefix(filePath, "/") } - exists, err := fileExists(path) + exists, err := fileExists(filePath) if err != nil { fmt.Println(err) @@ -229,12 +229,12 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat return } if !exists { - notFound(w, r, path) + notFound(w, r, filePath) return } - registered, fileType, mime, err := formats.FileType(path, registeredFormats) + registered, fileType, mimeType, err := formats.FileType(filePath, registeredFormats) if err != nil { fmt.Println(err) @@ -244,14 +244,14 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat } if !registered { - notFound(w, r, path) + notFound(w, r, filePath) return } - fileUri := generateFileUri(path) + fileUri := generateFileUri(filePath) - fileName := filepath.Base(path) + fileName := filepath.Base(filePath) w.Header().Add("Content-Type", "text/html") @@ -266,14 +266,14 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat htmlBody.WriteString(`a{display:block;height:100%;width:100%;text-decoration:none;}`) htmlBody.WriteString(`img{margin:auto;display:block;max-width:97%;max-height:97%;object-fit:scale-down;`) htmlBody.WriteString(`position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);}`) - htmlBody.WriteString((fileType.Title(queryParams, fileUri, path, fileName, mime))) + htmlBody.WriteString((fileType.Title(queryParams, fileUri, filePath, fileName, mimeType))) htmlBody.WriteString(``) if refreshInterval != "0ms" { htmlBody.WriteString(fmt.Sprintf("", queryParams, refreshTimer)) } - htmlBody.WriteString((fileType.Body(queryParams, fileUri, path, fileName, mime))) + htmlBody.WriteString((fileType.Body(queryParams, fileUri, filePath, fileName, mimeType))) htmlBody.WriteString(``) _, err = io.WriteString(w, gohtml.Format(htmlBody.String()))