2022-09-16 15:52:59 -04:00
## About
2023-09-10 21:29:11 -04:00
Sometimes, you just need a way to randomly display media from your filesystem.
2022-09-16 15:52:59 -04:00
2022-10-18 17:58:15 -04:00
Simply point this tool at one or more directories, and then open the specified port (default `8080` ) in your browser.
2022-09-16 15:52:59 -04:00
2023-09-10 21:29:11 -04:00
A new file will be selected if you open `/` directly, or if you click on any displayed files.
2022-09-16 15:52:59 -04:00
2023-09-10 21:29:11 -04:00
Browser history is preserved, so you can always go back to any previously displayed media.
2022-09-16 15:52:59 -04:00
2022-11-11 00:33:20 -05:00
Feature requests, code criticism, bug reports, general chit-chat, and unrelated angst accepted at `roulette@seedno.de` .
2022-11-11 00:34:31 -05:00
Static binary builds available [here ](https://cdn.seedno.de/builds/roulette ).
2022-11-11 18:51:02 -05:00
I only test the linux/amd64, linux/arm64, and windows/amd64 builds, the rest are all best-effort™.
x86_64 and ARM Docker images of latest version: `oci.seedno.de/seednode/roulette:latest` .
2023-09-05 11:20:04 -04:00
Dockerfile available [here ](https://git.seedno.de/seednode/roulette/raw/branch/master/docker/Dockerfile ).
2022-09-16 15:52:59 -04:00
2023-10-13 14:09:59 -04:00
An example instance with most features enabled can be found [here ](https://nature.seedno.de/ ).
2023-12-17 07:50:55 -05:00
## Admin prefix
You can restrict access to certain functionality by prepending a secret string to the paths.
For example, providing the `--admin-prefix=abc123` flag will register the index rebuild path as `/abc123/index/rebuild` .
2023-12-31 16:50:13 -05:00
The restricted paths are:
2024-01-14 10:29:22 -05:00
- `/debug/pprof/allocs`
- `/debug/pprof/block`
2023-12-17 07:50:55 -05:00
- `/debug/pprof/cmdline`
2024-01-14 10:29:22 -05:00
- `/debug/pprof/goroutine`
- `/debug/pprof/heap`
- `/debug/pprof/mutex`
2023-12-17 07:50:55 -05:00
- `/debug/pprof/profile`
- `/debug/pprof/symbol`
2024-01-14 10:29:22 -05:00
- `/debug/pprof/threadcreate`
2023-12-17 07:50:55 -05:00
- `/debug/pprof/trace`
- `/extensions/available`
- `/extensions/enabled`
2024-01-15 09:51:41 -05:00
- `/index/`
2023-12-17 07:50:55 -05:00
- `/index/rebuild`
- `/types/available`
- `/types/enabled`
2023-12-17 08:28:21 -05:00
While this might thwart very basic attacks, the proper solution for most use cases would likely be to add authentication via a reverse proxy.
2022-10-19 20:56:42 -04:00
## Filtering
2022-11-10 15:54:55 -05:00
You can provide a comma-delimited string of alphanumeric patterns to match via the `include=` query parameter, assuming the `-f|--filter` flag is enabled.
2022-10-19 20:56:42 -04:00
Only filenames matching one or more of the patterns will be served.
2022-11-10 15:54:17 -05:00
You can also provide a comma-delimited string of alphanumeric patterns to exclude, via the `exclude=` query parameter.
2022-10-19 20:56:42 -04:00
Filenames matching any of these patterns will not be served.
2023-09-28 04:36:26 -04:00
You can combine these two parameters, with exclusions taking priority over inclusions.
2022-10-19 20:56:42 -04:00
Both filtering parameters ignore the file extension and full path; they only compare against the bare filename.
2023-12-07 11:34:19 -05:00
## Ignoring directories
2024-01-05 22:55:22 -05:00
If the `--ignore` flag is passed, any directory containing a file named `.roulette-ignore` (configurable with `--ignore-file` ) will be skipped during the scanning stage.
2023-12-07 11:34:19 -05:00
2023-09-28 11:09:45 -04:00
## Indexing
2024-01-15 10:28:59 -05:00
If the `-i|--index` flag is passed, all specified paths will be indexed on start.
2023-09-28 11:09:45 -04:00
This will slightly increase the delay before the application begins responding to requests, but should significantly speed up subsequent requests.
2023-10-09 11:13:15 -04:00
The index can be regenerated at any time by accessing the `/index/rebuild` endpoint.
2022-10-19 20:56:42 -04:00
2024-01-30 05:38:29 -05:00
Automatic index rebuilds can be enabled via the `--index-interval` flag, which accepts [time.Duration ](https://pkg.go.dev/time#ParseDuration ) strings.
2023-09-28 11:09:45 -04:00
If `--index-file` is set, the index will be loaded from the specified file on start, and written to the file whenever it is re-generated.
2024-01-30 05:49:46 -05:00
The index file consists of [zstd ](https://facebook.github.io/zstd/ )-compressed [gobs ](https://pkg.go.dev/encoding/gob ).
2023-12-31 16:50:13 -05:00
2023-09-28 11:09:45 -04:00
## Info
2024-01-15 10:28:59 -05:00
If the `-i|--info` flag is passed, five additional endpoints are registered.
2022-10-19 20:56:42 -04:00
2024-01-15 10:28:59 -05:00
The first of these—`/index/`—returns the contents of the index, in JSON format.
2022-10-19 20:56:42 -04:00
2023-09-13 18:02:43 -04:00
This can prove useful when confirming whether the index is generated successfully, or whether a given file is in the index.
2022-10-19 21:42:08 -04:00
2023-10-09 11:13:15 -04:00
The remaining four endpoints—`/extensions/available`, `/extensions/enabled` , `/types/available` and `/types/enabled` —return information about the registered file types.
2022-10-19 20:56:42 -04:00
2022-11-08 20:24:49 -05:00
## Refresh
2023-09-14 01:07:54 -04:00
If the `--refresh` flag is passed and a positive-value `refresh=<integer><unit>` query parameter is provided, the page will reload after that interval.
2022-11-08 20:24:49 -05:00
2023-10-09 09:17:32 -04:00
This can be used to generate a sort of slideshow of files in any browser with Javascript support.
Pressing Spacebar will pause automatic refreshing until Spacebar is pressed again, the page is manually refreshed, or a new page is loaded.
2022-11-08 20:24:49 -05:00
2023-08-21 16:38:56 -04:00
Minimum accepted value is 500ms, as anything lower seems to cause inconsistent behavior. This might be changed in a future release.
2023-01-18 10:58:14 -05:00
Supported units are `ns` , `us` /`µs`, `ms` , `s` , `m` , and `h` .
2023-09-13 18:02:43 -04:00
## Russian
If the `--russian` flag is passed, everything functions exactly as you would expect.
2023-02-05 15:34:22 -05:00
2023-09-13 18:02:43 -04:00
That is, files will be deleted after being served. This is not a joke, you *will* lose data.
2023-09-13 00:35:17 -04:00
2024-01-30 05:49:46 -05:00
This uses [os.Remove() ](https://pkg.go.dev/os#Remove ) and checks to ensure the specified file is inside one of the paths passed to `roulette` .
2023-09-12 15:00:15 -04:00
2023-09-13 18:02:43 -04:00
That said, this has not been tested to any real extent, so only pass this flag on systems you don't care about.
2023-09-12 23:35:15 -04:00
2023-09-13 18:02:43 -04:00
Enjoy!
2023-09-13 00:35:17 -04:00
2023-09-13 18:02:43 -04:00
## Sorting
2023-09-28 04:36:26 -04:00
You can specify a sorting direction via the `sort=` query parameter, assuming the `-s|--sort` flag is enabled.
2023-09-12 15:00:15 -04:00
2023-09-13 18:02:43 -04:00
A value of `sort=asc` means files will be served in ascending order (lowest-numbered to highest).
2023-01-19 13:07:15 -05:00
2023-09-13 18:02:43 -04:00
If a file exists with a numbered suffix one higher than the currently displayed file, it will be served next.
2023-01-19 13:07:15 -05:00
2023-09-13 18:02:43 -04:00
A value of `sort=desc` means files will be served in descending order (highest-numbered to lowest).
2023-01-19 13:07:15 -05:00
2023-09-13 18:02:43 -04:00
If a file exists with a numbered suffix one lower than the currently displayed file, it will be served next.
2023-09-13 00:35:17 -04:00
2023-09-13 18:02:43 -04:00
In either case, if no sequential file is found, a new random one will be chosen.
2023-09-09 22:27:57 -04:00
2023-09-13 18:02:43 -04:00
For `sort=asc` , the lowest-numbered file matching a given name will be served first.
2023-09-09 22:27:57 -04:00
2023-09-13 18:02:43 -04:00
For `sort=desc` , the highest-numbered file will be served instead.
2023-09-09 22:27:57 -04:00
2023-09-13 18:02:43 -04:00
If any other (or no) value is provided, the selected file will be random.
2023-09-09 22:27:57 -04:00
2023-09-28 04:36:26 -04:00
Note: These options require sequentially-numbered files matching the following pattern: `filename[0-9]*.extension` .
2023-09-09 22:27:57 -04:00
2023-09-14 23:13:21 -04:00
## Themes
The `--code` handler provides syntax highlighting via [alecthomas/chroma ](https://github.com/alecthomas/chroma ).
Any [supported theme ](https://pkg.go.dev/github.com/alecthomas/chroma/v2@v2.9.1/styles#pkg-variables ) can be passed via the `--theme` flag.
By default, [`solarized-dark256` ](https://xyproto.github.io/splash/docs/solarized-dark256.html ) is used.
2022-09-16 15:52:59 -04:00
## Usage output
```
2023-09-10 21:29:11 -04:00
Serves random media from the specified directories.
2023-08-02 14:29:37 -04:00
2023-02-05 15:42:31 -05:00
Usage:
2023-01-19 13:12:40 -05:00
roulette < path > [path]... [flags]
2022-09-16 15:52:59 -04:00
Flags:
2024-01-30 05:35:49 -05:00
--admin-prefix string string to prepend to administrative paths
-a, --all enable all supported file types
--allow-empty allow specifying paths containing no supported files
--audio enable support for audio files
--binary-prefix use IEC binary prefixes instead of SI decimal prefixes
-b, --bind string address to bind to (default "0.0.0.0")
--case-insensitive use case-insensitive matching for filters
--code enable support for source code files
--code-theme string theme for source code syntax highlighting (default "solarized-dark256")
--concurrency int maximum concurrency for scan threads (default 1024)
-d, --debug display even more verbose logs
--disable-buttons disable first/prev/next/last buttons
--exit-on-error shut down webserver on error, instead of just printing error
--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 add a bit of excitement to your day
-h, --help help for roulette
--ignore skip all directories containing a specified filename
--ignore-file string filename used to indicate directory should be skipped (default ".roulette-ignore")
--images enable support for image files
--index generate index of supported file paths at startup
--index-file string path to optional persistent index file
--index-interval string interval at which to regenerate index (e.g. "3s" or "1h")
-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
-p, --port int port to listen on (default 8080)
--prefix string root path for http handlers (for reverse proxying) (default "/")
--profile register net/http/pprof handlers
-r, --recursive recurse into subdirectories
--refresh enable automatic page refresh via query parameter
--russian remove selected images after serving
-s, --sort enable sorting
--text enable support for text files
-v, --verbose log accessed files and other information to stdout
-V, --version display version and exit
--video enable support for video files
2023-09-05 09:22:06 -04:00
```
## Building the Docker container
From inside the `docker/` subdirectory, build the image using the following command:
2023-10-13 14:09:59 -04:00
`REGISTRY=<registry url> LATEST=yes TAG=alpine ./build.sh`