Rearranged source files for consistency

This commit is contained in:
Seednode 2023-09-11 12:59:40 -05:00
parent 86184f26bf
commit 51971feb87
4 changed files with 16 additions and 19 deletions

View File

@ -5,6 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
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

View File

@ -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

View File

@ -5,17 +5,12 @@ Copyright © 2023 Seednode <seednode@seedno.de>
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"
)

View File

@ -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%);}</style>`)
htmlBody.WriteString((fileType.Title(queryParams, fileUri, path, fileName, mime)))
htmlBody.WriteString((fileType.Title(queryParams, fileUri, filePath, fileName, mimeType)))
htmlBody.WriteString(`</head><body>`)
if refreshInterval != "0ms" {
htmlBody.WriteString(fmt.Sprintf("<script>window.onload = function(){setInterval(function(){window.location.href = '/%s';}, %d);};</script>",
queryParams,
refreshTimer))
}
htmlBody.WriteString((fileType.Body(queryParams, fileUri, path, fileName, mime)))
htmlBody.WriteString((fileType.Body(queryParams, fileUri, filePath, fileName, mimeType)))
htmlBody.WriteString(`</body></html>`)
_, err = io.WriteString(w, gohtml.Format(htmlBody.String()))