basic account lookup

This commit is contained in:
cutestnekoaqua 2023-02-13 16:12:21 +01:00
parent 68b2dcfd75
commit 113a1ebe59
No known key found for this signature in database
GPG key ID: 6BF0964A5069C1E0

View file

@ -1,4 +1,7 @@
import { Users } from "@/models/index.js";
import { resolveUser } from "@/remote/resolve-user.js";
import Router from "@koa/router"; import Router from "@koa/router";
import { FindOptionsWhere, IsNull } from "typeorm";
import { getClient } from "../ApiMastodonCompatibleService.js"; import { getClient } from "../ApiMastodonCompatibleService.js";
import { toLimitToInt } from "./timeline.js"; import { toLimitToInt } from "./timeline.js";
@ -68,9 +71,22 @@ export function apiAccountMastodon(router: Router): void {
const accessTokens = ctx.headers.authorization; const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
try { try {
const data = await client.getAccount( let userArray = ctx.query.acct?.toString().split("@");
`@${(ctx.query.acct || "").toString()}`, let userid;
); if (userArray === undefined) {
ctx.status = 401;
ctx.body = { error: "no user specified"};
return;
}
if (userArray.length === 1) {
const q: FindOptionsWhere<User> = { usernameLower: userArray[0].toLowerCase(), host: IsNull() };
const user = await Users.findOneBy(q);
userid = user?.id;
} else {
userid = (await resolveUser(userArray[0], userArray[1])).id;
}
const data = await client.getAccount(userid ? userid : '');
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);