mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add progress in /series/:id?width=firstEntry
This commit is contained in:
parent
be2e5e5ccf
commit
31a749b5ed
@ -114,6 +114,7 @@ async function getEntries({
|
|||||||
sort,
|
sort,
|
||||||
filter,
|
filter,
|
||||||
languages,
|
languages,
|
||||||
|
userId,
|
||||||
}: {
|
}: {
|
||||||
after: string | undefined;
|
after: string | undefined;
|
||||||
limit: number;
|
limit: number;
|
||||||
@ -121,6 +122,7 @@ async function getEntries({
|
|||||||
sort: Sort;
|
sort: Sort;
|
||||||
filter: SQL | undefined;
|
filter: SQL | undefined;
|
||||||
languages: string[];
|
languages: string[];
|
||||||
|
userId: number;
|
||||||
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([entryTranslations.pk])
|
.selectDistinctOn([entryTranslations.pk])
|
||||||
@ -158,6 +160,7 @@ async function getEntries({
|
|||||||
videoId: videos.id,
|
videoId: videos.id,
|
||||||
})
|
})
|
||||||
.from(history)
|
.from(history)
|
||||||
|
.where(eq(history.profilePk, userId))
|
||||||
.leftJoin(videos, eq(history.videoPk, videos.pk))
|
.leftJoin(videos, eq(history.videoPk, videos.pk))
|
||||||
.orderBy(history.entryPk, desc(history.playedDate))
|
.orderBy(history.entryPk, desc(history.playedDate))
|
||||||
.as("progress");
|
.as("progress");
|
||||||
@ -176,9 +179,7 @@ async function getEntries({
|
|||||||
...entryCol,
|
...entryCol,
|
||||||
...transCol,
|
...transCol,
|
||||||
videos: videosQ.videos,
|
videos: videosQ.videos,
|
||||||
progress: {
|
progress: getColumns(progressQ),
|
||||||
...getColumns(progressQ),
|
|
||||||
},
|
|
||||||
// specials don't have an `episodeNumber` but a `number` field.
|
// specials don't have an `episodeNumber` but a `number` field.
|
||||||
number: episodeNumber,
|
number: episodeNumber,
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { type SQL, and, eq, exists, ne, sql } from "drizzle-orm";
|
import { type SQL, and, desc, eq, exists, ne, sql } from "drizzle-orm";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import {
|
import {
|
||||||
entries,
|
entries,
|
||||||
entryTranslations,
|
entryTranslations,
|
||||||
entryVideoJoin,
|
entryVideoJoin,
|
||||||
|
history,
|
||||||
showStudioJoin,
|
showStudioJoin,
|
||||||
showTranslations,
|
showTranslations,
|
||||||
shows,
|
shows,
|
||||||
@ -144,7 +145,10 @@ const showRelations = {
|
|||||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||||
.as("videos");
|
.as("videos");
|
||||||
},
|
},
|
||||||
firstEntry: ({ languages }: { languages: string[] }) => {
|
firstEntry: ({
|
||||||
|
languages,
|
||||||
|
userId,
|
||||||
|
}: { languages: string[]; userId: number }) => {
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([entryTranslations.pk])
|
.selectDistinctOn([entryTranslations.pk])
|
||||||
.from(entryTranslations)
|
.from(entryTranslations)
|
||||||
@ -173,6 +177,19 @@ const showRelations = {
|
|||||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||||
.as("videos");
|
.as("videos");
|
||||||
|
|
||||||
|
const progressQ = db
|
||||||
|
.selectDistinctOn([history.entryPk], {
|
||||||
|
percent: history.percent,
|
||||||
|
time: history.time,
|
||||||
|
entryPk: history.entryPk,
|
||||||
|
videoId: videos.id,
|
||||||
|
})
|
||||||
|
.from(history)
|
||||||
|
.where(eq(history.profilePk, userId))
|
||||||
|
.leftJoin(videos, eq(history.videoPk, videos.pk))
|
||||||
|
.orderBy(history.entryPk, desc(history.playedDate))
|
||||||
|
.as("progress");
|
||||||
|
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
firstEntry: jsonbBuildObject<Entry>({
|
firstEntry: jsonbBuildObject<Entry>({
|
||||||
@ -180,10 +197,12 @@ const showRelations = {
|
|||||||
...transCol,
|
...transCol,
|
||||||
number: entries.episodeNumber,
|
number: entries.episodeNumber,
|
||||||
videos: videosQ.videos,
|
videos: videosQ.videos,
|
||||||
|
progress: getColumns(progressQ),
|
||||||
}).as("firstEntry"),
|
}).as("firstEntry"),
|
||||||
})
|
})
|
||||||
.from(entries)
|
.from(entries)
|
||||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||||
|
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
||||||
.leftJoinLateral(videosQ, sql`true`)
|
.leftJoinLateral(videosQ, sql`true`)
|
||||||
.where(and(eq(entries.showPk, shows.pk), ne(entries.kind, "extra")))
|
.where(and(eq(entries.showPk, shows.pk), ne(entries.kind, "extra")))
|
||||||
.orderBy(entries.order)
|
.orderBy(entries.order)
|
||||||
@ -202,6 +221,7 @@ export async function getShows({
|
|||||||
fallbackLanguage = true,
|
fallbackLanguage = true,
|
||||||
preferOriginal = false,
|
preferOriginal = false,
|
||||||
relations = [],
|
relations = [],
|
||||||
|
userId,
|
||||||
}: {
|
}: {
|
||||||
after?: string;
|
after?: string;
|
||||||
limit: number;
|
limit: number;
|
||||||
@ -212,6 +232,7 @@ export async function getShows({
|
|||||||
fallbackLanguage?: boolean;
|
fallbackLanguage?: boolean;
|
||||||
preferOriginal?: boolean;
|
preferOriginal?: boolean;
|
||||||
relations?: (keyof typeof showRelations)[];
|
relations?: (keyof typeof showRelations)[];
|
||||||
|
userId: number;
|
||||||
}) {
|
}) {
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([showTranslations.pk])
|
.selectDistinctOn([showTranslations.pk])
|
||||||
@ -245,7 +266,7 @@ export async function getShows({
|
|||||||
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
...buildRelations(relations, showRelations, { languages }),
|
...buildRelations(relations, showRelations, { languages, userId }),
|
||||||
})
|
})
|
||||||
.from(shows)
|
.from(shows)
|
||||||
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
|
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { check, index, integer, jsonb, timestamp } from "drizzle-orm/pg-core";
|
import { check, index, integer, timestamp } from "drizzle-orm/pg-core";
|
||||||
import { entries } from "./entries";
|
import { entries } from "./entries";
|
||||||
import { profiles } from "./profiles";
|
import { profiles } from "./profiles";
|
||||||
import { schema } from "./utils";
|
import { schema } from "./utils";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user