mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-23 23:52:27 -04:00
Prevent duplicated staff members
This commit is contained in:
+1
-2
@@ -52,8 +52,7 @@ export const base = new Elysia({ name: "base" })
|
||||
console.error(code, error);
|
||||
return {
|
||||
status: 500,
|
||||
message: "message" in error ? (error?.message ?? code) : code,
|
||||
details: error,
|
||||
message: "Internal server error",
|
||||
} as KError;
|
||||
})
|
||||
.get("/health", () => ({ status: "healthy" }) as const, {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { roles, staff } from "~/db/schema";
|
||||
import { conflictUpdateAllExcept, unnestValues } from "~/db/utils";
|
||||
import type { SeedStaff } from "~/models/staff";
|
||||
import { record } from "~/otel";
|
||||
import { uniqBy } from "~/utils";
|
||||
import { enqueueOptImage, flushImageQueue, type ImageTask } from "../images";
|
||||
|
||||
export const insertStaff = record(
|
||||
@@ -13,13 +14,16 @@ export const insertStaff = record(
|
||||
|
||||
return await db.transaction(async (tx) => {
|
||||
const imgQueue: ImageTask[] = [];
|
||||
const people = seed.map((x) => ({
|
||||
...x.staff,
|
||||
image: enqueueOptImage(imgQueue, {
|
||||
url: x.staff.image,
|
||||
column: staff.image,
|
||||
}),
|
||||
}));
|
||||
const people = uniqBy(
|
||||
seed.map((x) => ({
|
||||
...x.staff,
|
||||
image: enqueueOptImage(imgQueue, {
|
||||
url: x.staff.image,
|
||||
column: staff.image,
|
||||
}),
|
||||
})),
|
||||
(x) => x.slug,
|
||||
);
|
||||
const ret = await tx
|
||||
.insert(staff)
|
||||
.select(unnestValues(people, staff))
|
||||
@@ -36,7 +40,7 @@ export const insertStaff = record(
|
||||
|
||||
const rval = seed.map((x, i) => ({
|
||||
showPk,
|
||||
staffPk: ret[i].pk,
|
||||
staffPk: ret.find(y => y.slug === x.staff.slug)!.pk,
|
||||
kind: x.kind,
|
||||
order: i,
|
||||
character: {
|
||||
|
||||
@@ -831,6 +831,9 @@ export const videosWriteH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
.post(
|
||||
"",
|
||||
async ({ body, status }) => {
|
||||
if (body.length === 0) {
|
||||
return status(422, { status: 422, message: "No videos" });
|
||||
}
|
||||
return await db.transaction(async (tx) => {
|
||||
let vids: { pk: number; id: string; path: string; guess: Guess }[] = [];
|
||||
try {
|
||||
@@ -925,6 +928,7 @@ export const videosWriteH = new Elysia({ prefix: "/videos", tags: ["videos"] })
|
||||
description:
|
||||
"Invalid rendering specified. (conflicts with an existing video)",
|
||||
},
|
||||
422: KError,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -91,7 +91,7 @@ export const seasonRelations = relations(seasons, ({ one, many }) => ({
|
||||
|
||||
export const seasonTrRelations = relations(seasonTranslations, ({ one }) => ({
|
||||
season: one(seasons, {
|
||||
relationName: "season_translation",
|
||||
relationName: "season_translations",
|
||||
fields: [seasonTranslations.pk],
|
||||
references: [seasons.pk],
|
||||
}),
|
||||
|
||||
@@ -28,3 +28,13 @@ export function getFile(path: string): BunFile | S3File {
|
||||
|
||||
return Bun.file(path);
|
||||
}
|
||||
|
||||
export function uniqBy<T>(a: T[], key: (val: T) => string) {
|
||||
const seen: Record<string, boolean> = {};
|
||||
return a.filter((item) => {
|
||||
const k = key(item);
|
||||
if (seen[k]) return false;
|
||||
seen[k] = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user