mirror of
https://github.com/Xevion/glance.git
synced 2025-12-14 14:11:52 -06:00
Merge branch 'release/v0.7.0' into main
This commit is contained in:
@@ -3,6 +3,7 @@ package widget
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -10,8 +11,8 @@ import (
|
||||
"github.com/glanceapp/glance/internal/feed"
|
||||
)
|
||||
|
||||
func statusCodeToText(status int) string {
|
||||
if status == 200 {
|
||||
func statusCodeToText(status int, altStatusCodes []int) string {
|
||||
if status == 200 || slices.Contains(altStatusCodes, status) {
|
||||
return "OK"
|
||||
}
|
||||
if status == 404 {
|
||||
@@ -33,8 +34,8 @@ func statusCodeToText(status int) string {
|
||||
return strconv.Itoa(status)
|
||||
}
|
||||
|
||||
func statusCodeToStyle(status int) string {
|
||||
if status == 200 {
|
||||
func statusCodeToStyle(status int, altStatusCodes []int) string {
|
||||
if status == 200 || slices.Contains(altStatusCodes, status) {
|
||||
return "ok"
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ type Monitor struct {
|
||||
SameTab bool `yaml:"same-tab"`
|
||||
StatusText string `yaml:"-"`
|
||||
StatusStyle string `yaml:"-"`
|
||||
AltStatusCodes []int `yaml:"alt-status-codes"`
|
||||
} `yaml:"sites"`
|
||||
ShowFailingOnly bool `yaml:"show-failing-only"`
|
||||
HasFailing bool `yaml:"-"`
|
||||
@@ -82,13 +84,13 @@ func (widget *Monitor) Update(ctx context.Context) {
|
||||
status := &statuses[i]
|
||||
site.Status = status
|
||||
|
||||
if status.Code >= 400 || status.TimedOut || status.Error != nil {
|
||||
if !slices.Contains(site.AltStatusCodes, status.Code) && (status.Code >= 400 || status.TimedOut || status.Error != nil) {
|
||||
widget.HasFailing = true
|
||||
}
|
||||
|
||||
if !status.TimedOut {
|
||||
site.StatusText = statusCodeToText(status.Code)
|
||||
site.StatusStyle = statusCodeToStyle(status.Code)
|
||||
site.StatusText = statusCodeToText(status.Code, site.AltStatusCodes)
|
||||
site.StatusStyle = statusCodeToStyle(status.Code, site.AltStatusCodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user