mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Plugin assets, external scripts and CSP overrides (#4260)
* Add assets for plugins * Move plugin javascript and css into separate endpoints * Allow loading external scripts * Add csp overrides * Only include enabled plugins * Move URLMap to utils * Use URLMap for assets * Add documentation
This commit is contained in:
30
pkg/utils/urlmap.go
Normal file
30
pkg/utils/urlmap.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
// URLMap is a map of URL prefixes to filesystem locations
|
||||
type URLMap map[string]string
|
||||
|
||||
// GetFilesystemLocation returns the adjusted URL and the filesystem location
|
||||
func (m URLMap) GetFilesystemLocation(url string) (newURL string, fsPath string) {
|
||||
newURL = url
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
root := m["/"]
|
||||
for k, v := range m {
|
||||
if k != "/" && strings.HasPrefix(url, k) {
|
||||
newURL = strings.TrimPrefix(url, k)
|
||||
fsPath = v
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if root != "" {
|
||||
fsPath = root
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user