mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 22:17:30 -07:00
simplify code
This commit is contained in:
parent
1acf0518b0
commit
a97806eeaa
1 changed files with 7 additions and 26 deletions
|
@ -63,39 +63,20 @@ export function apiAccountMastodon(router: Router): void {
|
|||
ctx.body = e.response.data;
|
||||
}
|
||||
});
|
||||
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.query.acct || '').toString(), "accounts", {
|
||||
resolve: true
|
||||
});
|
||||
ctx.body = data.data.accounts[0];
|
||||
if (data.data.accounts.length === 0) {
|
||||
ctx.status = 404;
|
||||
ctx.body = {
|
||||
error: `Record (${ctx.query.acct}) not found`
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
ctx.status = 401;
|
||||
ctx.body = e.response.data;
|
||||
}
|
||||
},
|
||||
);
|
||||
router.get<{ Params: { id: string } }>(
|
||||
"/v1/accounts/:id",
|
||||
async (ctx) => {
|
||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||
const accessTokens = ctx.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
let req_user = ctx.query.acct;
|
||||
if (!req_user) {
|
||||
req_user = ctx.params.id;
|
||||
} else {
|
||||
req_user = req_user.toString();
|
||||
}
|
||||
try {
|
||||
const data = await client.getAccount(ctx.params.id);
|
||||
const data = await client.getAccount(req_user);
|
||||
ctx.body = data.data;
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
|
|
Loading…
Reference in a new issue