Corrected all references to image->media/file

This commit is contained in:
Seednode 2023-09-10 20:29:11 -05:00
parent 928bbb8c53
commit 8fa4a7c652
4 changed files with 28 additions and 28 deletions

View File

@ -1,14 +1,14 @@
## About ## About
Sometimes, you just need a way to randomly display images from your filesystem. Sometimes, you just need a way to randomly display media from your filesystem.
Simply point this tool at one or more directories, and then open the specified port (default `8080`) in your browser. Simply point this tool at one or more directories, and then open the specified port (default `8080`) in your browser.
A new file will be selected if you open `/` directly, or if you click on any displayed images. A new file will be selected if you open `/` directly, or if you click on any displayed files.
Browser history is preserved, so you can always go back to any previously displayed images. Browser history is preserved, so you can always go back to any previously displayed media.
Supported file types and extensions are `bmp`, `gif`, `jp[e]g`, `png`, and `webp`. Supported file types and extensions are `bmp`, `gif`, `jp[e]g`, `png`, `webp`, `mp4`, `ogv`, `webm`.
Feature requests, code criticism, bug reports, general chit-chat, and unrelated angst accepted at `roulette@seedno.de`. Feature requests, code criticism, bug reports, general chit-chat, and unrelated angst accepted at `roulette@seedno.de`.
@ -102,7 +102,7 @@ Enjoy!
## Usage output ## Usage output
``` ```
Serves random images from the specified directories. Serves random media from the specified directories.
Usage: Usage:
roulette <path> [path]... [flags] roulette <path> [path]... [flags]
@ -121,7 +121,7 @@ Flags:
--profile register net/http/pprof handlers --profile register net/http/pprof handlers
-r, --recursive recurse into subdirectories -r, --recursive recurse into subdirectories
--refresh-interval string force refresh interval equal to this duration (minimum 500ms) --refresh-interval string force refresh interval equal to this duration (minimum 500ms)
--russian remove selected images after serving --russian remove selected media after serving
-s, --sort enable sorting -s, --sort enable sorting
--stats expose stats endpoint --stats expose stats endpoint
--stats-file string path to optional persistent stats file --stats-file string path to optional persistent stats file

View File

@ -43,8 +43,8 @@ type Concurrency struct {
} }
var ( var (
ErrNoImagesFound = errors.New("no supported image formats found which match all criteria") ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
Extensions = [8]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".mp4", ".webm"} Extensions = [9]string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".mp4", ".ogv", ".webm"}
) )
type Dimensions struct { type Dimensions struct {
@ -133,7 +133,7 @@ func imageDimensions(path string) (*Dimensions, error) {
} }
func preparePath(path string) string { func preparePath(path string) string {
path = ImagePrefix + path path = MediaPrefix + path
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
path = fmt.Sprintf("/%s", filepath.ToSlash(path)) path = fmt.Sprintf("/%s", filepath.ToSlash(path))
@ -618,7 +618,7 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin
fileCount := len(fileList) fileCount := len(fileList)
if fileCount < 1 { if fileCount < 1 {
return "", ErrNoImagesFound return "", ErrNoMediaFound
} }
r, err := rand.Int(rand.Reader, big.NewInt(int64(fileCount-2))) r, err := rand.Int(rand.Reader, big.NewInt(int64(fileCount-2)))
@ -656,7 +656,7 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin
return filePath, nil return filePath, nil
} }
return "", ErrNoImagesFound return "", ErrNoMediaFound
} }
func normalizePath(path string) (string, error) { func normalizePath(path string) (string, error) {

View File

@ -17,7 +17,7 @@ var (
) )
const ( const (
Version string = "0.61.0" Version string = "0.61.1"
) )
var ( var (

View File

@ -40,7 +40,7 @@ var favicons embed.FS
const ( const (
LogDate string = `2006-01-02T15:04:05.000-07:00` LogDate string = `2006-01-02T15:04:05.000-07:00`
SourcePrefix string = `/source` SourcePrefix string = `/source`
ImagePrefix string = `/view` MediaPrefix string = `/view`
RedirectStatusCode int = http.StatusSeeOther RedirectStatusCode int = http.StatusSeeOther
Timeout time.Duration = 10 * time.Second Timeout time.Duration = 10 * time.Second
@ -213,20 +213,20 @@ type exportedServeStats struct {
Times map[string][]string Times map[string][]string
} }
func (s *ServeStats) incrementCounter(image string, timestamp time.Time, filesize string) { func (s *ServeStats) incrementCounter(file string, timestamp time.Time, filesize string) {
s.mutex.Lock() s.mutex.Lock()
s.count[image]++ s.count[file]++
s.times[image] = append(s.times[image], timestamp.Format(LogDate)) s.times[file] = append(s.times[file], timestamp.Format(LogDate))
_, exists := s.size[image] _, exists := s.size[file]
if !exists { if !exists {
s.size[image] = filesize s.size[file] = filesize
} }
if !contains(s.list, image) { if !contains(s.list, file) {
s.list = append(s.list, image) s.list = append(s.list, file)
} }
s.mutex.Unlock() s.mutex.Unlock()
@ -283,7 +283,7 @@ func (s *ServeStats) toImported(stats *exportedServeStats) {
s.mutex.Unlock() s.mutex.Unlock()
} }
func (s *ServeStats) ListImages(page int) ([]byte, error) { func (s *ServeStats) ListFiles(page int) ([]byte, error) {
stats := s.toExported() stats := s.toExported()
sort.SliceStable(stats.List, func(p, q int) bool { sort.SliceStable(stats.List, func(p, q int) bool {
@ -612,7 +612,7 @@ func serveStats(args []string, stats *ServeStats) httprouter.Handle {
page = -1 page = -1
} }
response, err := stats.ListImages(page) response, err := stats.ListFiles(page)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -686,7 +686,7 @@ func serveDebugHtml(args []string, index *Index, paginate bool) httprouter.Handl
if sorting { if sorting {
shouldSort = "?sort=asc" shouldSort = "?sort=asc"
} }
htmlBody.WriteString(fmt.Sprintf("<tr><td><a href=\"%s%s%s\">%s</a></td></tr>\n", ImagePrefix, v, shouldSort, v)) htmlBody.WriteString(fmt.Sprintf("<tr><td><a href=\"%s%s%s\">%s</a></td></tr>\n", MediaPrefix, v, shouldSort, v))
} }
} }
if pageLength != 0 { if pageLength != 0 {
@ -883,7 +883,7 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle
return return
} }
strippedRefererUri := strings.TrimPrefix(refererUri, ImagePrefix) strippedRefererUri := strings.TrimPrefix(refererUri, MediaPrefix)
filters := &Filters{ filters := &Filters{
includes: splitQueryParams(r.URL.Query().Get("include"), Regexes), includes: splitQueryParams(r.URL.Query().Get("include"), Regexes),
@ -921,7 +921,7 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle
filePath, err = newFile(paths, filters, sortOrder, Regexes, index) filePath, err = newFile(paths, filters, sortOrder, Regexes, index)
switch { switch {
case err != nil && err == ErrNoImagesFound: case err != nil && err == ErrNoMediaFound:
notFound(w, r, filePath) notFound(w, r, filePath)
return return
@ -945,7 +945,7 @@ func serveRoot(paths []string, Regexes *Regexes, index *Index) httprouter.Handle
} }
} }
func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handle { func serveMedia(paths []string, Regexes *Regexes, 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) {
filters := &Filters{ filters := &Filters{
includes: splitQueryParams(r.URL.Query().Get("include"), Regexes), includes: splitQueryParams(r.URL.Query().Get("include"), Regexes),
@ -954,7 +954,7 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
sortOrder := SortOrder(r) sortOrder := SortOrder(r)
filePath := strings.TrimPrefix(r.URL.Path, ImagePrefix) filePath := strings.TrimPrefix(r.URL.Path, MediaPrefix)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
filePath = strings.TrimPrefix(filePath, "/") filePath = strings.TrimPrefix(filePath, "/")
@ -1154,7 +1154,7 @@ func ServePage(args []string) error {
mux.GET("/favicon.ico", serveFavicons()) mux.GET("/favicon.ico", serveFavicons())
mux.GET(ImagePrefix+"/*image", serveImage(paths, regexes, index)) mux.GET(MediaPrefix+"/*media", serveMedia(paths, regexes, index))
mux.GET(SourcePrefix+"/*static", serveStaticFile(paths, stats, index)) mux.GET(SourcePrefix+"/*static", serveStaticFile(paths, stats, index))