chore: formatting

This commit is contained in:
ThatOneCalculator 2023-02-13 11:17:07 -08:00
parent 4e84d45a20
commit e9d55ff44b
No known key found for this signature in database
GPG key ID: 8703CACD01000000
4 changed files with 16 additions and 13 deletions

View file

@ -71,9 +71,9 @@ mastoRouter.use(
mastoRouter.use(async (ctx, next) => { mastoRouter.use(async (ctx, next) => {
if (ctx.request.query) { if (ctx.request.query) {
if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) { if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) {
ctx.request.body = ctx.request.query ctx.request.body = ctx.request.query;
} else { } else {
ctx.request.body = {...ctx.request.body, ...ctx.request.query} ctx.request.body = { ...ctx.request.body, ...ctx.request.query };
} }
} }
await next(); await next();

View file

@ -75,18 +75,21 @@ export function apiAccountMastodon(router: Router): void {
let userid; let userid;
if (userArray === undefined) { if (userArray === undefined) {
ctx.status = 401; ctx.status = 401;
ctx.body = { error: "no user specified"}; ctx.body = { error: "no user specified" };
return; return;
} }
if (userArray.length === 1) { if (userArray.length === 1) {
const q: FindOptionsWhere<User> = { usernameLower: userArray[0].toLowerCase(), host: IsNull() }; const q: FindOptionsWhere<User> = {
usernameLower: userArray[0].toLowerCase(),
host: IsNull(),
};
const user = await Users.findOneBy(q); const user = await Users.findOneBy(q);
userid = user?.id; userid = user?.id;
} else { } else {
userid = (await resolveUser(userArray[0], userArray[1])).id; userid = (await resolveUser(userArray[0], userArray[1])).id;
} }
const data = await client.getAccount(userid ? userid : ''); 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);
@ -311,7 +314,7 @@ export function apiAccountMastodon(router: Router): void {
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);
console.error(e.response.data); console.error(e.response.data);
e.response.data.user = users ? users : 'null'; e.response.data.user = users ? users : "null";
ctx.status = 401; ctx.status = 401;
ctx.body = e.response.data; ctx.body = e.response.data;
} }

View file

@ -15,9 +15,11 @@ export function limitToInt(q: ParsedUrlQuery) {
export function argsToBools(q: ParsedUrlQuery) { export function argsToBools(q: ParsedUrlQuery) {
let object: any = q; let object: any = q;
if (q.only_media) if (q.only_media)
if (typeof q.only_media === "string") object.only_media = q.only_media.toLowerCase() === "true"; if (typeof q.only_media === "string")
object.only_media = q.only_media.toLowerCase() === "true";
if (q.exclude_replies) if (q.exclude_replies)
if (typeof q.exclude_replies === "string") object.exclude_replies = q.exclude_replies.toLowerCase() === "true"; if (typeof q.exclude_replies === "string")
object.exclude_replies = q.exclude_replies.toLowerCase() === "true";
return q; return q;
} }
@ -143,9 +145,7 @@ export function apiTimelineMastodon(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.getConversationTimeline( const data = await client.getConversationTimeline(limitToInt(ctx.query));
limitToInt(ctx.query),
);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);

View file

@ -81,9 +81,9 @@ mastoRouter.use(
mastoRouter.use(async (ctx, next) => { mastoRouter.use(async (ctx, next) => {
if (ctx.request.query) { if (ctx.request.query) {
if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) { if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) {
ctx.request.body = ctx.request.query ctx.request.body = ctx.request.query;
} else { } else {
ctx.request.body = {...ctx.request.body, ...ctx.request.query} ctx.request.body = { ...ctx.request.body, ...ctx.request.query };
} }
} }
await next(); await next();