Replace tmdb-* URL routing with resolveTitle/resolvePerson server actions

- Add `resolveTitle` and `resolvePerson` server actions that import
  from TMDB and return the internal DB id
- Remove `tmdb-{id}-{type}` URL pattern and server-side redirect logic
  from TitleDetailPage and PersonDetailPage
- Rename `importTitle` → `getOrFetchTitleByTmdbId`; add `getOrFetchTitle`
  combining fetch + children lookup
- Update HeroBanner, TitleCard, and CommandPalette to call resolve
  actions client-side before pushing to router
- Batch availability offer inserts into a single transaction
This commit is contained in:
2026-03-07 14:27:03 -05:00
parent ccd482db4e
commit 8a45aa1c36
17 changed files with 552 additions and 419 deletions
+24 -20
View File
@@ -20,8 +20,26 @@ export async function refreshAvailability(titleId: string) {
const now = new Date();
const offerTypes = ["flatrate", "rent", "buy", "free", "ads"] as const;
// Collect all offer rows, then batch insert in a single transaction
const allOfferRows: (typeof availabilityOffers.$inferInsert)[] = [];
for (const offerType of offerTypes) {
const providers = us[offerType];
if (!providers) continue;
for (const p of providers) {
allOfferRows.push({
titleId,
region: "US",
providerId: p.provider_id,
providerName: p.provider_name,
logoPath: p.logo_path,
offerType,
link: us.link ?? null,
lastFetchedAt: now,
});
}
}
db.transaction((tx) => {
// Delete existing offers for this title+region
tx.delete(availabilityOffers)
.where(
and(
@@ -31,25 +49,11 @@ export async function refreshAvailability(titleId: string) {
)
.run();
for (const offerType of offerTypes) {
const providers = us[offerType];
if (!providers) continue;
for (const p of providers) {
tx.insert(availabilityOffers)
.values({
titleId,
region: "US",
providerId: p.provider_id,
providerName: p.provider_name,
logoPath: p.logo_path,
offerType,
link: us.link ?? null,
lastFetchedAt: now,
})
.onConflictDoNothing()
.run();
}
if (allOfferRows.length > 0) {
tx.insert(availabilityOffers)
.values(allOfferRows)
.onConflictDoNothing()
.run();
}
});