mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-19 03:04:01 +00:00
chore: update url util routes name
This commit is contained in:
29
api/v1/url_util.go
Normal file
29
api/v1/url_util.go
Normal 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)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user