Fix logo assets and license heartbeat

This commit is contained in:
ShukeBta
2026-06-17 23:30:31 +08:00
parent fb362e1fec
commit 29ac7765d2
11 changed files with 199 additions and 43 deletions
+7
View File
@@ -120,6 +120,7 @@ func main() {
}
}()
go services.Boot()
go handler.RunLicenseHeartbeatLoop(services.Context(), services)
go services.TelegramBot.StartPolling(context.Background())
// Graceful shutdown.
@@ -201,6 +202,12 @@ func serveSPA(r *gin.Engine, webDir string) {
c.Next()
})
assets.Static("/", filepath.Join(webDir, "assets"))
brand := r.Group("/brand")
brand.Use(func(c *gin.Context) {
c.Header("Cache-Control", "public, max-age=86400")
c.Next()
})
brand.Static("/", filepath.Join(webDir, "brand"))
for _, icon := range []string{"/favicon.ico", "/favicon.svg"} {
iconPath := filepath.Join(webDir, strings.TrimPrefix(icon, "/"))
r.GET(icon, serveNoCacheFile(iconPath))
+16
View File
@@ -52,12 +52,18 @@ func TestServeSPAServesAssetsImmutableAndBypassesAPIRoutes(t *testing.T) {
if err := os.MkdirAll(filepath.Join(webDir, "assets"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Join(webDir, "brand"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(webDir, "index.html"), []byte("index"), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(webDir, "assets", "app.js"), []byte("console.log('ok')"), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(webDir, "brand", "mediastationgo-logo.svg"), []byte("<svg></svg>"), 0o644); err != nil {
t.Fatal(err)
}
router := gin.New()
serveSPA(router, webDir)
@@ -72,6 +78,16 @@ func TestServeSPAServesAssetsImmutableAndBypassesAPIRoutes(t *testing.T) {
t.Fatalf("asset Cache-Control = %q, want immutable", got)
}
brandReq := httptest.NewRequest(http.MethodGet, "/brand/mediastationgo-logo.svg", nil)
brandResp := httptest.NewRecorder()
router.ServeHTTP(brandResp, brandReq)
if brandResp.Code != http.StatusOK {
t.Fatalf("brand asset status = %d, want 200", brandResp.Code)
}
if strings.Contains(brandResp.Body.String(), "index") {
t.Fatalf("brand asset should not serve SPA index: %q", brandResp.Body.String())
}
for _, path := range []string{
"/api/missing",
"/emby",