* fix(collections): repair broken builtin collection templates A live audit of the builtin template catalog (all 40 MDBList URLs and all 10 TMDB franchise IDs fetched) found two dead sources, a silent bundle-apply collision, and several templates whose defaults contradict their descriptions: - Repoint mdblist_misc_a24 and mdblist_misc_criterion_collection to live lists; the original irvingbeano/shtluck lists were deleted on MDBList (404), so every sync of those collections failed. - Retitle mdblist_charts_popular_movies to "IMDb MovieMeter Top 100". It shared the "popular-movies" title slug with tmdb_popular_movies, and bundle apply dedupes by slug per library, so applying all_defaults silently skipped it. Poster regenerated from the raw plate with the new title; new handler test asserts builtin title slugs stay unique. - Raise the shared default limit 50 -> 100, give the IMDb Top 250 templates an explicit 250 (limit*4 fetch trim previously never scanned entries 201-250), and drop the limit on catalog lists (Criterion, A24) so they hold every owned title. - Correct IFC Films to MediaMovie (live list is 100% movies; as MediaMixed it was offered to TV libraries where it always synced empty) and fix the Trakt Popular descriptions (ratings-based, not "most-watched"). - Update stale limit docs in collection-templates.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(collections): raise import limit caps above IMDb Top 250 default The IMDb Top 250 templates now default to 250 items, but the template config forms rendered their Max Items input with max=200 and the user import API rejected limits above 200, so applying those templates from the direct galleries failed native validation or got a 400. Raise the cap to 500 on both sides, wired to shared constants: sync's fetch trim (collectionSourceFetchMax) never scans more than 500 source entries, so a larger explicit limit could never be satisfied anyway. collectionutil.MaxExplicitItemLimit backs validateOptionalLimit, and COLLECTION_MAX_ITEMS in lib/collectionTemplates backs all seven Max Items inputs (gallery forms + admin import/editor dialogs). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package collectionutil
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
var ErrOrderedIDsMismatch = errors.New("ordered_ids does not match the current set")
|
|
|
|
const (
|
|
collectionSourceFetchMultiplier = 4
|
|
collectionSourceFetchMin = 100
|
|
collectionSourceFetchMax = 500
|
|
)
|
|
|
|
// MaxExplicitItemLimit is the largest explicit per-collection item limit the
|
|
// import APIs accept. Sync never scans more than collectionSourceFetchMax
|
|
// source entries, so a larger explicit limit could never be satisfied anyway.
|
|
// Mirrored by COLLECTION_MAX_ITEMS in web/src/lib/collectionTemplates.ts.
|
|
const MaxExplicitItemLimit = collectionSourceFetchMax
|
|
|
|
func SourceFetchLimit(itemLimit *int) int {
|
|
if itemLimit == nil || *itemLimit <= 0 {
|
|
return 0
|
|
}
|
|
limit := *itemLimit * collectionSourceFetchMultiplier
|
|
if limit < collectionSourceFetchMin {
|
|
limit = collectionSourceFetchMin
|
|
}
|
|
if limit > collectionSourceFetchMax {
|
|
limit = collectionSourceFetchMax
|
|
}
|
|
return limit
|
|
}
|
|
|
|
func ItemLimitReached(itemCount int, itemLimit *int) bool {
|
|
return itemLimit != nil && *itemLimit > 0 && itemCount >= *itemLimit
|
|
}
|
|
|
|
func HasDuplicateOrderedIDs(ids []string) bool {
|
|
seen := make(map[string]struct{}, len(ids))
|
|
for _, id := range ids {
|
|
if _, ok := seen[id]; ok {
|
|
return true
|
|
}
|
|
seen[id] = struct{}{}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func SlugifyGroupSlug(s string) string {
|
|
s = strings.ToLower(strings.TrimSpace(s))
|
|
var b strings.Builder
|
|
prevDash := false
|
|
for _, r := range s {
|
|
switch {
|
|
case (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9'):
|
|
b.WriteRune(r)
|
|
prevDash = false
|
|
case r == ' ' || r == '-' || r == '_':
|
|
if !prevDash && b.Len() > 0 {
|
|
b.WriteRune('-')
|
|
prevDash = true
|
|
}
|
|
}
|
|
}
|
|
out := strings.Trim(b.String(), "-")
|
|
if out == "" {
|
|
return "group"
|
|
}
|
|
return out
|
|
}
|