Files
silo-server/internal/models/library_collection.go
T
QuickandClaude Opus 5 d8faf83c6e fix(settings): make the settings contract enforceable and fix the appearance cache
The contract manifest landed as a document nothing checked. This makes it a
mechanism, and fixes the one defect in the change set that hurt users on merge
rather than at cutover.

Web appearance cache. useTheme cleared the cache for any account whose stamp
did not match and never repopulated it — the only writers were the four
user-action setters — so every upgrading user lost their warm start on every
load, not once, and x-large-text and high-contrast users lost theirs too. The
owner-stamp protocol is replaced with per-account key namespacing
(`silo-theme:7`): a foreign value is absent rather than present-and-distrusted,
so nothing has to be deleted, the first account keeps its warm start, and there
is no shared stamp for a second tab, a stale debounce timer, or an out-of-order
effect to race on. Widening ownership to profile scope, which this manifest
requires, is now a change to appearanceCacheOwner alone. Adds the API-to-cache
mirror useTheme was missing, cancels pending debounced writes across an account
change, and re-seeds provider state during render so no frame paints the
previous account's look.

Canonicalization. writeCanonical used json.Marshal, which HTML-escapes < > and
&, and canonicalNumber used Go's 'g' format — both diverge from RFC 8785, so
the first label containing an ampersand or bound below 1e-4 would have forked
the server's ETag from every conforming client. Output is now byte-identical to
ECMAScript String() across the edge cases, verified against node. The ETag also
covers the value schemas, which decide what the server accepts and previously
could change while the tag stood still. All four derived representations are
memoized; a conditional GET no longer costs a full parse and re-serialize.

Validation. strictUnmarshal's decoder.More() answered false for a stray ] or },
so `true]` validated as a boolean. Enum matching compared fmt.Sprintf tokens, so
the string "3" satisfied an integer member. Declared steps were never enforced.
The language pattern rejected tags both mobile platforms emit unprompted
(en_US, ca-ES-valencia, ar-EG-u-nu-latn) and never normalized case, so en-US and
en-us were two rows for one preference; NormalizeValue now canonicalizes on the
shared path.

Manifest. show_forced_subtitles defaulted false where the server column is NOT
NULL DEFAULT true, which would have turned forced subtitles off for every
profile that never touched it. preferred_quality declared 13 members where the
planner speaks 6 and collapses the rest to auto. metadata_language's allowlist
was bound to the very column it migrates from. subtitle-appearance pinned
fontFamily to three families while Apple stores any installed system font.
Registers five user-facing settings the clients already ship, and corrects three
notes that described Android behaviour that was not true.

Enforcement. The package had no non-test callers, so MustLoad never ran; it now
loads and logs at startup. The inventory test compared the manifest against a
hand-copied map and could not see the drift it named; it now iterates
settingsRegistry and checks defaults too — both verified to fail on injected
drift. Adds .github/workflows/ci.yml, the repo's first CI that runs go test,
go vet, gofmt, and the frontend suite. Known pre-existing failures are named
individually in the Makefile so everything else stays gated and the list can
only shrink.

Part of #135

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 15:24:33 +00:00

106 lines
2.9 KiB
Go

package models
import (
"encoding/json"
"time"
)
// LibraryCollection is an admin-managed collection scoped to one or more libraries.
type LibraryCollection struct {
ID string
LibraryID int
LibraryIDs []int
Slug string
Title string
Description string
CollectionType string
Visibility string
SortOrder int
GroupID *string
Featured bool
PosterURL string
BackdropURL string
PosterThumbhash string
BackdropThumbhash string
PosterAutoGenerated bool
// PosterFromTemplate flags posters set by a template bundle apply.
// ensureTemplatePoster sets this true; the guard treats template-origin
// posters as refreshable so template poster updates propagate, while
// admin-uploaded posters (PosterAutoGenerated=false AND PosterFromTemplate=false)
// remain sticky.
PosterFromTemplate bool
SourceURL string
QueryDefinition json.RawMessage
SortConfig json.RawMessage
SourceConfig json.RawMessage
ManagementMode string
ManagementSource string
ManagementKey string
LastSyncStatus string
LastSyncMessage string
LastSyncAt *time.Time
SyncSchedule *string
NextSyncAt *time.Time
ItemCount int
CreatedAt time.Time
UpdatedAt time.Time
}
type LibraryCollectionGroupKind string
const (
GroupKindRegular LibraryCollectionGroupKind = "regular"
GroupKindUserCollections LibraryCollectionGroupKind = "user_collections"
)
type GroupSortMode string
const (
GroupSortManual GroupSortMode = "manual"
GroupSortNameAsc GroupSortMode = "name_asc"
GroupSortNameDesc GroupSortMode = "name_desc"
GroupSortRecent GroupSortMode = "recent"
GroupSortMostItems GroupSortMode = "most_items"
)
// LibraryCollectionGroup is a per-library bucket that groups collections in the
// gallery view. Collections without a group_id fall into the implicit
// "Ungrouped" section that lives outside this table.
type LibraryCollectionGroup struct {
ID string
LibraryID int
Name string
Slug string
Kind LibraryCollectionGroupKind
DefaultSortMode GroupSortMode
SortOrder int
CreatedAt time.Time
UpdatedAt time.Time
}
// LibraryCollectionItem is a resolved membership entry for a library collection.
type LibraryCollectionItem struct {
CollectionID string
MediaItemID string
Position int
SourceRank int
CreatedAt time.Time
UpdatedAt time.Time
}
// LibraryCollectionSyncRun captures the outcome of a collection sync/import run.
type LibraryCollectionSyncRun struct {
ID string
CollectionID string
Status string
Message string
ItemsAdded int
ItemsRemoved int
ItemsMatched int
ItemsUnmatched int
Warnings json.RawMessage
StartedAt *time.Time
CompletedAt *time.Time
CreatedAt time.Time
}