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,
|
||||
filter,
|
||||
languages,
|
||||
userId,
|
||||
}: {
|
||||
after: string | undefined;
|
||||
limit: number;
|
||||
@ -121,6 +122,7 @@ async function getEntries({
|
||||
sort: Sort;
|
||||
filter: SQL | undefined;
|
||||
languages: string[];
|
||||
userId: number;
|
||||
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
||||
const transQ = db
|
||||
.selectDistinctOn([entryTranslations.pk])
|
||||
@ -158,6 +160,7 @@ async function getEntries({
|
||||
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");
|
||||
@ -176,9 +179,7 @@ async function getEntries({
|
||||
...entryCol,
|
||||
...transCol,
|
||||
videos: videosQ.videos,
|
||||
progress: {
|
||||
...getColumns(progressQ),
|
||||
},
|
||||
progress: getColumns(progressQ),
|
||||
// specials don't have an `episodeNumber` but a `number` field.
|
||||
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 {
|
||||
entries,
|
||||
entryTranslations,
|
||||
entryVideoJoin,
|
||||
history,
|
||||
showStudioJoin,
|
||||
showTranslations,
|
||||
shows,
|
||||
@ -144,7 +145,10 @@ const showRelations = {
|
||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||
.as("videos");
|
||||
},
|
||||
firstEntry: ({ languages }: { languages: string[] }) => {
|
||||
firstEntry: ({
|
||||
languages,
|
||||
userId,
|
||||
}: { languages: string[]; userId: number }) => {
|
||||
const transQ = db
|
||||
.selectDistinctOn([entryTranslations.pk])
|
||||
.from(entryTranslations)
|
||||
@ -173,6 +177,19 @@ const showRelations = {
|
||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||
.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
|
||||
.select({
|
||||
firstEntry: jsonbBuildObject<Entry>({
|
||||
@ -180,10 +197,12 @@ const showRelations = {
|
||||
...transCol,
|
||||
number: entries.episodeNumber,
|
||||
videos: videosQ.videos,
|
||||
progress: getColumns(progressQ),
|
||||
}).as("firstEntry"),
|
||||
})
|
||||
.from(entries)
|
||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
|
||||
.leftJoinLateral(videosQ, sql`true`)
|
||||
.where(and(eq(entries.showPk, shows.pk), ne(entries.kind, "extra")))
|
||||
.orderBy(entries.order)
|
||||
@ -202,6 +221,7 @@ export async function getShows({
|
||||
fallbackLanguage = true,
|
||||
preferOriginal = false,
|
||||
relations = [],
|
||||
userId,
|
||||
}: {
|
||||
after?: string;
|
||||
limit: number;
|
||||
@ -212,6 +232,7 @@ export async function getShows({
|
||||
fallbackLanguage?: boolean;
|
||||
preferOriginal?: boolean;
|
||||
relations?: (keyof typeof showRelations)[];
|
||||
userId: number;
|
||||
}) {
|
||||
const transQ = db
|
||||
.selectDistinctOn([showTranslations.pk])
|
||||
@ -245,7 +266,7 @@ export async function getShows({
|
||||
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
||||
}),
|
||||
|
||||
...buildRelations(relations, showRelations, { languages }),
|
||||
...buildRelations(relations, showRelations, { languages, userId }),
|
||||
})
|
||||
.from(shows)
|
||||
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 { profiles } from "./profiles";
|
||||
import { schema } from "./utils";
|
||||
|
Loading…
x
Reference in New Issue
Block a user