[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", "name": "cosmos-server",
"version": "0.5.0-unstable23", "version": "0.5.0-unstable24",
"description": "", "description": "",
"main": "test-server.js", "main": "test-server.js",
"bugs": { "bugs": {

View file

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