Fix purging default file from HTTP cache

This commit is contained in:
Ingo Oppermann
2023-03-23 11:17:13 +01:00
parent 52df872198
commit 48678fb4c6
2 changed files with 13 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import (
"net/http"
"path/filepath"
"sort"
"strings"
"github.com/datarhei/core/v16/http/api"
"github.com/datarhei/core/v16/http/fs"
@@ -107,12 +108,19 @@ func (h *FSHandler) DeleteFile(c echo.Context) error {
size := h.fs.Filesystem.Remove(path)
if size < 0 {
return api.Err(http.StatusNotFound, "File not found", path)
}
if h.fs.Cache != nil {
h.fs.Cache.Delete(path)
if len(h.fs.DefaultFile) != 0 {
if strings.HasSuffix(path, "/"+h.fs.DefaultFile) {
path := strings.TrimSuffix(path, h.fs.DefaultFile)
h.fs.Cache.Delete(path)
}
}
}
if size < 0 {
return api.Err(http.StatusNotFound, "File not found", path)
}
return c.String(http.StatusOK, "Deleted: "+path)