diff --git a/README.md b/README.md index c6da61b..0cc4f08 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Flags: --fallback serve files as application/octet-stream if no matching format is registered -f, --filter enable filtering --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) -h, --help help for roulette --images enable support for image files @@ -123,7 +124,7 @@ Flags: --index-file string path to optional persistent index file -i, --info expose informational endpoints --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 -p, --port int port to listen on (default 8080) --prefix string root path for http handlers (for reverse proxying) (default "/") diff --git a/cmd/root.go b/cmd/root.go index 794fda6..5ee0595 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( ) const ( - ReleaseVersion string = "2.5.1" + ReleaseVersion string = "2.6.0" ) var ( @@ -26,6 +26,7 @@ var ( Fallback bool Filtering bool Flash bool + Fun bool Handlers bool Images 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().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(&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(&Images, "images", false, "enable support for image files") rootCmd.Flags().BoolVar(&Index, "index", false, "generate index of supported file paths at startup") diff --git a/cmd/web.go b/cmd/web.go index f49f350..a099d58 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -436,29 +436,29 @@ func ServePage(args []string) error { formats := make(types.Types) if Audio || All { - formats.Add(audio.Format{}) + formats.Add(audio.Format{Fun: Fun}) } if Code || All { - formats.Add(code.Format{Theme: CodeTheme}) + formats.Add(code.Format{Fun: Fun, Theme: CodeTheme}) } if Flash || All { - formats.Add(flash.Format{}) + formats.Add(flash.Format{Fun: Fun}) } if Text || All { - formats.Add(text.Format{}) + formats.Add(text.Format{Fun: Fun}) } 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 // to be replaced with rootCmd.MarkFlagsOneRequired on next spf13/cobra update if Images || All || len(formats) == 0 { - formats.Add(images.Format{}) + formats.Add(images.Format{Fun: Fun}) } paths, err := validatePaths(args, formats) diff --git a/types/audio/audio.go b/types/audio/audio.go index e699f0e..a6b7c5b 100644 --- a/types/audio/audio.go +++ b/types/audio/audio.go @@ -11,7 +11,9 @@ import ( "seedno.de/seednode/roulette/types" ) -type Format struct{} +type Format struct { + Fun bool +} func (t Format) Css() string { var css strings.Builder diff --git a/types/code/code.go b/types/code/code.go index c4fd9e0..3171420 100644 --- a/types/code/code.go +++ b/types/code/code.go @@ -20,6 +20,7 @@ import ( ) type Format struct { + Fun bool Theme string } @@ -56,6 +57,9 @@ func (t Format) Css() string { 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") + if t.Fun { + css.WriteString("body{font-family: \"Comic Sans MS\", cursive, \"Brush Script MT\", sans-serif;}\n") + } return css.String() } diff --git a/types/flash/flash.go b/types/flash/flash.go index 77ecbc1..b434320 100644 --- a/types/flash/flash.go +++ b/types/flash/flash.go @@ -11,7 +11,9 @@ import ( "seedno.de/seednode/roulette/types" ) -type Format struct{} +type Format struct { + Fun bool +} func (t Format) Css() string { var css strings.Builder diff --git a/types/images/images.go b/types/images/images.go index 724af49..93a69a0 100644 --- a/types/images/images.go +++ b/types/images/images.go @@ -11,6 +11,7 @@ import ( _ "image/gif" _ "image/jpeg" _ "image/png" + "math/rand" "os" "strings" @@ -24,7 +25,9 @@ type dimensions struct { height int } -type Format struct{} +type Format struct { + Fun bool +} func (t Format) Css() string { 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(`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(`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() } diff --git a/types/text/text.go b/types/text/text.go index 914b2f8..cbcf780 100644 --- a/types/text/text.go +++ b/types/text/text.go @@ -14,7 +14,9 @@ import ( "seedno.de/seednode/roulette/types" ) -type Format struct{} +type Format struct { + Fun bool +} func (t Format) Css() string { var css strings.Builder diff --git a/types/types.go b/types/types.go index 335525a..b2bc101 100644 --- a/types/types.go +++ b/types/types.go @@ -13,12 +13,28 @@ import ( var SupportedFormats = make(Types) 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 + + // Returns a CSS string used to format the corresponding page Css() string + + // Returns an HTML element for the specified file 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) + + // Returns a map of file extensions to MIME type strings. 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 } diff --git a/types/video/video.go b/types/video/video.go index 17e2607..823b652 100644 --- a/types/video/video.go +++ b/types/video/video.go @@ -12,7 +12,9 @@ import ( "seedno.de/seednode/roulette/types" ) -type Format struct{} +type Format struct { + Fun bool +} func (t Format) Css() string { var css strings.Builder