mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Add custom served folders (#620)
This commit is contained in:
@@ -251,6 +251,24 @@ func Start() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
startThumbCache()
|
startThumbCache()
|
||||||
|
|
||||||
|
// Serve static folders
|
||||||
|
customServedFolders := config.GetCustomServedFolders()
|
||||||
|
if customServedFolders != nil {
|
||||||
|
r.HandleFunc("/custom/*", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.URL.Path = strings.Replace(r.URL.Path, "/custom", "", 1)
|
||||||
|
|
||||||
|
// map the path to the applicable filesystem location
|
||||||
|
var dir string
|
||||||
|
r.URL.Path, dir = customServedFolders.GetFilesystemLocation(r.URL.Path)
|
||||||
|
if dir != "" {
|
||||||
|
http.FileServer(http.Dir(dir)).ServeHTTP(w, r)
|
||||||
|
} else {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ const ScraperUserAgent = "scraper_user_agent"
|
|||||||
// i18n
|
// i18n
|
||||||
const Language = "language"
|
const Language = "language"
|
||||||
|
|
||||||
|
// served directories
|
||||||
|
// this should be manually configured only
|
||||||
|
const CustomServedFolders = "custom_served_folders"
|
||||||
|
|
||||||
// Interface options
|
// Interface options
|
||||||
const SoundOnPreview = "sound_on_preview"
|
const SoundOnPreview = "sound_on_preview"
|
||||||
const WallShowTitle = "wall_show_title"
|
const WallShowTitle = "wall_show_title"
|
||||||
@@ -231,6 +235,12 @@ func GetMaxSessionAge() int {
|
|||||||
return viper.GetInt(MaxSessionAge)
|
return viper.GetInt(MaxSessionAge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCustomServedFolders gets the map of custom paths to their applicable
|
||||||
|
// filesystem locations
|
||||||
|
func GetCustomServedFolders() URLMap {
|
||||||
|
return viper.GetStringMapString(CustomServedFolders)
|
||||||
|
}
|
||||||
|
|
||||||
// Interface options
|
// Interface options
|
||||||
func GetSoundOnPreview() bool {
|
func GetSoundOnPreview() bool {
|
||||||
viper.SetDefault(SoundOnPreview, true)
|
viper.SetDefault(SoundOnPreview, true)
|
||||||
|
|||||||
21
pkg/manager/config/urlmap.go
Normal file
21
pkg/manager/config/urlmap.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
type URLMap map[string]string
|
||||||
|
|
||||||
|
// GetFilesystemLocation returns the adjusted URL and the filesystem location
|
||||||
|
func (m URLMap) GetFilesystemLocation(url string) (string, string) {
|
||||||
|
root := m["/"]
|
||||||
|
for k, v := range m {
|
||||||
|
if k != "/" && strings.HasPrefix(url, k) {
|
||||||
|
return strings.TrimPrefix(url, k), v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if root != "" {
|
||||||
|
return url, root
|
||||||
|
}
|
||||||
|
|
||||||
|
return url, ""
|
||||||
|
}
|
||||||
28
pkg/manager/config/urlmap_test.go
Normal file
28
pkg/manager/config/urlmap_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestURLMapGetFilesystemLocation(t *testing.T) {
|
||||||
|
// create the URLMap
|
||||||
|
urlMap := make(URLMap)
|
||||||
|
urlMap["/"] = "root"
|
||||||
|
urlMap["/foo"] = "bar"
|
||||||
|
|
||||||
|
url, fs := urlMap.GetFilesystemLocation("/foo/bar")
|
||||||
|
assert.Equal(t, "/bar", url)
|
||||||
|
assert.Equal(t, urlMap["/foo"], fs)
|
||||||
|
|
||||||
|
url, fs = urlMap.GetFilesystemLocation("/bar")
|
||||||
|
assert.Equal(t, "/bar", url)
|
||||||
|
assert.Equal(t, urlMap["/"], fs)
|
||||||
|
|
||||||
|
delete(urlMap, "/")
|
||||||
|
|
||||||
|
url, fs = urlMap.GetFilesystemLocation("/bar")
|
||||||
|
assert.Equal(t, "/bar", url)
|
||||||
|
assert.Equal(t, "", fs)
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import ReactMarkdown from "react-markdown";
|
|||||||
|
|
||||||
const markup = `
|
const markup = `
|
||||||
### ✨ New Features
|
### ✨ New Features
|
||||||
|
* Add support for custom served folders.
|
||||||
* Add support for parent/child studios.
|
* Add support for parent/child studios.
|
||||||
|
|
||||||
### 🎨 Improvements
|
### 🎨 Improvements
|
||||||
|
|||||||
Reference in New Issue
Block a user