From 53d14ff279fe1fa8abf36cd05179fbecec2274c3 Mon Sep 17 00:00:00 2001 From: Seednode Date: Sat, 9 Sep 2023 21:17:17 -0500 Subject: [PATCH] Remove file from filesystem and cache at same time during serveStaticFile() --- cmd/root.go | 2 +- cmd/web.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index d9267b3..c5863e5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,7 @@ var ( ) const ( - Version string = "0.59.1" + Version string = "0.59.2" ) var ( diff --git a/cmd/web.go b/cmd/web.go index 1d93e58..a77ccd4 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -780,7 +780,7 @@ func serveDebugJson(args []string, index *Index) httprouter.Handle { } } -func serveStaticFile(paths []string, stats *ServeStats) httprouter.Handle { +func serveStaticFile(paths []string, stats *ServeStats, index *Index) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { path := strings.TrimPrefix(r.URL.Path, SourcePrefix) @@ -839,6 +839,10 @@ func serveStaticFile(paths []string, stats *ServeStats) httprouter.Handle { fileSize := humanReadableSize(len(buf)) if russian { + if cache { + index.Remove(filePath) + } + err = os.Remove(filePath) if err != nil { fmt.Println(err) @@ -1037,10 +1041,6 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl return } - - if russian && cache { - index.Remove(filePath) - } } } @@ -1142,7 +1142,7 @@ func ServePage(args []string) error { mux.GET(ImagePrefix+"/*image", serveImage(paths, Regexes, index)) - mux.GET(SourcePrefix+"/*static", serveStaticFile(paths, stats)) + mux.GET(SourcePrefix+"/*static", serveStaticFile(paths, stats, index)) mux.GET("/version", serveVersion())