[release] version 0.5.0-unstable24

This commit is contained in:
Yann Stepienik 2023-05-16 23:58:06 +01:00
parent aa0a4f8865
commit 7134301f64
2 changed files with 22 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.5.0-unstable23",
"version": "0.5.0-unstable24",
"description": "",
"main": "test-server.js",
"bugs": {

View file

@ -81,28 +81,38 @@ func GetFavicon(w http.ResponseWriter, req *http.Request) {
}
var icons []*favicon.Icon
var defaultIcons = []*favicon.Icon{
&favicon.Icon{URL: "favicon.png", Width: 0},
&favicon.Icon{URL: "/favicon.png", Width: 0},
&favicon.Icon{URL: "favicon.ico", Width: 0},
&favicon.Icon{URL: "/favicon.ico", Width: 0},
}
// follow siteurl and check if any redirect.
respNew, err := http.Get(siteurl)
if err != nil {
utils.Error("FaviconFetch", err)
icons = []*favicon.Icon{
&favicon.Icon{URL: "favicon.png", Width: 0},
&favicon.Icon{URL: "/favicon.png", Width: 0},
&favicon.Icon{URL: "favicon.ico", Width: 0},
&favicon.Icon{URL: "/favicon.ico", Width: 0},
}
icons = append(icons, defaultIcons...)
} else {
siteurl = respNew.Request.URL.String()
icons, err = favicon.Find(siteurl)
if err != nil || len(icons) == 0 {
icons = []*favicon.Icon{
&favicon.Icon{URL: "favicon.png", Width: 0},
&favicon.Icon{URL: "/favicon.png", Width: 0},
&favicon.Icon{URL: "favicon.ico", Width: 0},
&favicon.Icon{URL: "/favicon.ico", Width: 0},
icons = append(icons, defaultIcons...)
} else {
// Check if icons list is missing any default values
for _, defaultIcon := range defaultIcons {
found := false
for _, icon := range icons {
if icon.URL == defaultIcon.URL {
found = true
break
}
}
if !found {
icons = append(icons, defaultIcon)
}
}
}
}