bigbuffet-rw/packages/pl-api/lib/entities/trends-link.ts
marcin mikołajczak 036fa32cd3 Add pl-api to workspace
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-08-28 13:43:23 +02:00

29 lines
1.1 KiB
TypeScript

import { z } from 'zod';
import { blurhashSchema } from './media-attachment';
import { historySchema } from './tag';
/** @see {@link https://docs.joinmastodon.org/entities/PreviewCard/#trends-link} */
const trendsLinkSchema = z.preprocess((link: any) => ({ ...link, id: link.url }), z.object({
id: z.string().catch(''),
url: z.string().url().catch(''),
title: z.string().catch(''),
description: z.string().catch(''),
type: z.enum(['link', 'photo', 'video', 'rich']).catch('link'),
author_name: z.string().catch(''),
author_url: z.string().catch(''),
provider_name: z.string().catch(''),
provider_url: z.string().catch(''),
html: z.string().catch(''),
width: z.number().nullable().catch(null),
height: z.number().nullable().catch(null),
image: z.string().nullable().catch(null),
image_description: z.string().nullable().catch(null),
embed_url: z.string().catch(''),
blurhash: blurhashSchema.nullable().catch(null),
history: z.array(historySchema).nullable().catch(null),
}));
type TrendsLink = z.infer<typeof trendsLinkSchema>;
export { trendsLinkSchema, type TrendsLink };