mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-04 03:27:14 -05:00 
			
		
		
		
	Add /collections/:id/series & /collections/:id/movies
This commit is contained in:
		
							parent
							
								
									d53947265f
								
							
						
					
					
						commit
						9f974de245
					
				@ -9,15 +9,17 @@ import {
 | 
				
			|||||||
} from "~/models/collections";
 | 
					} from "~/models/collections";
 | 
				
			||||||
import { KError } from "~/models/error";
 | 
					import { KError } from "~/models/error";
 | 
				
			||||||
import { duneCollection } from "~/models/examples";
 | 
					import { duneCollection } from "~/models/examples";
 | 
				
			||||||
 | 
					import { Movie } from "~/models/movie";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
	AcceptLanguage,
 | 
						AcceptLanguage,
 | 
				
			||||||
	Filter,
 | 
						Filter,
 | 
				
			||||||
	Page,
 | 
						Page,
 | 
				
			||||||
	createPage,
 | 
						createPage,
 | 
				
			||||||
 | 
						isUuid,
 | 
				
			||||||
	processLanguages,
 | 
						processLanguages,
 | 
				
			||||||
} from "~/models/utils";
 | 
					} from "~/models/utils";
 | 
				
			||||||
import { desc } from "~/models/utils/descriptions";
 | 
					import { desc } from "~/models/utils/descriptions";
 | 
				
			||||||
import { getShow, getShows, showFilters, showSort } from "./shows";
 | 
					import { getShow, getShows, showFilters, showSort } from "./logic";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const collections = new Elysia({
 | 
					export const collections = new Elysia({
 | 
				
			||||||
	prefix: "/collections",
 | 
						prefix: "/collections",
 | 
				
			||||||
@ -168,4 +170,166 @@ export const collections = new Elysia({
 | 
				
			|||||||
				422: KError,
 | 
									422: KError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						.get(
 | 
				
			||||||
 | 
							"/:id/movies",
 | 
				
			||||||
 | 
							async ({
 | 
				
			||||||
 | 
								params: { id },
 | 
				
			||||||
 | 
								query: { limit, after, query, sort, filter, preferOriginal },
 | 
				
			||||||
 | 
								headers: { "accept-language": languages },
 | 
				
			||||||
 | 
								request: { url },
 | 
				
			||||||
 | 
								error,
 | 
				
			||||||
 | 
							}) => {
 | 
				
			||||||
 | 
								const [collection] = await db
 | 
				
			||||||
 | 
									.select({ pk: shows.pk })
 | 
				
			||||||
 | 
									.from(shows)
 | 
				
			||||||
 | 
									.where(
 | 
				
			||||||
 | 
										and(
 | 
				
			||||||
 | 
											eq(shows.kind, "collection"),
 | 
				
			||||||
 | 
											isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
									.limit(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!collection) {
 | 
				
			||||||
 | 
									return error(404, {
 | 
				
			||||||
 | 
										status: 404,
 | 
				
			||||||
 | 
										message: `No collection with the id or slug: '${id}'.`,
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const langs = processLanguages(languages);
 | 
				
			||||||
 | 
								const items = await getShows({
 | 
				
			||||||
 | 
									limit,
 | 
				
			||||||
 | 
									after,
 | 
				
			||||||
 | 
									query,
 | 
				
			||||||
 | 
									sort,
 | 
				
			||||||
 | 
									filter: and(
 | 
				
			||||||
 | 
										eq(shows.collectionPk, collection.pk),
 | 
				
			||||||
 | 
										eq(shows.kind, "movie"),
 | 
				
			||||||
 | 
										filter,
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
									languages: langs,
 | 
				
			||||||
 | 
									preferOriginal,
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
								return createPage(items, { url, sort, limit });
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								detail: { description: "Get all movies in a collection" },
 | 
				
			||||||
 | 
								params: t.Object({
 | 
				
			||||||
 | 
									id: t.String({
 | 
				
			||||||
 | 
										description: "The id or slug of the collection.",
 | 
				
			||||||
 | 
										example: duneCollection.slug,
 | 
				
			||||||
 | 
									}),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								query: t.Object({
 | 
				
			||||||
 | 
									sort: showSort,
 | 
				
			||||||
 | 
									filter: t.Optional(Filter({ def: showFilters })),
 | 
				
			||||||
 | 
									query: t.Optional(t.String({ description: desc.query })),
 | 
				
			||||||
 | 
									limit: t.Integer({
 | 
				
			||||||
 | 
										minimum: 1,
 | 
				
			||||||
 | 
										maximum: 250,
 | 
				
			||||||
 | 
										default: 50,
 | 
				
			||||||
 | 
										description: "Max page size.",
 | 
				
			||||||
 | 
									}),
 | 
				
			||||||
 | 
									after: t.Optional(t.String({ description: desc.after })),
 | 
				
			||||||
 | 
									preferOriginal: t.Optional(
 | 
				
			||||||
 | 
										t.Boolean({
 | 
				
			||||||
 | 
											description: desc.preferOriginal,
 | 
				
			||||||
 | 
										}),
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								headers: t.Object({
 | 
				
			||||||
 | 
									"accept-language": AcceptLanguage({ autoFallback: true }),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								response: {
 | 
				
			||||||
 | 
									200: Page(Movie),
 | 
				
			||||||
 | 
									404: {
 | 
				
			||||||
 | 
										...KError,
 | 
				
			||||||
 | 
										description: "No collection found with the given id or slug.",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									422: KError,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						.get(
 | 
				
			||||||
 | 
							"/:id/series",
 | 
				
			||||||
 | 
							async ({
 | 
				
			||||||
 | 
								params: { id },
 | 
				
			||||||
 | 
								query: { limit, after, query, sort, filter, preferOriginal },
 | 
				
			||||||
 | 
								headers: { "accept-language": languages },
 | 
				
			||||||
 | 
								request: { url },
 | 
				
			||||||
 | 
								error,
 | 
				
			||||||
 | 
							}) => {
 | 
				
			||||||
 | 
								const [collection] = await db
 | 
				
			||||||
 | 
									.select({ pk: shows.pk })
 | 
				
			||||||
 | 
									.from(shows)
 | 
				
			||||||
 | 
									.where(
 | 
				
			||||||
 | 
										and(
 | 
				
			||||||
 | 
											eq(shows.kind, "collection"),
 | 
				
			||||||
 | 
											isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
									.limit(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!collection) {
 | 
				
			||||||
 | 
									return error(404, {
 | 
				
			||||||
 | 
										status: 404,
 | 
				
			||||||
 | 
										message: `No collection with the id or slug: '${id}'.`,
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const langs = processLanguages(languages);
 | 
				
			||||||
 | 
								const items = await getShows({
 | 
				
			||||||
 | 
									limit,
 | 
				
			||||||
 | 
									after,
 | 
				
			||||||
 | 
									query,
 | 
				
			||||||
 | 
									sort,
 | 
				
			||||||
 | 
									filter: and(
 | 
				
			||||||
 | 
										eq(shows.collectionPk, collection.pk),
 | 
				
			||||||
 | 
										eq(shows.kind, "serie"),
 | 
				
			||||||
 | 
										filter,
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
									languages: langs,
 | 
				
			||||||
 | 
									preferOriginal,
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
								return createPage(items, { url, sort, limit });
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								detail: { description: "Get all series in a collection" },
 | 
				
			||||||
 | 
								params: t.Object({
 | 
				
			||||||
 | 
									id: t.String({
 | 
				
			||||||
 | 
										description: "The id or slug of the collection.",
 | 
				
			||||||
 | 
										example: duneCollection.slug,
 | 
				
			||||||
 | 
									}),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								query: t.Object({
 | 
				
			||||||
 | 
									sort: showSort,
 | 
				
			||||||
 | 
									filter: t.Optional(Filter({ def: showFilters })),
 | 
				
			||||||
 | 
									query: t.Optional(t.String({ description: desc.query })),
 | 
				
			||||||
 | 
									limit: t.Integer({
 | 
				
			||||||
 | 
										minimum: 1,
 | 
				
			||||||
 | 
										maximum: 250,
 | 
				
			||||||
 | 
										default: 50,
 | 
				
			||||||
 | 
										description: "Max page size.",
 | 
				
			||||||
 | 
									}),
 | 
				
			||||||
 | 
									after: t.Optional(t.String({ description: desc.after })),
 | 
				
			||||||
 | 
									preferOriginal: t.Optional(
 | 
				
			||||||
 | 
										t.Boolean({
 | 
				
			||||||
 | 
											description: desc.preferOriginal,
 | 
				
			||||||
 | 
										}),
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								headers: t.Object({
 | 
				
			||||||
 | 
									"accept-language": AcceptLanguage({ autoFallback: true }),
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								response: {
 | 
				
			||||||
 | 
									200: Page(Movie),
 | 
				
			||||||
 | 
									404: {
 | 
				
			||||||
 | 
										...KError,
 | 
				
			||||||
 | 
										description: "No collection found with the given id or slug.",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									422: KError,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ import {
 | 
				
			|||||||
	processLanguages,
 | 
						processLanguages,
 | 
				
			||||||
} from "~/models/utils";
 | 
					} from "~/models/utils";
 | 
				
			||||||
import { desc } from "~/models/utils/descriptions";
 | 
					import { desc } from "~/models/utils/descriptions";
 | 
				
			||||||
import { getShow, getShows, showFilters, showSort } from "./shows";
 | 
					import { getShow, getShows, showFilters, showSort } from "./logic";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
 | 
					export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
 | 
				
			||||||
	.model({
 | 
						.model({
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ import {
 | 
				
			|||||||
	processLanguages,
 | 
						processLanguages,
 | 
				
			||||||
} from "~/models/utils";
 | 
					} from "~/models/utils";
 | 
				
			||||||
import { desc } from "~/models/utils/descriptions";
 | 
					import { desc } from "~/models/utils/descriptions";
 | 
				
			||||||
import { getShow, getShows, showFilters, showSort } from "./shows";
 | 
					import { getShow, getShows, showFilters, showSort } from "./logic";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const series = new Elysia({ prefix: "/series", tags: ["series"] })
 | 
					export const series = new Elysia({ prefix: "/series", tags: ["series"] })
 | 
				
			||||||
	.model({
 | 
						.model({
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user