forked from stashapp/stash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom served folders (stashapp#620)
- Loading branch information
1 parent
bee5dda
commit 532900b
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters