mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-03 20:21:40 +00:00
feat: add shortcut favicon
This commit is contained in:
29
api/v1/favicon.go
Normal file
29
api/v1/favicon.go
Normal file
@ -0,0 +1,29 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.deanishe.net/favicon"
|
||||
)
|
||||
|
||||
func (*APIV1Service) registerFaviconRoutes(g *echo.Group) {
|
||||
g.GET("/favicon", func(c echo.Context) error {
|
||||
url := c.QueryParam("url")
|
||||
icons, err := favicon.Find(url)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find favicon")
|
||||
}
|
||||
|
||||
availableIcons := []*favicon.Icon{}
|
||||
for _, icon := range icons {
|
||||
if icon.Width == icon.Height {
|
||||
availableIcons = append(availableIcons, icon)
|
||||
}
|
||||
}
|
||||
if len(availableIcons) == 0 {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "No favicon found")
|
||||
}
|
||||
return c.JSON(http.StatusOK, availableIcons[0].URL)
|
||||
})
|
||||
}
|
@ -24,6 +24,7 @@ func (s *APIV1Service) Start(apiGroup *echo.Group, secret string) {
|
||||
apiV1Group.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return JWTMiddleware(s, next, secret)
|
||||
})
|
||||
s.registerFaviconRoutes(apiV1Group)
|
||||
s.registerWorkspaceRoutes(apiV1Group)
|
||||
s.registerAuthRoutes(apiV1Group, secret)
|
||||
s.registerUserRoutes(apiV1Group)
|
||||
|
Reference in New Issue
Block a user