Remove file from filesystem and cache at same time during serveStaticFile()

This commit is contained in:
Seednode 2023-09-09 21:17:17 -05:00
parent 26475ed491
commit 53d14ff279
2 changed files with 7 additions and 7 deletions

View File

@ -17,7 +17,7 @@ var (
) )
const ( const (
Version string = "0.59.1" Version string = "0.59.2"
) )
var ( var (

View File

@ -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) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
path := strings.TrimPrefix(r.URL.Path, SourcePrefix) path := strings.TrimPrefix(r.URL.Path, SourcePrefix)
@ -839,6 +839,10 @@ func serveStaticFile(paths []string, stats *ServeStats) httprouter.Handle {
fileSize := humanReadableSize(len(buf)) fileSize := humanReadableSize(len(buf))
if russian { if russian {
if cache {
index.Remove(filePath)
}
err = os.Remove(filePath) err = os.Remove(filePath)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -1037,10 +1041,6 @@ func serveImage(paths []string, Regexes *Regexes, index *Index) httprouter.Handl
return 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(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()) mux.GET("/version", serveVersion())