From 7e38ab624a8a92c64c9fdf31cf57800277392b3c Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 1 Oct 2024 08:59:11 +0200 Subject: [PATCH 1/3] Update configuration.md --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 116f8da..6f9d602 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -852,7 +852,7 @@ Either a value from the table below or a URL to a custom search engine. Use `{QU ##### `new-tab` When set to `true`, swaps the shortcuts for showing results in the same or new tab, defaulting to showing results in a new tab. -##### `new-tab` +##### `autofocus` When set to `true`, automatically focuses the search input on page load. ##### `bangs` From ee94d6aa895cd2190fe1dd9ae2a72fd78a40872b Mon Sep 17 00:00:00 2001 From: Cody Meadows Date: Thu, 17 Oct 2024 21:58:18 +0000 Subject: [PATCH 2/3] Add alternative status code prameter --- docs/configuration.md | 10 ++++++++++ internal/widget/monitor.go | 14 ++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6f9d602..a2c7cbd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1082,6 +1082,7 @@ Properties for each site: | icon | string | no | | | allow-insecure | boolean | no | false | | same-tab | boolean | no | false | +| alt-status-codes | array | no | | `title` @@ -1117,6 +1118,15 @@ Whether to ignore invalid/self-signed certificates. 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 Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub. diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go index 06d7303..0ece553 100644 --- a/internal/widget/monitor.go +++ b/internal/widget/monitor.go @@ -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" } @@ -52,6 +53,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:"-"` @@ -92,8 +94,8 @@ func (widget *Monitor) Update(ctx context.Context) { } 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) } } } From 201b4ca1e87a7fa79fe56ef1bacecc4ff89666ae Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:51:46 +0100 Subject: [PATCH 3/3] Use AltStatusCodes for HasFailing check --- internal/widget/monitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go index 0ece553..581781c 100644 --- a/internal/widget/monitor.go +++ b/internal/widget/monitor.go @@ -89,7 +89,7 @@ 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 }