From f4b1f883607094a162079fc7f88a20303ce7b045 Mon Sep 17 00:00:00 2001 From: XOF Date: Sat, 29 Nov 2025 03:33:46 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20=EF=BC=9A=E6=9B=B4=E6=96=B0=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0e88a16..4bb0d55 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ type Task struct { InStock bool `json:"in_stock"` LastCheck time.Time `json:"last_check"` Status string `json:"status"` + Notified bool `json:"notified"` } type Config struct { @@ -32,11 +33,12 @@ type Config struct { GotifyToken string `json:"gotify_token"` Interval int `json:"interval"` Timeout int `json:"timeout"` + NotifyEnabled bool `json:"notify_enabled"` } var ( tasks = make(map[string]*Task) - config = &Config{Interval: 60, Timeout: 20} + config = &Config{Interval: 60, Timeout: 20, NotifyEnabled: true} mu sync.RWMutex configMu sync.RWMutex authToken = os.Getenv("AUTH_TOKEN") @@ -211,6 +213,9 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {

系统设置

+
@@ -286,8 +291,8 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { '' + stockText + '' + '' + lastCheck + '' + '' + - '' + - '' + + '' + + '' + ''; }).join(''); }); @@ -315,6 +320,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { document.getElementById('gotifyToken').value = cfg.gotify_token || ''; document.getElementById('interval').value = cfg.interval || 60; document.getElementById('timeout').value = cfg.timeout || 20; + document.getElementById('notifyEnabled').checked = cfg.notify_enabled !== false; document.getElementById('configModal').classList.add('show'); }); } @@ -379,7 +385,8 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { gotify_url: document.getElementById('gotifyUrl').value, gotify_token: document.getElementById('gotifyToken').value, interval: parseInt(document.getElementById('interval').value), - timeout: parseInt(document.getElementById('timeout').value) + timeout: parseInt(document.getElementById('timeout').value), + notify_enabled: document.getElementById('notifyEnabled').checked }; fetch('/api/config', { method: 'POST', @@ -495,15 +502,27 @@ func checkTask(task *Task) { mu.Lock() wasInStock := task.InStock + wasNotified := task.Notified task.Status = status task.InStock = inStock task.LastCheck = now + + if !inStock { + task.Notified = false + } mu.Unlock() - saveTasks() - if inStock && !wasInStock { + configMu.RLock() + notifyEnabled := config.NotifyEnabled + configMu.RUnlock() + + if notifyEnabled && inStock && !wasInStock && !wasNotified { notify(task.Name + " 有货了!", task.URL) + mu.Lock() + task.Notified = true + mu.Unlock() + saveTasks() } }