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