mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Rework original handling in seeding
This commit is contained in:
parent
b69cb05088
commit
67dc251489
@ -28,6 +28,7 @@ export const insertCollection = async (
|
||||
endAir: show.kind === "movie" ? show.airDate : show.endAir,
|
||||
nextRefresh: show.nextRefresh,
|
||||
entriesCount: 0,
|
||||
original: {} as any,
|
||||
...col,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { t } from "elysia";
|
||||
import type { SeedMovie } from "~/models/movie";
|
||||
import { getYear } from "~/utils";
|
||||
import { processOptImage } from "./images";
|
||||
import { insertCollection } from "./insert/collection";
|
||||
import { insertEntries } from "./insert/entries";
|
||||
import { insertShow, updateAvailableCount } from "./insert/shows";
|
||||
@ -45,8 +46,8 @@ export const seedMovie = async (
|
||||
seed.slug = `random-${getYear(seed.airDate)}`;
|
||||
}
|
||||
|
||||
const { translations, videos, collection, studios, ...bMovie } = seed;
|
||||
const nextRefresh = guessNextRefresh(bMovie.airDate ?? new Date());
|
||||
const { translations, videos, collection, studios, ...movie } = seed;
|
||||
const nextRefresh = guessNextRefresh(movie.airDate ?? new Date());
|
||||
|
||||
const col = await insertCollection(collection, {
|
||||
kind: "movie",
|
||||
@ -54,14 +55,24 @@ export const seedMovie = async (
|
||||
...seed,
|
||||
});
|
||||
|
||||
const original = translations[movie.originalLanguage];
|
||||
const show = await insertShow(
|
||||
{
|
||||
kind: "movie",
|
||||
startAir: bMovie.airDate,
|
||||
startAir: movie.airDate,
|
||||
nextRefresh,
|
||||
collectionPk: col?.pk,
|
||||
entriesCount: 1,
|
||||
...bMovie,
|
||||
original: {
|
||||
language: movie.originalLanguage,
|
||||
name: original.name,
|
||||
latinName: original.latinName ?? null,
|
||||
poster: processOptImage(original.poster),
|
||||
thumbnail: processOptImage(original.thumbnail),
|
||||
logo: processOptImage(original.logo),
|
||||
banner: processOptImage(original.banner),
|
||||
},
|
||||
...movie,
|
||||
},
|
||||
translations,
|
||||
);
|
||||
@ -70,11 +81,11 @@ export const seedMovie = async (
|
||||
// even if never shown to the user, a movie still has an entry.
|
||||
const [entry] = await insertEntries(show, [
|
||||
{
|
||||
...bMovie,
|
||||
...movie,
|
||||
kind: "movie",
|
||||
order: 1,
|
||||
thumbnail: (bMovie.originalLanguage
|
||||
? translations[bMovie.originalLanguage]
|
||||
thumbnail: (movie.originalLanguage
|
||||
? translations[movie.originalLanguage]
|
||||
: Object.values(translations)[0]
|
||||
)?.thumbnail,
|
||||
translations,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { t } from "elysia";
|
||||
import type { SeedSerie } from "~/models/serie";
|
||||
import { getYear } from "~/utils";
|
||||
import { processOptImage } from "./images";
|
||||
import { insertCollection } from "./insert/collection";
|
||||
import { insertEntries } from "./insert/entries";
|
||||
import { insertSeasons } from "./insert/seasons";
|
||||
@ -89,12 +90,22 @@ export const seedSerie = async (
|
||||
...seed,
|
||||
});
|
||||
|
||||
const original = translations[serie.originalLanguage];
|
||||
const show = await insertShow(
|
||||
{
|
||||
kind: "serie",
|
||||
nextRefresh,
|
||||
collectionPk: col?.pk,
|
||||
entriesCount: entries.length,
|
||||
original: {
|
||||
language: serie.originalLanguage,
|
||||
name: original.name,
|
||||
latinName: original.latinName ?? null,
|
||||
poster: processOptImage(original.poster),
|
||||
thumbnail: processOptImage(original.thumbnail),
|
||||
logo: processOptImage(original.logo),
|
||||
banner: processOptImage(original.banner),
|
||||
},
|
||||
...serie,
|
||||
},
|
||||
translations,
|
||||
|
@ -5,6 +5,7 @@ import {
|
||||
date,
|
||||
index,
|
||||
integer,
|
||||
jsonb,
|
||||
primaryKey,
|
||||
smallint,
|
||||
text,
|
||||
@ -12,6 +13,7 @@ import {
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import type { Image, Original } from "~/models/utils";
|
||||
import { entries } from "./entries";
|
||||
import { seasons } from "./seasons";
|
||||
import { showStudioJoin } from "./studios";
|
||||
@ -54,6 +56,13 @@ export const genres = schema.enum("genres", [
|
||||
"talk",
|
||||
]);
|
||||
|
||||
type OriginalWithImages = Original & {
|
||||
poster: Image | null;
|
||||
thumbnail: Image | null;
|
||||
banner: Image | null;
|
||||
logo: Image | null;
|
||||
};
|
||||
|
||||
export const shows = schema.table(
|
||||
"shows",
|
||||
{
|
||||
@ -67,7 +76,7 @@ export const shows = schema.table(
|
||||
status: showStatus().notNull(),
|
||||
startAir: date(),
|
||||
endAir: date(),
|
||||
originalLanguage: language(),
|
||||
original: jsonb().$type<OriginalWithImages>().notNull(),
|
||||
|
||||
collectionPk: integer().references((): AnyPgColumn => shows.pk, {
|
||||
onDelete: "set null",
|
||||
@ -120,16 +129,8 @@ export const showTranslations = schema.table(
|
||||
],
|
||||
);
|
||||
|
||||
export const showsRelations = relations(shows, ({ many, one }) => ({
|
||||
selectedTranslation: many(showTranslations, {
|
||||
relationName: "selected_translation",
|
||||
}),
|
||||
export const showsRelations = relations(shows, ({ many }) => ({
|
||||
translations: many(showTranslations, { relationName: "show_translations" }),
|
||||
originalTranslation: one(showTranslations, {
|
||||
relationName: "original_translation",
|
||||
fields: [shows.pk, shows.originalLanguage],
|
||||
references: [showTranslations.pk, showTranslations.language],
|
||||
}),
|
||||
entries: many(entries, { relationName: "show_entries" }),
|
||||
seasons: many(seasons, { relationName: "show_seasons" }),
|
||||
studios: many(showStudioJoin, { relationName: "ssj_show" }),
|
||||
@ -140,14 +141,4 @@ export const showsTrRelations = relations(showTranslations, ({ one }) => ({
|
||||
fields: [showTranslations.pk],
|
||||
references: [shows.pk],
|
||||
}),
|
||||
selectedTranslation: one(shows, {
|
||||
relationName: "selected_translation",
|
||||
fields: [showTranslations.pk],
|
||||
references: [shows.pk],
|
||||
}),
|
||||
originalTranslation: one(shows, {
|
||||
relationName: "original_translation",
|
||||
fields: [showTranslations.pk, showTranslations.language],
|
||||
references: [shows.pk, shows.originalLanguage],
|
||||
}),
|
||||
}));
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { jsonb, pgSchema, varchar } from "drizzle-orm/pg-core";
|
||||
import type { Image } from "~/models/utils";
|
||||
|
||||
export const schema = pgSchema("kyoo");
|
||||
|
||||
export const language = () => varchar({ length: 255 });
|
||||
|
||||
export const image = () =>
|
||||
jsonb().$type<{ id: string; source: string; blurhash: string }>();
|
||||
export const image = () => jsonb().$type<Image>();
|
||||
|
||||
export const externalid = () =>
|
||||
jsonb()
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
SeedImage,
|
||||
TranslationRecord,
|
||||
} from "./utils";
|
||||
import { Original } from "./utils/orignial";
|
||||
import { Original } from "./utils/original";
|
||||
import { Video } from "./video";
|
||||
|
||||
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
SeedImage,
|
||||
TranslationRecord,
|
||||
} from "./utils";
|
||||
import { Original } from "./utils/orignial";
|
||||
import { Original } from "./utils/original";
|
||||
|
||||
export const SerieStatus = t.UnionEnum([
|
||||
"unknown",
|
||||
|
@ -8,3 +8,4 @@ export * from "./page";
|
||||
export * from "./sort";
|
||||
export * from "./keyset-paginate";
|
||||
export * from "./db-metadata";
|
||||
export * from "./original";
|
||||
|
Loading…
x
Reference in New Issue
Block a user