Lifecycle (internal/app + main.go): - App.OnShutdown hooks run after the HTTP server drains, in registration order: Worker.Shutdown (background jobs now drain instead of dying on SIGTERM), DeviceAuthMiddleware.Stop (releases the rate-limiter ticker), Handler.CloseScanner (fsnotify watcher and scan log files) Security headers: - SecurityHeadersMiddleware (survivor of middleware/security.go, renamed security_headers.go) is now on the echo stack: nosniff, frame-deny, HSTS, CSP (unsafe-inline required by the sanctioned theme flash guard + Alpine), referrer and permissions policy Scanner settings cache: - settings saves (UpdateScanSettings + ApplySetting for the three scan keys) now invalidate MediaScanner's 30s settings cache via SystemSettingsHandler.SetScanSettingsChanged, so changes apply on the next poll instead of after the TTL - MediaScanner.Close closes the scan logger, fixing a file-descriptor leak on every per-item rescan (fresh scanners never closed logs) Client fix: - custom-section-builder's add/remove-selection buttons used inline onclick attributes referencing module-scoped functions, which are not global in a bundled ES module: the buttons threw ReferenceError. Functions restored and exposed on window via declare global Also fixes a pre-existing vet error (saveCoverImage copied echo.Context by value, mutex included) and drops the per-key SettingsCache.InvalidateKey variant left callerless by the full-flush invalidation wiring.
51 lines
854 B
Go
51 lines
854 B
Go
package services
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type SettingsCache struct {
|
|
data map[string]string
|
|
mu sync.RWMutex
|
|
ttl time.Duration
|
|
lastUpdate time.Time
|
|
}
|
|
|
|
func NewSettingsCache(ttl time.Duration) *SettingsCache {
|
|
return &SettingsCache{
|
|
data: make(map[string]string),
|
|
ttl: ttl,
|
|
lastUpdate: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (c *SettingsCache) Get(key string) (string, bool) {
|
|
c.mu.RLock()
|
|
defer c.mu.RUnlock()
|
|
|
|
// Check if cache is expired
|
|
if time.Since(c.lastUpdate) > c.ttl {
|
|
return "", false
|
|
}
|
|
|
|
val, ok := c.data[key]
|
|
return val, ok
|
|
}
|
|
|
|
func (c *SettingsCache) Set(key, value string) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
|
|
c.data[key] = value
|
|
c.lastUpdate = time.Now()
|
|
}
|
|
|
|
func (c *SettingsCache) Invalidate() {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
|
|
c.data = make(map[string]string)
|
|
c.lastUpdate = time.Time{}
|
|
}
|