From ccb0989d07db2fe4ade12de38c15efe2b6cea332 Mon Sep 17 00:00:00 2001 From: dragonish Date: Mon, 2 Sep 2024 21:57:21 +0800 Subject: [PATCH] feat(icons): set cache fields for icons response --- internal/pages/main.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/pages/main.go b/internal/pages/main.go index cb062f1..ba74db3 100644 --- a/internal/pages/main.go +++ b/internal/pages/main.go @@ -53,12 +53,24 @@ func Pages(router *gin.Engine) { router.LoadHTMLFiles(htmlTemplates...) iconsFs, _ := fs.Sub(mFs, MEM_ICONS_DIR) - router.StaticFS("/assets/icons", http.FS(iconsFs)) - router.StaticFS("/assets/uploads", gin.Dir(model.UPLOAD_FILES_PATH, false)) + uploadsFs := gin.Dir(model.UPLOAD_FILES_PATH, false) + router.Static("/assets/js", model.JS_PATH) router.Static("/assets/css", model.CSS_PATH) router.Static("/manager-assets", model.MANAGER_PATH+"/manager-assets") + router.GET("/assets/icons/*filepath", func(ctx *gin.Context) { + filepath := ctx.Param("filepath") + setCacheHeader(ctx) + ctx.FileFromFS(filepath, http.FS(iconsFs)) + }) + + router.GET("/assets/uploads/*filepath", func(ctx *gin.Context) { + filepath := ctx.Param("filepath") + setCacheHeader(ctx) + ctx.FileFromFS(filepath, uploadsFs) + }) + home(router) login(router) logout(router)