mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 14:07:38 -07:00
[mastodon-client] GET /accounts/lookup
This commit is contained in:
parent
45d005fa1a
commit
3fd98eb88a
2 changed files with 15 additions and 8 deletions
|
@ -76,15 +76,15 @@ export function apiAccountMastodon(router: Router): void {
|
|||
}
|
||||
});
|
||||
router.get("/v1/accounts/lookup", async (ctx) => {
|
||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||
const accessTokens = ctx.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const data = await client.search(
|
||||
(ctx.request.query as any).acct,
|
||||
"accounts",
|
||||
);
|
||||
ctx.body = convertAccount(data.data.accounts[0]);
|
||||
const args = normalizeUrlQuery(ctx.query);
|
||||
const user = await UserHelpers.getUserFromAcct(args.acct);
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
const account = await UserConverter.encode(user);
|
||||
ctx.body = convertAccount(account);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
|
|
|
@ -33,6 +33,7 @@ import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
|||
import { convertId, IdType } from "@/misc/convert-id.js";
|
||||
import acceptFollowRequest from "@/services/following/requests/accept.js";
|
||||
import { rejectFollowRequest } from "@/services/following/reject.js";
|
||||
import { IsNull } from "typeorm";
|
||||
|
||||
export type AccountCache = {
|
||||
locks: AsyncLock;
|
||||
|
@ -136,6 +137,12 @@ export class UserHelpers {
|
|||
return this.getUserRelationshipTo(target.id, localUser.id);
|
||||
}
|
||||
|
||||
public static async getUserFromAcct(acct: string): Promise<User | null> {
|
||||
const split = acct.toLowerCase().split('@');
|
||||
if (split.length > 2) throw new Error('Invalid acct');
|
||||
return Users.findOneBy({usernameLower: split[0], host: split[1] ?? IsNull()});
|
||||
}
|
||||
|
||||
public static async getUserMutes(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40, cache: AccountCache = UserHelpers.getFreshAccountCache()): Promise<LinkPaginationObject<MastodonEntity.MutedAccount[]>> {
|
||||
if (limit > 80) limit = 80;
|
||||
|
||||
|
|
Loading…
Reference in a new issue