Add new --fun flag, add comments to Type interface
This commit is contained in:
parent
9ae0aa60d3
commit
9844f4a2e1
|
@ -116,6 +116,7 @@ Flags:
|
||||||
--fallback serve files as application/octet-stream if no matching format is registered
|
--fallback serve files as application/octet-stream if no matching format is registered
|
||||||
-f, --filter enable filtering
|
-f, --filter enable filtering
|
||||||
--flash enable support for shockwave flash files (via ruffle.rs)
|
--flash enable support for shockwave flash files (via ruffle.rs)
|
||||||
|
--fun adds a bit of excitement to your day
|
||||||
--handlers display registered handlers (for debugging)
|
--handlers display registered handlers (for debugging)
|
||||||
-h, --help help for roulette
|
-h, --help help for roulette
|
||||||
--images enable support for image files
|
--images enable support for image files
|
||||||
|
@ -123,7 +124,7 @@ Flags:
|
||||||
--index-file string path to optional persistent index file
|
--index-file string path to optional persistent index file
|
||||||
-i, --info expose informational endpoints
|
-i, --info expose informational endpoints
|
||||||
--max-file-count int skip directories with file counts above this value (default 2147483647)
|
--max-file-count int skip directories with file counts above this value (default 2147483647)
|
||||||
--min-file-count int skip directories with file counts below this value (default 1)
|
--min-file-count int skip directories with file counts below this value
|
||||||
--page-length int pagination length for info pages
|
--page-length int pagination length for info pages
|
||||||
-p, --port int port to listen on (default 8080)
|
-p, --port int port to listen on (default 8080)
|
||||||
--prefix string root path for http handlers (for reverse proxying) (default "/")
|
--prefix string root path for http handlers (for reverse proxying) (default "/")
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReleaseVersion string = "2.5.1"
|
ReleaseVersion string = "2.6.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -26,6 +26,7 @@ var (
|
||||||
Fallback bool
|
Fallback bool
|
||||||
Filtering bool
|
Filtering bool
|
||||||
Flash bool
|
Flash bool
|
||||||
|
Fun bool
|
||||||
Handlers bool
|
Handlers bool
|
||||||
Images bool
|
Images bool
|
||||||
Index bool
|
Index bool
|
||||||
|
@ -91,6 +92,7 @@ func init() {
|
||||||
rootCmd.Flags().BoolVar(&Fallback, "fallback", false, "serve files as application/octet-stream if no matching format is registered")
|
rootCmd.Flags().BoolVar(&Fallback, "fallback", false, "serve files as application/octet-stream if no matching format is registered")
|
||||||
rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering")
|
rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering")
|
||||||
rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
|
rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
|
||||||
|
rootCmd.Flags().BoolVar(&Fun, "fun", false, "adds a bit of excitement to your day")
|
||||||
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")
|
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")
|
||||||
rootCmd.Flags().BoolVar(&Images, "images", false, "enable support for image files")
|
rootCmd.Flags().BoolVar(&Images, "images", false, "enable support for image files")
|
||||||
rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup")
|
rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup")
|
||||||
|
|
12
cmd/web.go
12
cmd/web.go
|
@ -436,29 +436,29 @@ func ServePage(args []string) error {
|
||||||
formats := make(types.Types)
|
formats := make(types.Types)
|
||||||
|
|
||||||
if Audio || All {
|
if Audio || All {
|
||||||
formats.Add(audio.Format{})
|
formats.Add(audio.Format{Fun: Fun})
|
||||||
}
|
}
|
||||||
|
|
||||||
if Code || All {
|
if Code || All {
|
||||||
formats.Add(code.Format{Theme: CodeTheme})
|
formats.Add(code.Format{Fun: Fun, Theme: CodeTheme})
|
||||||
}
|
}
|
||||||
|
|
||||||
if Flash || All {
|
if Flash || All {
|
||||||
formats.Add(flash.Format{})
|
formats.Add(flash.Format{Fun: Fun})
|
||||||
}
|
}
|
||||||
|
|
||||||
if Text || All {
|
if Text || All {
|
||||||
formats.Add(text.Format{})
|
formats.Add(text.Format{Fun: Fun})
|
||||||
}
|
}
|
||||||
|
|
||||||
if Videos || All {
|
if Videos || All {
|
||||||
formats.Add(video.Format{})
|
formats.Add(video.Format{Fun: Fun})
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable image support if no other flags are passed, to retain backwards compatibility
|
// enable image support if no other flags are passed, to retain backwards compatibility
|
||||||
// to be replaced with rootCmd.MarkFlagsOneRequired on next spf13/cobra update
|
// to be replaced with rootCmd.MarkFlagsOneRequired on next spf13/cobra update
|
||||||
if Images || All || len(formats) == 0 {
|
if Images || All || len(formats) == 0 {
|
||||||
formats.Add(images.Format{})
|
formats.Add(images.Format{Fun: Fun})
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, err := validatePaths(args, formats)
|
paths, err := validatePaths(args, formats)
|
||||||
|
|
|
@ -11,7 +11,9 @@ import (
|
||||||
"seedno.de/seednode/roulette/types"
|
"seedno.de/seednode/roulette/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format struct{}
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
|
}
|
||||||
|
|
||||||
func (t Format) Css() string {
|
func (t Format) Css() string {
|
||||||
var css strings.Builder
|
var css strings.Builder
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format struct {
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
Theme string
|
Theme string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +57,9 @@ func (t Format) Css() string {
|
||||||
|
|
||||||
css.WriteString("html{height:100%;width:100%;}\n")
|
css.WriteString("html{height:100%;width:100%;}\n")
|
||||||
css.WriteString("a{bottom:0;left:0;position:absolute;right:0;top:0;margin:1rem;padding:0;height:99%;width:99%;color:inherit;text-decoration:none;}\n")
|
css.WriteString("a{bottom:0;left:0;position:absolute;right:0;top:0;margin:1rem;padding:0;height:99%;width:99%;color:inherit;text-decoration:none;}\n")
|
||||||
|
if t.Fun {
|
||||||
|
css.WriteString("body{font-family: \"Comic Sans MS\", cursive, \"Brush Script MT\", sans-serif;}\n")
|
||||||
|
}
|
||||||
|
|
||||||
return css.String()
|
return css.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@ import (
|
||||||
"seedno.de/seednode/roulette/types"
|
"seedno.de/seednode/roulette/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format struct{}
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
|
}
|
||||||
|
|
||||||
func (t Format) Css() string {
|
func (t Format) Css() string {
|
||||||
var css strings.Builder
|
var css strings.Builder
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -24,7 +25,9 @@ type dimensions struct {
|
||||||
height int
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Format struct{}
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
|
}
|
||||||
|
|
||||||
func (t Format) Css() string {
|
func (t Format) Css() string {
|
||||||
var css strings.Builder
|
var css strings.Builder
|
||||||
|
@ -32,7 +35,17 @@ func (t Format) Css() string {
|
||||||
css.WriteString(`html,body{margin:0;padding:0;height:100%;}`)
|
css.WriteString(`html,body{margin:0;padding:0;height:100%;}`)
|
||||||
css.WriteString(`a{color:inherit;display:block;height:100%;width:100%;text-decoration:none;}`)
|
css.WriteString(`a{color:inherit;display:block;height:100%;width:100%;text-decoration:none;}`)
|
||||||
css.WriteString(`img{margin:auto;display:block;max-width:97%;max-height:97%;`)
|
css.WriteString(`img{margin:auto;display:block;max-width:97%;max-height:97%;`)
|
||||||
css.WriteString(`object-fit:scale-down;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);}`)
|
css.WriteString(`object-fit:scale-down;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)`)
|
||||||
|
if t.Fun {
|
||||||
|
rotate := rand.Intn(360)
|
||||||
|
|
||||||
|
css.WriteString(fmt.Sprintf(" rotate(%ddeg);", rotate))
|
||||||
|
css.WriteString(fmt.Sprintf("-ms-transform:rotate(%ddeg);", rotate))
|
||||||
|
css.WriteString(fmt.Sprintf("-webkit-transform:rotate(%ddeg);", rotate))
|
||||||
|
css.WriteString(fmt.Sprintf("-moz-transform:rotate(%ddeg);", rotate))
|
||||||
|
css.WriteString(fmt.Sprintf("-o-transform:rotate(%ddeg)", rotate))
|
||||||
|
}
|
||||||
|
css.WriteString(`;}`)
|
||||||
|
|
||||||
return css.String()
|
return css.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ import (
|
||||||
"seedno.de/seednode/roulette/types"
|
"seedno.de/seednode/roulette/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format struct{}
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
|
}
|
||||||
|
|
||||||
func (t Format) Css() string {
|
func (t Format) Css() string {
|
||||||
var css strings.Builder
|
var css strings.Builder
|
||||||
|
|
|
@ -13,12 +13,28 @@ import (
|
||||||
var SupportedFormats = make(Types)
|
var SupportedFormats = make(Types)
|
||||||
|
|
||||||
type Type interface {
|
type Type interface {
|
||||||
|
// Returns either "inline" or "embed", depending on whether the file
|
||||||
|
// should be displayed inline (e.g. code) or embedded (e.g. images)
|
||||||
Type() string
|
Type() string
|
||||||
|
|
||||||
|
// Returns a CSS string used to format the corresponding page
|
||||||
Css() string
|
Css() string
|
||||||
|
|
||||||
|
// Returns an HTML <title> element for the specified file
|
||||||
Title(rootUrl, fileUri, filePath, fileName, prefix, mime string) (string, error)
|
Title(rootUrl, fileUri, filePath, fileName, prefix, mime string) (string, error)
|
||||||
|
|
||||||
|
// Returns an HTML <body> element used to display the specified file
|
||||||
Body(rootUrl, fileUri, filePath, fileName, prefix, mime string) (string, error)
|
Body(rootUrl, fileUri, filePath, fileName, prefix, mime string) (string, error)
|
||||||
|
|
||||||
|
// Returns a map of file extensions to MIME type strings.
|
||||||
Extensions() map[string]string
|
Extensions() map[string]string
|
||||||
MimeType(string) string
|
|
||||||
|
// Given a file extension, returns the corresponding MIME type,
|
||||||
|
// if one exists. Otherwise, returns an empty string.
|
||||||
|
MimeType(extension string) string
|
||||||
|
|
||||||
|
// Optional function used to validate whether a given file matches this format.
|
||||||
|
// If no validation checks are needed, this function should always return true.
|
||||||
Validate(filePath string) bool
|
Validate(filePath string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ import (
|
||||||
"seedno.de/seednode/roulette/types"
|
"seedno.de/seednode/roulette/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format struct{}
|
type Format struct {
|
||||||
|
Fun bool
|
||||||
|
}
|
||||||
|
|
||||||
func (t Format) Css() string {
|
func (t Format) Css() string {
|
||||||
var css strings.Builder
|
var css strings.Builder
|
||||||
|
|
Loading…
Reference in New Issue