[mastodon-client] fix search type param

This commit is contained in:
Laura Hausmann 2023-07-07 23:42:19 +02:00
parent 8323a33f97
commit 7ffe30dcdb
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -30,21 +30,25 @@ export function apiSearchMastodon(router: Router): void {
try { try {
const query: any = convertTimelinesArgsId(limitToInt(ctx.query)); const query: any = convertTimelinesArgsId(limitToInt(ctx.query));
const type = query.type; const type = query.type;
if (type) { const acct =
const data = await client.search(query.q, type, query); !type || type === "accounts"
ctx.body = data.data.accounts.map((account) => convertAccount(account)); ? await client.search(query.q, "accounts", query)
} else { : null;
const acct = await client.search(query.q, "accounts", query); const stat =
const stat = await client.search(query.q, "statuses", query); !type || type === "statuses"
const tags = await client.search(query.q, "hashtags", query); ? await client.search(query.q, "statuses", query)
: null;
const tags =
!type || type === "hashtags"
? await client.search(query.q, "hashtags", query)
: null;
ctx.body = { ctx.body = {
accounts: acct.data.accounts.map((account) => accounts:
convertAccount(account), acct?.data?.accounts.map((account) => convertAccount(account)) ?? [],
), statuses:
statuses: stat.data.statuses.map((status) => convertStatus(status)), stat?.data?.statuses.map((status) => convertStatus(status)) ?? [],
hashtags: tags.data.hashtags, hashtags: tags?.data?.hashtags ?? [],
}; };
}
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);
ctx.status = 401; ctx.status = 401;