enhanced prefix handling

This commit is contained in:
Martin Riedl 2021-03-18 19:02:34 +01:00
parent dd14b201b1
commit 01030a52ba
Signed by: martinr92
GPG key ID: FB68DA65516A804C

8
fs.go
View file

@ -65,16 +65,12 @@ func (fs *FS) ServeHTTP(w http.ResponseWriter, r *http.Request, info RoutingInfo
func (fs *FS) findFile(url string) (fs.File, error) {
// build file path
filePath := path.Join(fs.FolderPrefix, url)
if strings.HasPrefix(filePath, "/") {
filePath = filePath[1:]
}
filePath = strings.TrimPrefix(filePath, "/")
// check, if file exists in local folder
if fs.UseLocalFolder {
localFilePath := path.Join(fs.LocalFolderPrefix, filePath)
if strings.HasPrefix(localFilePath, "/") {
localFilePath = localFilePath[1:]
}
localFilePath = strings.TrimPrefix(localFilePath, "/")
file, err := os.Open(localFilePath)
if err == nil {