Added favicons (iconset && auto-detection)

This commit is contained in:
2023-12-23 23:52:53 +01:00
parent c38afc6ef3
commit 8eed2ca69f
32 changed files with 576 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package handler
import (
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
bunny "locbunny"
"locbunny/logic"
@@ -45,3 +46,33 @@ func (h APIHandler) ListServer(pctx ginext.PreContext) ginext.HTTPResponse {
return ginext.JSON(http.StatusOK, response{Servers: srvs})
}
// GetIcon swaggerdoc
//
// @Summary Get Icon
//
// @Param cs path number true "Icon Checksum"
//
// @Router /icon/:cs [GET]
func (h APIHandler) GetIcon(pctx ginext.PreContext) ginext.HTTPResponse {
type uri struct {
Checksum string `uri:"cs"`
}
var u uri
ctx, _, errResp := pctx.URI(&u).Start()
if errResp != nil {
return *errResp
}
defer ctx.Cancel()
icn := h.app.GetIcon(ctx, u.Checksum)
if icn == nil {
return ginext.Error(exerr.New(bunny.ErrEntityNotFound, "Icon not found").Str("cs", u.Checksum).WithStatuscode(404).Build())
}
return ginext.Data(200, icn.ContentType, icn.Data).
WithHeader("X-BUNNY-ICONID", icn.IconID.String()).
WithHeader("X-BUNNY-CHECKSUM", icn.Checksum).
WithHeader("X-BUNNY-ICONDATE", icn.Time.String())
}

View File

@@ -64,6 +64,7 @@ func (r *Router) Init(e *ginext.GinWrapper) {
// ================ API ================
api.GET("/server").Handle(r.apiHandler.ListServer)
api.GET("/icon/:cs").Handle(r.apiHandler.GetIcon)
// ================ ================