Copy ImgName before invoke c.SendFile since stripTrailingSlashes in fasthttp will change the content of ctx.URI().Path(), which was once obtained as ImgPath := c.Path()

Signed-off-by: Cocoa <0xbbc@0xbbc.com>
This commit is contained in:
Cocoa 2020-02-26 02:04:50 +08:00
parent 735b7d2cda
commit 25d46611f1
No known key found for this signature in database
GPG Key ID: 9821F9625A97231D

View File

@ -169,11 +169,13 @@ func main() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
ImgNameCopy := string([]byte(ImgName))
c.SendFile(WebpAbsolutePath) c.SendFile(WebpAbsolutePath)
// /home/webp_server/exhaust/path/to/tsuki.jpg.1582558100.webp <- older ones will be removed // /home/webp_server/exhaust/path/to/tsuki.jpg.1582558100.webp <- older ones will be removed
// /home/webp_server/exhaust/path/to/tsuki.jpg.1582558990.webp <- keep the latest one // /home/webp_server/exhaust/path/to/tsuki.jpg.1582558990.webp <- keep the latest one
WebpCachedImgPath := path.Clean(fmt.Sprintf("%s/exhaust%s/%s.*.webp", CurrentPath, DirPath, ImgName)) WebpCachedImgPath := path.Clean(fmt.Sprintf("%s/exhaust%s/%s.*.webp", CurrentPath, DirPath, ImgNameCopy))
matches, err := filepath.Glob(WebpCachedImgPath) matches, err := filepath.Glob(WebpCachedImgPath)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())