Compare commits

..

No commits in common. "e392e7ba8b04987b99cee0b733a0773600fa6960" and "48599bac5f15e29be88ad7498ff67400570ef953" have entirely different histories.

10
main.go
View File

@ -23,17 +23,14 @@ import (
var content embed.FS var content embed.FS
var chrome *svg2png.Chrome
func main() { func main() {
chrome = svg2png.NewChrome().SetHeight(600).SetWith(1200).SetTimeout(10 * time.Second)
ch := cache.New(24*time.Hour, 48*time.Hour)
app := fiber.New() app := fiber.New()
app.Use(compress.New()) app.Use(compress.New())
app.Use(cors.New()) app.Use(cors.New())
app.Use(logger.New()) app.Use(logger.New())
ch := cache.New(6*time.Hour, 24*time.Hour)
app.Get("/", func(c *fiber.Ctx) error { app.Get("/", func(c *fiber.Ctx) error {
c.Type("html", "UTF8") c.Type("html", "UTF8")
body, _ := content.ReadFile("index.html") body, _ := content.ReadFile("index.html")
@ -63,7 +60,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return c.SendStatus(500) return c.SendStatus(500)
} }
ch.Set(key, png, cache.DefaultExpiration) ch.Set(key, png, 0)
} }
c.Type("png") c.Type("png")
@ -94,6 +91,7 @@ func generateImage(vars map[string]string) ([]byte, error) {
imageFile, err := os.CreateTemp(os.TempDir(), "img-*.png") imageFile, err := os.CreateTemp(os.TempDir(), "img-*.png")
chrome := svg2png.NewChrome().SetHeight(600).SetWith(1200).SetTimeout(10 * time.Second)
if err := chrome.Screenshoot(fmt.Sprintf("file://%s", file.Name()), imageFile.Name()); err != nil { if err := chrome.Screenshoot(fmt.Sprintf("file://%s", file.Name()), imageFile.Name()); err != nil {
return nil, err return nil, err
} }