Add looping and preload to audio and video files, add file types listed as supported by MDN

This commit is contained in:
Seednode 2023-09-11 21:22:26 -05:00
parent e614846302
commit 2097a9ab13
6 changed files with 18 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"regexp"
"crypto/rand" "crypto/rand"
"os" "os"
@ -30,6 +31,11 @@ const (
maxFileScans maxConcurrency = 256 maxFileScans maxConcurrency = 256
) )
type Regexes struct {
alphanumeric *regexp.Regexp
filename *regexp.Regexp
}
type Concurrency struct { type Concurrency struct {
directoryScans chan int directoryScans chan int
fileScans chan int fileScans chan int

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
Version string = "0.69.2" Version string = "0.69.3"
) )
var ( var (

View File

@ -37,11 +37,6 @@ const (
Timeout time.Duration = 10 * time.Second Timeout time.Duration = 10 * time.Second
) )
type Regexes struct {
alphanumeric *regexp.Regexp
filename *regexp.Regexp
}
func serveStaticFile(paths []string, stats *ServeStats, index *Index) httprouter.Handle { func serveStaticFile(paths []string, stats *ServeStats, index *Index) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
path := strings.TrimPrefix(r.URL.Path, SourcePrefix) path := strings.TrimPrefix(r.URL.Path, SourcePrefix)

View File

@ -15,7 +15,7 @@ func RegisterAudioFormats() *SupportedFormat {
return fmt.Sprintf(`<title>%s</title>`, fileName) return fmt.Sprintf(`<title>%s</title>`, fileName)
}, },
Body: func(queryParams, fileUri, filePath, fileName, mime string) string { Body: func(queryParams, fileUri, filePath, fileName, mime string) string {
return fmt.Sprintf(`<a href="/%s"><audio controls autoplay><source src="%s" type="%s" alt="Roulette selected: %s">Your browser does not support the audio tag.</audio></a>`, return fmt.Sprintf(`<a href="/%s"><audio controls autoplay loop preload="auto"><source src="%s" type="%s" alt="Roulette selected: %s">Your browser does not support the audio tag.</audio></a>`,
queryParams, queryParams,
fileUri, fileUri,
mime, mime,

View File

@ -51,18 +51,27 @@ func RegisterImageFormats() *SupportedFormat {
fileName) fileName)
}, },
Extensions: []string{ Extensions: []string{
`.apng`,
`.avif`,
`.bmp`, `.bmp`,
`.gif`, `.gif`,
`.jpg`, `.jpg`,
`.jpeg`, `.jpeg`,
`.jfif`,
`.pjp`,
`.pjpeg`,
`.png`, `.png`,
`.svg`,
`.webp`, `.webp`,
}, },
MimeTypes: []string{ MimeTypes: []string{
`image/apng`,
`image/avif`,
`image/bmp`, `image/bmp`,
`image/gif`, `image/gif`,
`image/jpeg`, `image/jpeg`,
`image/png`, `image/png`,
`image/svg+xml`,
`image/webp`, `image/webp`,
}, },
Validate: func(filePath string) bool { Validate: func(filePath string) bool {

View File

@ -15,7 +15,7 @@ func RegisterVideoFormats() *SupportedFormat {
return fmt.Sprintf(`<title>%s</title>`, fileName) return fmt.Sprintf(`<title>%s</title>`, fileName)
}, },
Body: func(queryParams, fileUri, filePath, fileName, mime string) string { Body: func(queryParams, fileUri, filePath, fileName, mime string) string {
return fmt.Sprintf(`<a href="/%s"><video controls autoplay><source src="%s" type="%s" alt="Roulette selected: %s">Your browser does not support the video tag.</video></a>`, return fmt.Sprintf(`<a href="/%s"><video controls autoplay loop preload="auto"><source src="%s" type="%s" alt="Roulette selected: %s">Your browser does not support the video tag.</video></a>`,
queryParams, queryParams,
fileUri, fileUri,
mime, mime,