mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
Load favicon if provided
This commit is contained in:
parent
e213fde0cc
commit
d77d667679
2 changed files with 35 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -255,6 +256,9 @@ func Initialize() (*Server, error) {
|
||||||
staticUI = statigz.FileServer(ui.UIBox.(fs.ReadDirFS))
|
staticUI = statigz.FileServer(ui.UIBox.(fs.ReadDirFS))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle favicon override
|
||||||
|
r.HandleFunc("/favicon.ico", handleFavicon(staticUI))
|
||||||
|
|
||||||
// Serve the web app
|
// Serve the web app
|
||||||
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||||
ext := path.Ext(r.URL.Path)
|
ext := path.Ext(r.URL.Path)
|
||||||
|
|
@ -295,6 +299,31 @@ func Initialize() (*Server, error) {
|
||||||
return server, nil
|
return server, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleFavicon(staticUI *statigz.Server) func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
mgr := manager.GetInstance()
|
||||||
|
cfg := mgr.Config
|
||||||
|
|
||||||
|
// check if favicon.ico exists in the config directory
|
||||||
|
// if so, use that
|
||||||
|
// otherwise, use the embedded one
|
||||||
|
iconPath := filepath.Join(cfg.GetConfigPath(), "favicon.ico")
|
||||||
|
exists, _ := fsutil.FileExists(iconPath)
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
logger.Debugf("Using custom favicon at %s", iconPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Cache-Control", "no-cache")
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
http.ServeFile(w, r, iconPath)
|
||||||
|
} else {
|
||||||
|
staticUI.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start starts the server. It listens on the configured address and port.
|
// Start starts the server. It listens on the configured address and port.
|
||||||
// It calls ListenAndServeTLS if TLS is configured, otherwise it calls ListenAndServe.
|
// It calls ListenAndServeTLS if TLS is configured, otherwise it calls ListenAndServe.
|
||||||
// Calls to Start are blocked until the server is shutdown.
|
// Calls to Start are blocked until the server is shutdown.
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,12 @@ The following environment variables are also supported:
|
||||||
|----------------------|---------|
|
|----------------------|---------|
|
||||||
| `STASH_SQLITE_CACHE_SIZE` | Sets the SQLite cache size. See https://www.sqlite.org/pragma.html#pragma_cache_size. Default is `-2000` which is 2MB. |
|
| `STASH_SQLITE_CACHE_SIZE` | Sets the SQLite cache size. See https://www.sqlite.org/pragma.html#pragma_cache_size. Default is `-2000` which is 2MB. |
|
||||||
|
|
||||||
|
### Custom favicon
|
||||||
|
|
||||||
|
You can provide a custom favicon by placing a `favicon.ico` file in the configuration directory. The configuration directory is located alongside the `config.yml` file.
|
||||||
|
|
||||||
|
When a custom favicon is provided, it will be served instead of the default embedded favicon.
|
||||||
|
|
||||||
### Custom served folders
|
### Custom served folders
|
||||||
|
|
||||||
Custom served folders are served when the server handles a request with the `/custom` URL prefix. The following is an example configuration:
|
Custom served folders are served when the server handles a request with the `/custom` URL prefix. The following is an example configuration:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue