feat(admin): archived-items page with purge dates, restore, and purge

Admins need to see what the archive lifecycle is holding: a dedicated
/admin/archived page listing every hidden item (archived or still in
the missing grace window) with library, file path, status, and - when
retention is enabled - the exact date it will be permanently deleted
(archived_at + ARCHIVE_RETENTION_DAYS).

Per row: Restore (POST /api/media-items/:id/unarchive, clears the
archive state so it reappears; if the file is still gone the next scan
hides it again) and Delete (existing DELETE endpoint for single-row
purge with its reading history). Purge All Archived reuses the existing
bulk button. The library admin banner links to the page and keeps its
purge button; row actions use data attributes with delegated listeners
in admin.ts since this templ version has no JSFunctionCall helper.

Verified live: page 200 with purge dates shown, unarchive returned 204
and reset the row, per-item delete and bulk purge ({purged:1}) both
removed their rows with no leftovers.
This commit is contained in:
John O'Keefe
2026-09-13 12:01:05 -04:00
parent fe5ab9e5f8
commit aac7c72900
8 changed files with 529 additions and 43 deletions
+48
View File
@@ -849,6 +849,54 @@ func registerFrontendRoutes(cfg *Config) {
return c.HTML(http.StatusOK, buf.String())
}))
frontendProtected.GET("/admin/archived", handlers.AdminMiddleware(func(c *echo.Context) error {
user, err := getTemplateUserWithTheme(c, cfg)
if err != nil {
return renderErrorPage(c, "Error loading user", "user_load_error")
}
rows, err := cfg.Queries.ListHiddenMediaItems(c.Request().Context())
if err != nil {
log.Printf("ListHiddenMediaItems failed: %v", err)
rows = []database.ListHiddenMediaItemsRow{}
}
retentionDays := config.ArchiveRetentionDays()
items := make([]templates.ArchivedItem, 0, len(rows))
for _, row := range rows {
itemUUID, _ := uuid.FromBytes(row.ID.Bytes[0:16])
item := templates.ArchivedItem{
ID: itemUUID.String(),
Title: row.Title,
Author: getText(row.Author),
LibraryName: row.LibraryName,
FilePath: row.FilePath,
MissingScans: row.MissingScanCount,
}
if row.ArchivedAt.Valid {
archived := row.ArchivedAt.Time
item.ArchivedAt = &archived
switch {
case retentionDays <= 0:
item.Status = "Archived - kept until manually purged (retention disabled)"
default:
purge := archived.AddDate(0, 0, retentionDays)
item.PurgeAt = &purge
item.Status = "Archived - permanently deleted " + purge.Format("Jan 2, 2006")
}
} else {
item.Status = fmt.Sprintf("Missing from disk - archives on the next scan (%d/2)", row.MissingScanCount)
}
items = append(items, item)
}
var buf bytes.Buffer
if err := templates.AdminArchived(user, items, retentionDays).Render(c.Request().Context(), &buf); err != nil {
return err
}
return c.HTML(http.StatusOK, buf.String())
}))
frontendProtected.GET("/admin/library", handlers.AdminMiddleware(func(c *echo.Context) error {
user, err := getTemplateUserWithTheme(c, cfg)
if err != nil {
+1
View File
@@ -63,6 +63,7 @@ func registerMediaRoutes(cfg *Config) {
admin.POST("/media-items/:id/rescan", cfg.MediaHandler.RescanMediaItem)
admin.DELETE("/media-items/:id", cfg.MediaHandler.DeleteMediaItem)
admin.POST("/media-items/purge-archived", cfg.MediaHandler.PurgeArchivedMediaItems)
admin.POST("/media-items/:id/unarchive", cfg.MediaHandler.UnarchiveMediaItem)
// Shelf management (protected)
protected.POST("/devices/:id/shelves", cfg.MediaHandler.AddToShelf)