mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import Elysia from "elysia";
|
|
import { buildUrl } from "tests/utils";
|
|
import { base } from "~/base";
|
|
import { movies } from "~/controllers/movies";
|
|
import { seed } from "~/controllers/seed";
|
|
import { series } from "~/controllers/series";
|
|
import { videos } from "~/controllers/videos";
|
|
import type { SeedMovie } from "~/models/movie";
|
|
import type { SeedVideo } from "~/models/video";
|
|
|
|
export const app = new Elysia()
|
|
.use(base)
|
|
.use(movies)
|
|
.use(series)
|
|
.use(videos)
|
|
.use(seed);
|
|
|
|
export const getMovie = async (
|
|
id: string,
|
|
{ langs, ...query }: { langs?: string; preferOriginal?: boolean },
|
|
) => {
|
|
const resp = await app.handle(
|
|
new Request(buildUrl(`movies/${id}`, query), {
|
|
method: "GET",
|
|
headers: langs
|
|
? {
|
|
"Accept-Language": langs,
|
|
}
|
|
: {},
|
|
}),
|
|
);
|
|
const body = await resp.json();
|
|
return [resp, body] as const;
|
|
};
|
|
|
|
export const getMovies = async ({
|
|
langs,
|
|
...query
|
|
}: {
|
|
filter?: string;
|
|
limit?: number;
|
|
after?: string;
|
|
sort?: string | string[];
|
|
query?: string;
|
|
langs?: string;
|
|
preferOriginal?: boolean;
|
|
}) => {
|
|
const resp = await app.handle(
|
|
new Request(buildUrl("movies", query), {
|
|
method: "GET",
|
|
headers: langs
|
|
? {
|
|
"Accept-Language": langs,
|
|
}
|
|
: {},
|
|
}),
|
|
);
|
|
const body = await resp.json();
|
|
return [resp, body] as const;
|
|
};
|
|
|
|
export const createMovie = async (movie: SeedMovie) => {
|
|
const resp = await app.handle(
|
|
new Request(buildUrl("movies"), {
|
|
method: "POST",
|
|
body: JSON.stringify(movie),
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}),
|
|
);
|
|
const body = await resp.json();
|
|
return [resp, body] as const;
|
|
};
|
|
|
|
export const createVideo = async (video: SeedVideo | SeedVideo[]) => {
|
|
const resp = await app.handle(
|
|
new Request(buildUrl("videos"), {
|
|
method: "POST",
|
|
body: JSON.stringify(Array.isArray(video) ? video : [video]),
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}),
|
|
);
|
|
const body = await resp.json();
|
|
return [resp, body] as const;
|
|
};
|