mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2025-01-21 04:52:54 +09:00
[mastodon-client] Code cleanup & reformat
This commit is contained in:
parent
8bc7bf373e
commit
afd9e236a3
@ -1,6 +1,12 @@
|
||||
import Router from "@koa/router";
|
||||
import { convertId, IdType } from "../../index.js";
|
||||
import { convertAccountId, convertPollId, convertStatusIds, convertStatusEditIds, convertStatusSourceId, } from "../converters.js";
|
||||
import {
|
||||
convertAccountId,
|
||||
convertPollId,
|
||||
convertStatusEditIds,
|
||||
convertStatusIds,
|
||||
convertStatusSourceId,
|
||||
} from "../converters.js";
|
||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
|
||||
import { convertPaginationArgsIds, limitToInt, normalizeUrlQuery } from "@/server/api/mastodon/endpoints/timeline.js";
|
||||
|
@ -32,6 +32,7 @@ export class ListHelpers {
|
||||
throw new MastoApiError(404);
|
||||
})
|
||||
}
|
||||
|
||||
public static async getListUsers(user: ILocalUser, id: string, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 40): Promise<LinkPaginationObject<User[]>> {
|
||||
if (limit > 80) limit = 80;
|
||||
const list = await UserLists.findOneBy({ userId: user.id, id: id });
|
||||
|
@ -7,11 +7,10 @@ import { awaitAll } from "@/prelude/await-all.js";
|
||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||
import { convertAccountId } from "@/server/api/mastodon/converters.js";
|
||||
import { Announcement } from "@/models/entities/announcement.js";
|
||||
import { ILocalUser } from "@/models/entities/user.js";
|
||||
import { ILocalUser, User } from "@/models/entities/user.js";
|
||||
import { AnnouncementConverter } from "@/server/api/mastodon/converters/announcement.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import * as Acct from "@/misc/acct.js";
|
||||
import { User } from "@/models/entities/user.js";
|
||||
import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||
import { generateMutedUserQueryForUsers } from "@/server/api/common/generate-muted-user-query.js";
|
||||
import { generateBlockQueryForUsers } from "@/server/api/common/generate-block-query.js";
|
||||
@ -192,7 +191,8 @@ export class MiscHelpers {
|
||||
cache: {
|
||||
id: "meta_emojis",
|
||||
milliseconds: 3600000, // 1 hour
|
||||
}}
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(dbRes => populateEmojis(dbRes.map(p => p.name), null)
|
||||
.then(p => p.map(x => EmojiConverter.encode(x))
|
||||
|
@ -63,7 +63,10 @@ export class SearchHelpers {
|
||||
if (!match) match = q.match(/^@(?<user>[a-zA-Z0-9_]+)$/)
|
||||
if (match) {
|
||||
// check if user is already in database
|
||||
const dbResult = await Users.findOneBy({usernameLower: match.groups!.user.toLowerCase(), host: match.groups?.host ?? IsNull()});
|
||||
const dbResult = await Users.findOneBy({
|
||||
usernameLower: match.groups!.user.toLowerCase(),
|
||||
host: match.groups?.host ?? IsNull()
|
||||
});
|
||||
if (dbResult) return [dbResult];
|
||||
|
||||
const result = await resolveUser(match.groups!.user.toLowerCase(), match.groups?.host ?? null);
|
||||
|
@ -538,6 +538,11 @@ export class UserHelpers {
|
||||
}
|
||||
|
||||
public static async getDefaultNoteVisibility(user: ILocalUser): Promise<IceshrimpVisibility> {
|
||||
return RegistryItems.findOneBy({domain: IsNull(), userId: user.id, key: 'defaultNoteVisibility', scope: '{client,base}'}).then(p => p?.value ?? 'public')
|
||||
return RegistryItems.findOneBy({
|
||||
domain: IsNull(),
|
||||
userId: user.id,
|
||||
key: 'defaultNoteVisibility',
|
||||
scope: '{client,base}'
|
||||
}).then(p => p?.value ?? 'public')
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,7 @@ export function auth(required: boolean, scopes: string[] = []) {
|
||||
if (required) {
|
||||
ctx.status = 403;
|
||||
ctx.body = { error: "This action is outside the authorized scopes" };
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx.user = null;
|
||||
ctx.scopes = [];
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { MastoContext, logger } from "@/server/api/mastodon/index.js";
|
||||
import { logger, MastoContext } from "@/server/api/mastodon/index.js";
|
||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
|
||||
export class MastoApiError extends Error {
|
||||
statusCode: number;
|
||||
|
||||
constructor(statusCode: number, message?: string) {
|
||||
if (message == null) {
|
||||
switch (statusCode) {
|
||||
@ -26,20 +27,16 @@ export async function CatchErrorsMiddleware(ctx: MastoContext, next: () => Promi
|
||||
} catch (e: any) {
|
||||
if (e instanceof MastoApiError) {
|
||||
ctx.status = e.statusCode;
|
||||
}
|
||||
else if (e instanceof IdentifiableError) {
|
||||
} else if (e instanceof IdentifiableError) {
|
||||
ctx.status = 400;
|
||||
}
|
||||
else if (e instanceof ApiError) {
|
||||
} else if (e instanceof ApiError) {
|
||||
ctx.status = e.httpStatusCode ?? 500;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logger.error(`Error occured in ${ctx.method} ${ctx.path}:`);
|
||||
if (e instanceof Error) {
|
||||
if (e.stack) logger.error(e.stack);
|
||||
else logger.error(`${e.name}: ${e.message}`);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logger.error(e);
|
||||
}
|
||||
ctx.status = 500;
|
||||
|
Loading…
Reference in New Issue
Block a user