Rearranged source files for consistency
This commit is contained in:
parent
86184f26bf
commit
51971feb87
|
@ -5,6 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,6 +15,11 @@ import (
|
||||||
"github.com/yosssi/gohtml"
|
"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 {
|
func newErrorPage(title, body string) string {
|
||||||
var htmlBody strings.Builder
|
var htmlBody strings.Builder
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,6 @@ type Concurrency struct {
|
||||||
fileScans chan int
|
fileScans chan int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Files struct {
|
type Files struct {
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
list map[string][]string
|
list map[string][]string
|
||||||
|
|
|
@ -5,17 +5,12 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrIncorrectRefreshInterval = errors.New("refresh interval must be a duration string >= 500ms")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version string = "0.65.0"
|
Version string = "0.65.0"
|
||||||
)
|
)
|
||||||
|
|
20
cmd/web.go
20
cmd/web.go
|
@ -214,13 +214,13 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat
|
||||||
|
|
||||||
sortOrder := SortOrder(r)
|
sortOrder := SortOrder(r)
|
||||||
|
|
||||||
path := strings.TrimPrefix(r.URL.Path, MediaPrefix)
|
filePath := strings.TrimPrefix(r.URL.Path, MediaPrefix)
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
path = strings.TrimPrefix(path, "/")
|
filePath = strings.TrimPrefix(filePath, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
exists, err := fileExists(path)
|
exists, err := fileExists(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
||||||
|
@ -229,12 +229,12 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
notFound(w, r, path)
|
notFound(w, r, filePath)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registered, fileType, mime, err := formats.FileType(path, registeredFormats)
|
registered, fileType, mimeType, err := formats.FileType(filePath, registeredFormats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
||||||
|
@ -244,14 +244,14 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index, registeredFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
if !registered {
|
if !registered {
|
||||||
notFound(w, r, path)
|
notFound(w, r, filePath)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fileUri := generateFileUri(path)
|
fileUri := generateFileUri(filePath)
|
||||||
|
|
||||||
fileName := filepath.Base(path)
|
fileName := filepath.Base(filePath)
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "text/html")
|
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(`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(`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(`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>`)
|
htmlBody.WriteString(`</head><body>`)
|
||||||
if refreshInterval != "0ms" {
|
if refreshInterval != "0ms" {
|
||||||
htmlBody.WriteString(fmt.Sprintf("<script>window.onload = function(){setInterval(function(){window.location.href = '/%s';}, %d);};</script>",
|
htmlBody.WriteString(fmt.Sprintf("<script>window.onload = function(){setInterval(function(){window.location.href = '/%s';}, %d);};</script>",
|
||||||
queryParams,
|
queryParams,
|
||||||
refreshTimer))
|
refreshTimer))
|
||||||
}
|
}
|
||||||
htmlBody.WriteString((fileType.Body(queryParams, fileUri, path, fileName, mime)))
|
htmlBody.WriteString((fileType.Body(queryParams, fileUri, filePath, fileName, mimeType)))
|
||||||
htmlBody.WriteString(`</body></html>`)
|
htmlBody.WriteString(`</body></html>`)
|
||||||
|
|
||||||
_, err = io.WriteString(w, gohtml.Format(htmlBody.String()))
|
_, err = io.WriteString(w, gohtml.Format(htmlBody.String()))
|
||||||
|
|
Loading…
Reference in New Issue