mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Take images url from api
This commit is contained in:
parent
dc5fd8f5a3
commit
69e8340c95
@ -19,10 +19,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { withImages, ResourceP } from "../traits";
|
import { ImagesP, ResourceP } from "../traits";
|
||||||
|
|
||||||
export const CollectionP = withImages(
|
export const CollectionP = ResourceP("collection")
|
||||||
ResourceP("collection").extend({
|
.merge(ImagesP)
|
||||||
|
.extend({
|
||||||
/**
|
/**
|
||||||
* The title of this collection.
|
* The title of this collection.
|
||||||
*/
|
*/
|
||||||
@ -31,11 +32,11 @@ export const CollectionP = withImages(
|
|||||||
* The summary of this show.
|
* The summary of this show.
|
||||||
*/
|
*/
|
||||||
overview: z.string().nullable(),
|
overview: z.string().nullable(),
|
||||||
}),
|
})
|
||||||
).transform((x) => ({
|
.transform((x) => ({
|
||||||
...x,
|
...x,
|
||||||
href: `/collection/${x.slug}`,
|
href: `/collection/${x.slug}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class representing collections of show or movies.
|
* A class representing collections of show or movies.
|
||||||
|
@ -20,11 +20,12 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zdate } from "../utils";
|
import { zdate } from "../utils";
|
||||||
import { withImages, imageFn } from "../traits";
|
import { ImagesP, imageFn } from "../traits";
|
||||||
import { ResourceP } from "../traits/resource";
|
import { ResourceP } from "../traits/resource";
|
||||||
|
|
||||||
export const BaseEpisodeP = withImages(
|
export const BaseEpisodeP = ResourceP("episode")
|
||||||
ResourceP("episode").extend({
|
.merge(ImagesP)
|
||||||
|
.extend({
|
||||||
/**
|
/**
|
||||||
* The season in witch this episode is in.
|
* The season in witch this episode is in.
|
||||||
*/
|
*/
|
||||||
@ -71,8 +72,7 @@ export const BaseEpisodeP = withImages(
|
|||||||
* The id of the show containing this episode
|
* The id of the show containing this episode
|
||||||
*/
|
*/
|
||||||
showId: z.string(),
|
showId: z.string(),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
.transform((x) => ({
|
.transform((x) => ({
|
||||||
...x,
|
...x,
|
||||||
runtime: x.runtime === 0 ? null : x.runtime,
|
runtime: x.runtime === 0 ? null : x.runtime,
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zdate } from "../utils";
|
import { zdate } from "../utils";
|
||||||
import { withImages, ResourceP, imageFn } from "../traits";
|
import { ImagesP, ResourceP, imageFn } from "../traits";
|
||||||
import { Genre } from "./genre";
|
import { Genre } from "./genre";
|
||||||
import { StudioP } from "./studio";
|
import { StudioP } from "./studio";
|
||||||
import { Status } from "./show";
|
import { Status } from "./show";
|
||||||
@ -28,8 +28,9 @@ import { CollectionP } from "./collection";
|
|||||||
import { MetadataP } from "./metadata";
|
import { MetadataP } from "./metadata";
|
||||||
import { WatchStatusP } from "./watch-status";
|
import { WatchStatusP } from "./watch-status";
|
||||||
|
|
||||||
export const MovieP = withImages(
|
export const MovieP = ResourceP("movie")
|
||||||
ResourceP("movie").extend({
|
.merge(ImagesP)
|
||||||
|
.extend({
|
||||||
/**
|
/**
|
||||||
* The title of this movie.
|
* The title of this movie.
|
||||||
*/
|
*/
|
||||||
@ -104,8 +105,7 @@ export const MovieP = withImages(
|
|||||||
* Metadata of what an user as started/planned to watch.
|
* Metadata of what an user as started/planned to watch.
|
||||||
*/
|
*/
|
||||||
watchStatus: WatchStatusP.optional().nullable(),
|
watchStatus: WatchStatusP.optional().nullable(),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
.transform((x) => ({
|
.transform((x) => ({
|
||||||
...x,
|
...x,
|
||||||
runtime: x.runtime === 0 ? null : x.runtime,
|
runtime: x.runtime === 0 ? null : x.runtime,
|
||||||
|
@ -19,28 +19,25 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { withImages } from "../traits";
|
import { ImagesP, ResourceP } from "../traits";
|
||||||
import { ResourceP } from "../traits/resource";
|
|
||||||
|
|
||||||
export const PersonP = withImages(
|
export const PersonP = ResourceP("people").merge(ImagesP).extend({
|
||||||
ResourceP("people").extend({
|
/**
|
||||||
/**
|
* The name of this person.
|
||||||
* The name of this person.
|
*/
|
||||||
*/
|
name: z.string(),
|
||||||
name: z.string(),
|
/**
|
||||||
/**
|
* The type of work the person has done for the show. That can be something like "Actor",
|
||||||
* The type of work the person has done for the show. That can be something like "Actor",
|
* "Writer", "Music", "Voice Actor"...
|
||||||
* "Writer", "Music", "Voice Actor"...
|
*/
|
||||||
*/
|
type: z.string().optional(),
|
||||||
type: z.string().optional(),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The role the People played. This is mostly used to inform witch character was played for actor
|
* The role the People played. This is mostly used to inform witch character was played for actor
|
||||||
* and voice actors.
|
* and voice actors.
|
||||||
*/
|
*/
|
||||||
role: z.string().optional(),
|
role: z.string().optional(),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A studio that make shows.
|
* A studio that make shows.
|
||||||
|
@ -20,37 +20,34 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zdate } from "../utils";
|
import { zdate } from "../utils";
|
||||||
import { withImages } from "../traits";
|
import { ImagesP, ResourceP } from "../traits";
|
||||||
import { ResourceP } from "../traits/resource";
|
|
||||||
|
|
||||||
export const SeasonP = withImages(
|
export const SeasonP = ResourceP("season").merge(ImagesP).extend({
|
||||||
ResourceP("season").extend({
|
/**
|
||||||
/**
|
* The name of this season.
|
||||||
* The name of this season.
|
*/
|
||||||
*/
|
name: z.string(),
|
||||||
name: z.string(),
|
/**
|
||||||
/**
|
* The number of this season. This can be set to 0 to indicate specials.
|
||||||
* The number of this season. This can be set to 0 to indicate specials.
|
*/
|
||||||
*/
|
seasonNumber: z.number(),
|
||||||
seasonNumber: z.number(),
|
/**
|
||||||
/**
|
* A quick overview of this season.
|
||||||
* A quick overview of this season.
|
*/
|
||||||
*/
|
overview: z.string().nullable(),
|
||||||
overview: z.string().nullable(),
|
/**
|
||||||
/**
|
* The starting air date of this season.
|
||||||
* The starting air date of this season.
|
*/
|
||||||
*/
|
startDate: zdate().nullable(),
|
||||||
startDate: zdate().nullable(),
|
/**
|
||||||
/**
|
* The ending date of this season.
|
||||||
* The ending date of this season.
|
*/
|
||||||
*/
|
endDate: zdate().nullable(),
|
||||||
endDate: zdate().nullable(),
|
/**
|
||||||
/**
|
* The number of episodes available on kyoo of this season.
|
||||||
* The number of episodes available on kyoo of this season.
|
*/
|
||||||
*/
|
episodesCount: z.number(),
|
||||||
episodesCount: z.number(),
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A season of a Show.
|
* A season of a Show.
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zdate } from "../utils";
|
import { zdate } from "../utils";
|
||||||
import { withImages, ResourceP } from "../traits";
|
import { ImagesP, ResourceP } from "../traits";
|
||||||
import { Genre } from "./genre";
|
import { Genre } from "./genre";
|
||||||
import { StudioP } from "./studio";
|
import { StudioP } from "./studio";
|
||||||
import { BaseEpisodeP } from "./episode.base";
|
import { BaseEpisodeP } from "./episode.base";
|
||||||
@ -37,8 +37,9 @@ export enum Status {
|
|||||||
Planned = "Planned",
|
Planned = "Planned",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ShowP = withImages(
|
export const ShowP = ResourceP("show")
|
||||||
ResourceP("show").extend({
|
.merge(ImagesP)
|
||||||
|
.extend({
|
||||||
/**
|
/**
|
||||||
* The title of this show.
|
* The title of this show.
|
||||||
*/
|
*/
|
||||||
@ -103,8 +104,7 @@ export const ShowP = withImages(
|
|||||||
* The number of episodes in this show.
|
* The number of episodes in this show.
|
||||||
*/
|
*/
|
||||||
episodesCount: z.number().int().gte(0).optional(),
|
episodesCount: z.number().int().gte(0).optional(),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
.transform((x) => {
|
.transform((x) => {
|
||||||
if (!x.thumbnail && x.poster) {
|
if (!x.thumbnail && x.poster) {
|
||||||
x.thumbnail = { ...x.poster };
|
x.thumbnail = { ...x.poster };
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
import { ZodObject, ZodRawShape, z } from "zod";
|
import { z } from "zod";
|
||||||
import { lastUsedUrl } from "..";
|
import { lastUsedUrl } from "..";
|
||||||
|
|
||||||
export const imageFn = (url: string) =>
|
export const imageFn = (url: string) =>
|
||||||
@ -28,9 +28,12 @@ export const imageFn = (url: string) =>
|
|||||||
export const Img = z.object({
|
export const Img = z.object({
|
||||||
source: z.string(),
|
source: z.string(),
|
||||||
blurhash: z.string(),
|
blurhash: z.string(),
|
||||||
|
low: z.string().transform(imageFn),
|
||||||
|
medium: z.string().transform(imageFn),
|
||||||
|
high: z.string().transform(imageFn),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ImagesP = z.object({
|
export const ImagesP = z.object({
|
||||||
/**
|
/**
|
||||||
* An url to the poster of this resource. If this resource does not have an image, the link will
|
* An url to the poster of this resource. If this resource does not have an image, the link will
|
||||||
* be null. If the kyoo's instance is not capable of handling this kind of image for the specific
|
* be null. If the kyoo's instance is not capable of handling this kind of image for the specific
|
||||||
@ -53,28 +56,7 @@ const ImagesP = z.object({
|
|||||||
logo: Img.nullable(),
|
logo: Img.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const addQualities = (x: object | null | undefined, href: string) => {
|
|
||||||
if (x === null) return null;
|
|
||||||
return {
|
|
||||||
...x,
|
|
||||||
low: imageFn(`${href}?quality=low`),
|
|
||||||
medium: imageFn(`${href}?quality=medium`),
|
|
||||||
high: imageFn(`${href}?quality=high`),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const withImages = <T extends ZodRawShape>(parser: ZodObject<T>) => {
|
|
||||||
return parser.merge(ImagesP).transform((x) => {
|
|
||||||
return {
|
|
||||||
...x,
|
|
||||||
poster: addQualities(x.poster, `/${x.kind}/${x.slug}/poster`),
|
|
||||||
thumbnail: addQualities(x.thumbnail, `/${x.kind}/${x.slug}/thumbnail`),
|
|
||||||
logo: addQualities(x.logo, `/${x.kind}/${x.slug}/logo`),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base traits for items that has image resources.
|
* Base traits for items that has image resources.
|
||||||
*/
|
*/
|
||||||
export type KyooImage = z.infer<typeof Img> & { low: string; medium: string; high: string };
|
export type KyooImage = z.infer<typeof Img>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user