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` * Support `/api/v1/suggestions`
* @see {@link https://docs.joinmastodon.org/methods/suggestions/#v1} * @see {@link https://docs.joinmastodon.org/methods/suggestions/#v1}
*/ */
if (!suggestion) return null;
if (suggestion?.acct) return { if (suggestion?.acct) return {
source: 'staff', source: 'staff',
sources: 'featured', sources: ['featured'],
account: suggestion, 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; return suggestion;
}, z.object({ }, z.object({
source: z.string(), source: z.string().nullable().catch(null),
sources: z.array(z.string()), sources: z.array(z.string()).catch([]),
account: accountSchema, account: accountSchema,
})); }));

View File

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

View File

@ -133,7 +133,7 @@
"multiselect-react-dropdown": "^2.0.25", "multiselect-react-dropdown": "^2.0.25",
"object-to-formdata": "^4.5.1", "object-to-formdata": "^4.5.1",
"path-browserify": "^1.0.1", "path-browserify": "^1.0.1",
"pl-api": "^0.0.27", "pl-api": "^0.0.28",
"postcss": "^8.4.29", "postcss": "^8.4.29",
"process": "^0.11.10", "process": "^0.11.10",
"punycode": "^2.1.1", "punycode": "^2.1.1",

View File

@ -8378,10 +8378,10 @@ pkg-types@^1.0.3:
mlly "^1.2.0" mlly "^1.2.0"
pathe "^1.1.0" pathe "^1.1.0"
pl-api@^0.0.27: pl-api@^0.0.28:
version "0.0.27" version "0.0.28"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.27.tgz#8a9d52594a0d35da9364bbf769b84233827366e1" resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.28.tgz#b8ad56706fa31c163e05f0610257953e76ddd720"
integrity sha512-7u/mUexOcBwCa1d4LKZzhFp2bAYqGzfxVXh/RmgMVFd5+d57Kx6Itpzk3dHBJ4aHiE7NV2llEeG/SaYr7mUzuA== integrity sha512-j2j0yloxPgpQtyBehOR+aJ7LKKjwDrZLYMDg4ZojsjYi9qIS5PO9jRRpi9DSB4kFyrpQagyLbJKXY3DbeHS70w==
dependencies: dependencies:
blurhash "^2.0.5" blurhash "^2.0.5"
http-link-header "^1.1.3" http-link-header "^1.1.3"