mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Fix aliases issues in jsonBuildObject
This commit is contained in:
parent
5a6e29e57a
commit
5994b8bc02
@ -143,13 +143,16 @@ export const getEntryProgressQ = (userId: string) =>
|
|||||||
|
|
||||||
export const mapProgress = (
|
export const mapProgress = (
|
||||||
progressQ: ReturnType<typeof getEntryProgressQ>,
|
progressQ: ReturnType<typeof getEntryProgressQ>,
|
||||||
|
{ aliased }: { aliased: boolean } = { aliased: false },
|
||||||
) => {
|
) => {
|
||||||
const { time, percent, videoId } = getColumns(progressQ);
|
const { time, percent, videoId } = getColumns(progressQ);
|
||||||
return {
|
const ret = {
|
||||||
time: coalesce(time, sql`0`),
|
time: coalesce(time, sql`0`),
|
||||||
percent: coalesce(percent, sql`0`),
|
percent: coalesce(percent, sql`0`),
|
||||||
videoId,
|
videoId: sql`${videoId}`,
|
||||||
};
|
};
|
||||||
|
if (!aliased) return ret;
|
||||||
|
return Object.fromEntries(Object.entries(ret).map(([k, v]) => [k, v.as(k)]));
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getEntries({
|
async function getEntries({
|
||||||
@ -195,7 +198,7 @@ async function getEntries({
|
|||||||
...entryCol,
|
...entryCol,
|
||||||
...transCol,
|
...transCol,
|
||||||
videos: entryVideosQ.videos,
|
videos: entryVideosQ.videos,
|
||||||
progress: mapProgress(entryProgressQ),
|
progress: mapProgress(entryProgressQ, { aliased: true }),
|
||||||
// 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,5 +1,6 @@
|
|||||||
import { and, isNull, sql } from "drizzle-orm";
|
import { and, isNull, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
import { auth } from "~/auth";
|
||||||
import { prefix } from "~/base";
|
import { prefix } from "~/base";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { shows } from "~/db/schema";
|
import { shows } from "~/db/schema";
|
||||||
@ -19,6 +20,7 @@ export const showsH = new Elysia({ prefix: "/shows", tags: ["shows"] })
|
|||||||
.model({
|
.model({
|
||||||
show: Show,
|
show: Show,
|
||||||
})
|
})
|
||||||
|
.use(auth)
|
||||||
.get(
|
.get(
|
||||||
"random",
|
"random",
|
||||||
async ({ error, redirect }) => {
|
async ({ error, redirect }) => {
|
||||||
@ -63,6 +65,7 @@ export const showsH = new Elysia({ prefix: "/shows", tags: ["shows"] })
|
|||||||
},
|
},
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
request: { url },
|
request: { url },
|
||||||
|
jwt: { sub },
|
||||||
}) => {
|
}) => {
|
||||||
const langs = processLanguages(languages);
|
const langs = processLanguages(languages);
|
||||||
const items = await getShows({
|
const items = await getShows({
|
||||||
@ -76,6 +79,7 @@ export const showsH = new Elysia({ prefix: "/shows", tags: ["shows"] })
|
|||||||
),
|
),
|
||||||
languages: langs,
|
languages: langs,
|
||||||
preferOriginal,
|
preferOriginal,
|
||||||
|
userId: sub,
|
||||||
});
|
});
|
||||||
return createPage(items, { url, sort, limit });
|
return createPage(items, { url, sort, limit });
|
||||||
},
|
},
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import { type SQL, and, eq, sql } from "drizzle-orm";
|
import { type SQL, and, eq, sql } from "drizzle-orm";
|
||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
|
import { auth } from "~/auth";
|
||||||
import { prefix } from "~/base";
|
import { prefix } from "~/base";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { showTranslations, shows } from "~/db/schema";
|
import { profiles, showTranslations, shows } from "~/db/schema";
|
||||||
import { roles, staff } from "~/db/schema/staff";
|
import { roles, staff } from "~/db/schema/staff";
|
||||||
import { getColumns, sqlarr } from "~/db/utils";
|
import { watchlist } from "~/db/schema/watchlist";
|
||||||
|
import { getColumns, jsonbBuildObject, sqlarr } from "~/db/utils";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
import type { MovieStatus } from "~/models/movie";
|
import type { MovieStatus } from "~/models/movie";
|
||||||
import { Role, Staff } from "~/models/staff";
|
import { Role, Staff } from "~/models/staff";
|
||||||
import { RoleWShow, RoleWStaff } from "~/models/staff-roles";
|
import { RoleWShow, RoleWStaff } from "~/models/staff-roles";
|
||||||
import {
|
import {
|
||||||
|
AcceptLanguage,
|
||||||
Filter,
|
Filter,
|
||||||
type FilterDef,
|
type FilterDef,
|
||||||
type Image,
|
type Image,
|
||||||
@ -22,6 +25,7 @@ import {
|
|||||||
sortToSql,
|
sortToSql,
|
||||||
} from "~/models/utils";
|
} from "~/models/utils";
|
||||||
import { desc } from "~/models/utils/descriptions";
|
import { desc } from "~/models/utils/descriptions";
|
||||||
|
import type { WatchStatus } from "~/models/watchlist";
|
||||||
import { showFilters, showSort } from "./shows/logic";
|
import { showFilters, showSort } from "./shows/logic";
|
||||||
|
|
||||||
const staffSort = Sort(
|
const staffSort = Sort(
|
||||||
@ -113,6 +117,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
staff: Staff,
|
staff: Staff,
|
||||||
role: Role,
|
role: Role,
|
||||||
})
|
})
|
||||||
|
.use(auth)
|
||||||
.get(
|
.get(
|
||||||
"/staff/:id",
|
"/staff/:id",
|
||||||
async ({ params: { id }, error }) => {
|
async ({ params: { id }, error }) => {
|
||||||
@ -186,6 +191,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
query: { limit, after, query, sort, filter, preferOriginal },
|
query: { limit, after, query, sort, filter, preferOriginal },
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
request: { url },
|
request: { url },
|
||||||
|
jwt: { sub },
|
||||||
error,
|
error,
|
||||||
}) => {
|
}) => {
|
||||||
const [member] = await db
|
const [member] = await db
|
||||||
@ -210,6 +216,20 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
sql`array_position(${sqlarr(langs)}, ${showTranslations.language})`,
|
sql`array_position(${sqlarr(langs)}, ${showTranslations.language})`,
|
||||||
)
|
)
|
||||||
.as("t");
|
.as("t");
|
||||||
|
|
||||||
|
const watchStatusQ = db
|
||||||
|
.select({
|
||||||
|
watchStatus: jsonbBuildObject<WatchStatus>({
|
||||||
|
...getColumns(watchlist),
|
||||||
|
percent: watchlist.seenCount,
|
||||||
|
}).as("watchStatus"),
|
||||||
|
})
|
||||||
|
.from(watchlist)
|
||||||
|
.leftJoin(profiles, eq(watchlist.profilePk, profiles.pk))
|
||||||
|
.where(and(eq(profiles.id, sub), eq(watchlist.showPk, shows.pk)))
|
||||||
|
.limit(1)
|
||||||
|
.as("watchstatus");
|
||||||
|
|
||||||
const items = await db
|
const items = await db
|
||||||
.select({
|
.select({
|
||||||
...getColumns(roles),
|
...getColumns(roles),
|
||||||
@ -229,6 +249,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
banner: sql<Image>`coalesce(nullif(${shows.original}->'banner', 'null'::jsonb), ${transQ.banner})`,
|
banner: sql<Image>`coalesce(nullif(${shows.original}->'banner', 'null'::jsonb), ${transQ.banner})`,
|
||||||
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
||||||
}),
|
}),
|
||||||
|
watchStatus: sql`${watchStatusQ}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.from(roles)
|
.from(roles)
|
||||||
@ -278,6 +299,12 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
|
headers: t.Object(
|
||||||
|
{
|
||||||
|
"accept-language": AcceptLanguage(),
|
||||||
|
},
|
||||||
|
{ additionalProperties: true },
|
||||||
|
),
|
||||||
response: {
|
response: {
|
||||||
200: Page(RoleWShow),
|
200: Page(RoleWShow),
|
||||||
404: {
|
404: {
|
||||||
|
@ -52,3 +52,4 @@ export const WatchStatus = t.Object({
|
|||||||
maximum: 100,
|
maximum: 100,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
export type WatchStatus = typeof WatchStatus.static;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user