From 48678fb4c60a3beeeede03191333809029dac5e6 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Thu, 23 Mar 2023 11:17:13 +0100 Subject: [PATCH] Fix purging default file from HTTP cache --- CHANGELOG.md | 1 + http/handler/filesystem.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7f4285d..bdd254d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix better naming for storage endpoint documentation - Fix freeing up S3 mounts - Fix URL validation if the path contains FFmpeg specific placeholders +- Fix purging default file from HTTP cache ### Core v16.11.0 > v16.12.0 diff --git a/http/handler/filesystem.go b/http/handler/filesystem.go index a8277e7c..54435238 100644 --- a/http/handler/filesystem.go +++ b/http/handler/filesystem.go @@ -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)