fix: wire security headers, graceful shutdown, and settings invalidation
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.
This commit is contained in:
1 parent
8631aa00bf
commit
a716b386a1
10 files changed
+98
-195
No files matched your search
@@ -1550,7 +1550,7 @@ func (mh *MediaHandler) UpdateMediaItem(c *echo.Context) error {
|
||||
} else if req.CoverAction == "upload" {
|
||||
file, err := c.FormFile("cover_file")
|
||||
if err == nil {
|
||||
savedPath, err := mh.saveCoverImage(*c, mediaUUID, file)
|
||||
savedPath, err := mh.saveCoverImage(c, mediaUUID, file)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to save cover image"})
|
||||
}
|
||||
@@ -2876,7 +2876,7 @@ func jsonBytesToMap(b []byte) map[string]interface{} {
|
||||
return result
|
||||
}
|
||||
|
||||
func (mh *MediaHandler) saveCoverImage(c echo.Context, mediaUUID uuid.UUID, file *multipart.FileHeader) (string, error) {
|
||||
func (mh *MediaHandler) saveCoverImage(c *echo.Context, mediaUUID uuid.UUID, file *multipart.FileHeader) (string, error) {
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to open uploaded file: %w", err)
|
||||
@@ -3030,7 +3030,8 @@ func (mh *MediaHandler) GetAudioChapters(c *echo.Context) error {
|
||||
// SetAudioSpeed handles PUT /api/media-items/:id/audio-speed — the
|
||||
// per-user per-book playback speed upsert (plan §8). The client SPEEDS
|
||||
// list is the real gate; the server sanity-checks the range.
|
||||
func (mh *MediaHandler) SetAudioSpeed(c *echo.Context) error { mediaID := c.Param("id")
|
||||
func (mh *MediaHandler) SetAudioSpeed(c *echo.Context) error {
|
||||
mediaID := c.Param("id")
|
||||
mediaUUID, err := uuid.Parse(mediaID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid media item id"})
|
||||
|
||||
Reference in new issue
Block a user