* Don't capitalize local variables
ValidCodecs -> validCodecs
* Capitalize deprecation markers
A deprecated marker should be capitalized.
* Use re.MustCompile for static regexes
If the regex fails to compile, it's a programmer error, and should be
treated as such. The regex is entirely static.
* Simplify else-if constructions
Rewrite
else { if cond {}}
to
else if cond {}
* Use a switch statement to analyze formats
Break an if-else chain. While here, simplify code flow.
Also introduce a proper static error for unsupported image formats,
paving the way for being able to check against the error.
* Rewrite ifElse chains into switch statements
The "Effective Go" https://golang.org/doc/effective_go#switch document
mentions it is more idiomatic to write if-else chains as switches when
it is possible.
Find all the plain rewrite occurrences in the code base and rewrite.
In some cases, the if-else chains are replaced by a switch scrutinizer.
That is, the code sequence
if x == 1 {
..
} else if x == 2 {
..
} else if x == 3 {
...
}
can be rewritten into
switch x {
case 1:
..
case 2:
..
case 3:
..
}
which is clearer for the compiler: it can decide if the switch is
better served by a jump-table then a branch-chain.
* Rewrite switches, introduce static errors
Introduce two new static errors:
* `ErrNotImplmented`
* `ErrNotSupported`
And use these rather than forming new generative errors whenever the
code is called. Code can now test on the errors (since they are static
and the pointers to them wont change).
Also rewrite ifElse chains into switches in this part of the code base.
* Introduce a StashBoxError in configuration
Since all stashbox errors are the same, treat them as such in the code
base. While here, rewrite an ifElse chain.
In the future, it might be beneifical to refactor configuration errors
into one error which can handle missing fields, which context the error
occurs in and so on. But for now, try to get an overview of the error
categories by hoisting them into static errors.
* Get rid of an else-block in transaction handling
If we succesfully `recover()`, we then always `panic()`. This means the
rest of the code is not reachable, so we can avoid having an else-block
here.
It also solves an ifElse-chain style check in the code base.
* Use strings.ReplaceAll
Rewrite
strings.Replace(s, o, n, -1)
into
strings.ReplaceAll(s, o, n)
To make it consistent and clear that we are doing an all-replace in the
string rather than replacing parts of it. It's more of a nitpick since
there are no implementation differences: the stdlib implementation is
just to supply -1.
* Rewrite via gocritic's assignOp
Statements of the form
x = x + e
is rewritten into
x += e
where applicable.
* Formatting
* Review comments handled
Stash-box is a proper noun.
Rewrite a switch into an if-chain which returns on the first error
encountered.
* Use context.TODO() over context.Background()
Patch in the same vein as everything else: use the TODO() marker so we
can search for it later and link it into the context tree/tentacle once
it reaches down to this level in the code base.
* Tell the linter to ignore a section in manager_tasks.go
The section is less readable, so mark it with a nolint for now. Because
the rewrite enables a ifElseChain, also mark that as nolint for now.
* Use strings.ReplaceAll over strings.Replace
* Apply an ifElse rewrite
else { if .. { .. } } rewrite into else if { .. }
* Use switch-statements over ifElseChains
Rewrite chains of if-else into switch statements. Where applicable,
add an early nil-guard to simplify case analysis. Also, in
ScanTask's Start(..), invert the logic to outdent the whole block, and
help the reader: if it's not a scene, the function flow is now far more
local to the top of the function, and it's clear that the rest of the
function has to do with scene management.
* Enable gocritic on the code base.
Disable appendAssign for now since we aren't passing that check yet.
* Document the nolint additions
* Document StashBoxBatchPerformerTagInput
Stash
Stash is a locally hosted web-based app written in Go which organizes and serves your porn.
- It can gather information about videos in your collection from the internet, and is extensible through the use of community-built plugins for a large number of content producers.
- It supports a wide variety of both video and image formats.
- You can tag videos and find them later.
- It provides statistics about performers, tags, studios and other things.
You can watch a SFW demo video to see it in action.
For further information you can read the in-app manual.
Installing stash
via Docker
Follow this README.md in the docker directory.
Pre-Compiled Binaries
The Stash server runs on macOS, Windows, and Linux. Download the latest release here.
Run the executable (double click the exe on windows or run ./stash-osx / ./stash-linux from the terminal on macOS / Linux) and navigate to either https://localhost:9999 or http://localhost:9999 to get started.
Note for Windows users: Running the app might present a security prompt since the binary isn't yet signed. Bypass this by clicking "more info" and then the "run anyway" button.
FFMPEG
If stash is unable to find or download FFMPEG then download it yourself from the link for your platform:
The ffmpeg(.exe) and ffprobe(.exe) files should be placed in ~/.stash on macOS / Linux or C:\Users\YourUsername\.stash on Windows.
Usage
Quickstart Guide
- Download and install Stash and its dependencies
- Run Stash. It will prompt you for some configuration options and a directory to index (you can also do this step afterward)
- After configuration, launch your web browser and navigate to the URL shown within the Stash app.
Note that Stash does not currently retrieve and organize information about your entire library automatically. You will need to help it along through the use of scrapers. The Stash community has developed scrapers for many popular data sources which can be downloaded and installed from this repository.
The simplest way to tag a large number of files is by using the Tagger which uses filename keywords to help identify the file and pull in scene and performer information from our stash-box database. Note that this data source is not comprehensive and you may need to use the scrapers to identify some of your media.
CLI
Stash runs as a command-line app and local web server. There are some command-line options available, which you can see by running stash --help.
For example, to run stash locally on port 80 run it like this (OSX / Linux) stash --host 127.0.0.1 --port 80
SSL (HTTPS)
Stash can run over HTTPS with some additional work. First you must generate a SSL certificate and key combo. Here is an example using openssl:
openssl req -x509 -newkey rsa:4096 -sha256 -days 7300 -nodes -keyout stash.key -out stash.crt -extensions san -config <(echo "[req]"; echo distinguished_name=req; echo "[san]"; echo subjectAltName=DNS:stash.server,IP:127.0.0.1) -subj /CN=stash.server
This command would need customizing for your environment. This link might be useful.
Once you have a certificate and key file name them stash.crt and stash.key and place them in the same directory as the config.yml file, or the ~/.stash directory. Stash detects these and starts up using HTTPS rather than HTTP.
Basepath rewriting
The basepath defaults to /. When running stash via a reverse proxy in a subpath, the basepath can be changed by having the reverse proxy pass X-Forwarded-Prefix (and optionally X-Forwarded-Port) headers. When detects these headers, it alters the basepath URL of the UI.
Customization
Themes and CSS Customization
There is a directory of community-created themes on our Wiki, along with instructions on how to install them.
You can also make Stash interface fit your desired style with Custom CSS snippets and CSS Tweaks.
Support (FAQ)
Answers to other Frequently Asked Questions can be found on our Wiki
For issues not addressed there, there are a few options.
- Read the Wiki
- Check the in-app documentation (also available here
- Join the Discord server, where the community can offer support.
Compiling From Source Code
Pre-requisites
- Go
- GolangCI - A meta-linter which runs several linters in parallel
- To install, follow the local installation instructions
- Yarn - Yarn package manager
- Run
yarn install --frozen-lockfilein thestash/ui/v2.5folder (before running make generate for first time).
- Run
NOTE: You may need to run the go get commands outside the project directory to avoid modifying the projects module file.
Environment
macOS
TODO
Windows
- Download and install Go for Windows
- Download and install MingW
- Search for "advanced system settings" and open the system properties dialog.
- Click the
Environment Variablesbutton - Under system variables find the
Path. Edit and addC:\Program Files\mingw-w64\*\mingw64\bin(replace * with the correct path).
- Click the
NOTE: The make command in Windows will be mingw32-make with MingW.
Commands
make generate- Generate Go and UI GraphQL filesmake build- Builds the binary (make sure to build the UI as well... see below)make docker-build- Locally builds and tags a complete 'stash/build' docker imagemake pre-ui- Installs the UI dependencies. Only needs to be run once before building the UI for the first time, or if the dependencies are updatedmake fmt-ui- Formats the UI source codemake ui- Builds the frontendmake lint- Run the linter on the backendmake fmt- Rungo fmtmake it- Run the unit and integration testsmake validate- Run all of the tests and checks required to submit a PRmake ui-start- Runs the UI in development mode. Requires a running stash server to connect to. Stash port can be changed from the default of9999with environment variableREACT_APP_PLATFORM_PORT.
Building a release
- Run
make generateto create generated files - Run
make uito compile the frontend - Run
make buildto build the executable for your current platform
Cross compiling
This project uses a modification of the CI-GoReleaser docker container to create an environment
where the app can be cross-compiled. This process is kicked off by CI via the scripts/cross-compile.sh script. Run the following
command to open a bash shell to the container to poke around:
docker run --rm --mount type=bind,source="$(pwd)",target=/stash -w /stash -i -t stashappdev/compiler:latest /bin/bash
Profiling
Stash can be profiled using the --cpuprofile <output profile filename> command line flag.
The resulting file can then be used with pprof as follows:
go tool pprof <path to binary> <path to profile filename>
With graphviz installed and in the path, a call graph can be generated with:
go tool pprof -svg <path to binary> <path to profile filename> > <output svg file>