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) => {
if (ctx.request.query) {
if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) {
ctx.request.body = ctx.request.query
ctx.request.body = ctx.request.query;
} else {
ctx.request.body = {...ctx.request.body, ...ctx.request.query}
ctx.request.body = { ...ctx.request.body, ...ctx.request.query };
}
}
await next();

View File

@ -75,18 +75,21 @@ export function apiAccountMastodon(router: Router): void {
let userid;
if (userArray === undefined) {
ctx.status = 401;
ctx.body = { error: "no user specified"};
ctx.body = { error: "no user specified" };
return;
}
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);
userid = user?.id;
} else {
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;
} catch (e: any) {
console.error(e);
@ -311,7 +314,7 @@ export function apiAccountMastodon(router: Router): void {
} catch (e: any) {
console.error(e);
console.error(e.response.data);
e.response.data.user = users ? users : 'null';
e.response.data.user = users ? users : "null";
ctx.status = 401;
ctx.body = e.response.data;
}

View File

@ -15,9 +15,11 @@ export function limitToInt(q: ParsedUrlQuery) {
export function argsToBools(q: ParsedUrlQuery) {
let object: any = q;
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 (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;
}
@ -143,9 +145,7 @@ export function apiTimelineMastodon(router: Router): void {
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getConversationTimeline(
limitToInt(ctx.query),
);
const data = await client.getConversationTimeline(limitToInt(ctx.query));
ctx.body = data.data;
} catch (e: any) {
console.error(e);

View File

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