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) { func (fs *FS) findFile(url string) (fs.File, error) {
// build file path // build file path
filePath := path.Join(fs.FolderPrefix, url) filePath := path.Join(fs.FolderPrefix, url)
if strings.HasPrefix(filePath, "/") { filePath = strings.TrimPrefix(filePath, "/")
filePath = filePath[1:]
}
// check, if file exists in local folder // check, if file exists in local folder
if fs.UseLocalFolder { if fs.UseLocalFolder {
localFilePath := path.Join(fs.LocalFolderPrefix, filePath) localFilePath := path.Join(fs.LocalFolderPrefix, filePath)
if strings.HasPrefix(localFilePath, "/") { localFilePath = strings.TrimPrefix(localFilePath, "/")
localFilePath = localFilePath[1:]
}
file, err := os.Open(localFilePath) file, err := os.Open(localFilePath)
if err == nil { if err == nil {