chore: update url util routes name

This commit is contained in:
Steven
2023-06-28 22:20:55 +08:00
parent eee4976fba
commit bcb71f6631
3 changed files with 4 additions and 4 deletions

29
api/v1/url_util.go Normal file
View File

@@ -0,0 +1,29 @@
package v1
import (
"net/http"
"github.com/labstack/echo/v4"
"go.deanishe.net/favicon"
)
func (*APIV1Service) registerURLUtilRoutes(g *echo.Group) {
g.GET("/url/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)
})
}