mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Add alternative status code prameter
This commit is contained in:
parent
d90d39933a
commit
ee94d6aa89
@ -1082,6 +1082,7 @@ Properties for each site:
|
|||||||
| icon | string | no | |
|
| icon | string | no | |
|
||||||
| allow-insecure | boolean | no | false |
|
| allow-insecure | boolean | no | false |
|
||||||
| same-tab | boolean | no | false |
|
| same-tab | boolean | no | false |
|
||||||
|
| alt-status-codes | array | no | |
|
||||||
|
|
||||||
`title`
|
`title`
|
||||||
|
|
||||||
@ -1117,6 +1118,15 @@ Whether to ignore invalid/self-signed certificates.
|
|||||||
|
|
||||||
Whether to open the link in the same or a new tab.
|
Whether to open the link in the same or a new tab.
|
||||||
|
|
||||||
|
`alt-status-codes`
|
||||||
|
|
||||||
|
Status codes other than 200 that you want to return "OK".
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
alt-status-codes:
|
||||||
|
- 403
|
||||||
|
```
|
||||||
|
|
||||||
### Releases
|
### Releases
|
||||||
Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub.
|
Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub.
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package widget
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -10,8 +11,8 @@ import (
|
|||||||
"github.com/glanceapp/glance/internal/feed"
|
"github.com/glanceapp/glance/internal/feed"
|
||||||
)
|
)
|
||||||
|
|
||||||
func statusCodeToText(status int) string {
|
func statusCodeToText(status int, altStatusCodes []int) string {
|
||||||
if status == 200 {
|
if status == 200 || slices.Contains(altStatusCodes, status) {
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
if status == 404 {
|
if status == 404 {
|
||||||
@ -33,8 +34,8 @@ func statusCodeToText(status int) string {
|
|||||||
return strconv.Itoa(status)
|
return strconv.Itoa(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusCodeToStyle(status int) string {
|
func statusCodeToStyle(status int, altStatusCodes []int) string {
|
||||||
if status == 200 {
|
if status == 200 || slices.Contains(altStatusCodes, status) {
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ type Monitor struct {
|
|||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
StatusText string `yaml:"-"`
|
StatusText string `yaml:"-"`
|
||||||
StatusStyle string `yaml:"-"`
|
StatusStyle string `yaml:"-"`
|
||||||
|
AltStatusCodes []int `yaml:"alt-status-codes"`
|
||||||
} `yaml:"sites"`
|
} `yaml:"sites"`
|
||||||
ShowFailingOnly bool `yaml:"show-failing-only"`
|
ShowFailingOnly bool `yaml:"show-failing-only"`
|
||||||
HasFailing bool `yaml:"-"`
|
HasFailing bool `yaml:"-"`
|
||||||
@ -92,8 +94,8 @@ func (widget *Monitor) Update(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !status.TimedOut {
|
if !status.TimedOut {
|
||||||
site.StatusText = statusCodeToText(status.Code)
|
site.StatusText = statusCodeToText(status.Code, site.AltStatusCodes)
|
||||||
site.StatusStyle = statusCodeToStyle(status.Code)
|
site.StatusStyle = statusCodeToStyle(status.Code, site.AltStatusCodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user