[mastodon-client] Code formatting pass

This commit is contained in:
Laura Hausmann 2023-07-05 21:53:00 +02:00 committed by Laura Hausmann
parent 37b21f973f
commit 8a6a1cfc43
3 changed files with 32 additions and 34 deletions

View File

@ -18,7 +18,7 @@ export function getClient(
const accessTokenArr = authorization?.split(" ") ?? [null]; const accessTokenArr = authorization?.split(" ") ?? [null];
const accessToken = accessTokenArr[accessTokenArr.length - 1]; const accessToken = accessTokenArr[accessTokenArr.length - 1];
const generator = (megalodon as any).default; const generator = (megalodon as any).default;
const client = generator(BASE_URL, accessToken) as MegalodonInterface; const client = generator(BASE_URL, accessToken) as MegalodonInterface;
return client; return client;
} }

View File

@ -361,38 +361,34 @@ export function apiAccountMastodon(router: Router): void {
} }
}, },
); );
router.get("/v1/featured_tags", router.get("/v1/featured_tags", async (ctx) => {
async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; 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.getFeaturedTags();
const data = await client.getFeaturedTags(); ctx.body = data.data.map((account) => convertAccount(account));
ctx.body = data.data.map((account) => convertAccount(account)); } catch (e: any) {
} catch (e: any) { console.error(e);
console.error(e); console.error(e.response.data);
console.error(e.response.data); ctx.status = 401;
ctx.status = 401; ctx.body = e.response.data;
ctx.body = e.response.data; }
} });
}, router.get("/v1/followed_tags", async (ctx) => {
); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
router.get("/v1/followed_tags", const accessTokens = ctx.headers.authorization;
async (ctx) => { const client = getClient(BASE_URL, accessTokens);
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; try {
const accessTokens = ctx.headers.authorization; const data = await client.getFollowedTags();
const client = getClient(BASE_URL, accessTokens); ctx.body = data.data.map((account) => convertAccount(account));
try { } catch (e: any) {
const data = await client.getFollowedTags(); console.error(e);
ctx.body = data.data.map((account) => convertAccount(account)); console.error(e.response.data);
} catch (e: any) { ctx.status = 401;
console.error(e); ctx.body = e.response.data;
console.error(e.response.data); }
ctx.status = 401; });
ctx.body = e.response.data;
}
},
);
router.get("/v1/bookmarks", async (ctx) => { router.get("/v1/bookmarks", async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization; const accessTokens = ctx.headers.authorization;

View File

@ -60,7 +60,9 @@ export function apiStatusMastodon(router: Router): void {
if (!body.media_ids) body.media_ids = undefined; if (!body.media_ids) body.media_ids = undefined;
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined; if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
if (body.media_ids) { if (body.media_ids) {
body.media_ids = (body.media_ids as string[]).map(p => convertId(p, IdType.CalckeyId)); body.media_ids = (body.media_ids as string[]).map((p) =>
convertId(p, IdType.CalckeyId),
);
} }
const { sensitive } = body; const { sensitive } = body;
body.sensitive = body.sensitive =