pl-api: Fix suggestion schema

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-09-07 19:58:02 +02:00
parent 2ff3b88d3a
commit 688f04600c
4 changed files with 24 additions and 9 deletions

View File

@ -8,15 +8,30 @@ const suggestionSchema = z.preprocess((suggestion: any) => {
* Support `/api/v1/suggestions`
* @see {@link https://docs.joinmastodon.org/methods/suggestions/#v1}
*/
if (!suggestion) return null;
if (suggestion?.acct) return {
source: 'staff',
sources: 'featured',
sources: ['featured'],
account: suggestion,
};
if (!suggestion.sources) {
suggestion.sources = [];
switch (suggestion.source) {
case 'staff':
suggestion.sources.push('staff');
break;
case 'global':
suggestion.sources.push('most_interactions');
break;
}
}
return suggestion;
}, z.object({
source: z.string(),
sources: z.array(z.string()),
source: z.string().nullable().catch(null),
sources: z.array(z.string()).catch([]),
account: accountSchema,
}));

View File

@ -1,6 +1,6 @@
{
"name": "pl-api",
"version": "0.0.27",
"version": "0.0.28",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/fork/packages/pl-api",
"repository": {