From e49b8d0ef3c429ecbb9c008c98d3041974e082c5 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 2 Dec 2022 18:58:19 +0100 Subject: [PATCH] server: remove unnecessary apLogger aliases --- .../remote/activitypub/kernel/accept/index.ts | 6 ++---- .../activitypub/kernel/announce/index.ts | 4 +--- .../activitypub/kernel/announce/note.ts | 11 +++------- .../remote/activitypub/kernel/create/index.ts | 8 +++----- .../remote/activitypub/kernel/delete/actor.ts | 6 ++---- .../remote/activitypub/kernel/delete/note.ts | 5 +---- .../remote/activitypub/kernel/reject/index.ts | 6 ++---- .../remote/activitypub/kernel/undo/index.ts | 7 ++----- .../src/remote/activitypub/models/image.ts | 4 +--- .../src/remote/activitypub/models/note.ts | 20 +++++++++---------- .../src/remote/activitypub/models/person.ts | 18 ++++++++--------- 11 files changed, 34 insertions(+), 61 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/accept/index.ts b/packages/backend/src/remote/activitypub/kernel/accept/index.ts index b5102da9b..ee0b6ed88 100644 --- a/packages/backend/src/remote/activitypub/kernel/accept/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/accept/index.ts @@ -4,17 +4,15 @@ import Resolver from '@/remote/activitypub/resolver.js'; import { IAccept, isFollow, getApType } from '@/remote/activitypub/type.js'; import acceptFollow from './follow.js'; -const logger = apLogger; - export default async (actor: CacheableRemoteUser, activity: IAccept): Promise => { const uri = activity.id || activity; - logger.info(`Accept: ${uri}`); + apLogger.info(`Accept: ${uri}`); const resolver = new Resolver(); const object = await resolver.resolve(activity.object).catch(e => { - logger.error(`Resolution failed: ${e}`); + apLogger.error(`Resolution failed: ${e}`); throw e; }); diff --git a/packages/backend/src/remote/activitypub/kernel/announce/index.ts b/packages/backend/src/remote/activitypub/kernel/announce/index.ts index 7a7e3b428..e32e8fef4 100644 --- a/packages/backend/src/remote/activitypub/kernel/announce/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/announce/index.ts @@ -4,12 +4,10 @@ import Resolver from '@/remote/activitypub/resolver.js'; import { IAnnounce, getApId } from '@/remote/activitypub/type.js'; import announceNote from './note.js'; -const logger = apLogger; - export default async (actor: CacheableRemoteUser, activity: IAnnounce): Promise => { const uri = getApId(activity); - logger.info(`Announce: ${uri}`); + apLogger.info(`Announce: ${uri}`); const resolver = new Resolver(); diff --git a/packages/backend/src/remote/activitypub/kernel/announce/note.ts b/packages/backend/src/remote/activitypub/kernel/announce/note.ts index 0783d1ea0..527b6b09c 100644 --- a/packages/backend/src/remote/activitypub/kernel/announce/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/announce/note.ts @@ -11,11 +11,6 @@ import { fetchNote, resolveNote } from '@/remote/activitypub/models/note.js'; import Resolver from '@/remote/activitypub/resolver.js'; import { IAnnounce, getApId } from '@/remote/activitypub/type.js'; -const logger = apLogger; - -/** - * アナウンスアクティビティを捌きます - */ export default async function(resolver: Resolver, actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise { const uri = getApId(activity); @@ -44,18 +39,18 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac // 対象が4xxならスキップ if (e instanceof StatusError) { if (e.isClientError) { - logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`); + apLogger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`); return; } - logger.warn(`Error in announce target ${targetUri} - ${e.statusCode || e}`); + apLogger.warn(`Error in announce target ${targetUri} - ${e.statusCode || e}`); } throw e; } if (!await Notes.isVisibleForMe(renote, actor.id)) return 'skip: invalid actor for this activity'; - logger.info(`Creating the (Re)Note: ${uri}`); + apLogger.info(`Creating the (Re)Note: ${uri}`); const activityAudience = await parseAudience(actor, activity.to, activity.cc); diff --git a/packages/backend/src/remote/activitypub/kernel/create/index.ts b/packages/backend/src/remote/activitypub/kernel/create/index.ts index beaefb3f1..e7531d3d3 100644 --- a/packages/backend/src/remote/activitypub/kernel/create/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/create/index.ts @@ -5,12 +5,10 @@ import { ICreate, getApId, isPost, getApType } from '../../type.js'; import { apLogger } from '../../logger.js'; import createNote from './note.js'; -const logger = apLogger; - export default async (actor: CacheableRemoteUser, activity: ICreate): Promise => { const uri = getApId(activity); - logger.info(`Create: ${uri}`); + apLogger.info(`Create: ${uri}`); // copy audiences between activity <=> object. if (typeof activity.object === 'object') { @@ -31,13 +29,13 @@ export default async (actor: CacheableRemoteUser, activity: ICreate): Promise { - logger.error(`Resolution failed: ${e}`); + apLogger.error(`Resolution failed: ${e}`); throw e; }); if (isPost(object)) { createNote(resolver, actor, object, false, activity); } else { - logger.warn(`Unknown type: ${getApType(object)}`); + apLogger.warn(`Unknown type: ${getApType(object)}`); } }; diff --git a/packages/backend/src/remote/activitypub/kernel/delete/actor.ts b/packages/backend/src/remote/activitypub/kernel/delete/actor.ts index ca347beb0..7d09d8fa3 100644 --- a/packages/backend/src/remote/activitypub/kernel/delete/actor.ts +++ b/packages/backend/src/remote/activitypub/kernel/delete/actor.ts @@ -3,10 +3,8 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; import { Users } from '@/models/index.js'; import { apLogger } from '@/remote/activitypub/logger.js'; -const logger = apLogger; - export async function deleteActor(actor: CacheableRemoteUser, uri: string): Promise { - logger.info(`Deleting the Actor: ${uri}`); + apLogger.info(`Deleting the Actor: ${uri}`); if (actor.uri !== uri) { return `skip: delete actor ${actor.uri} !== ${uri}`; @@ -14,7 +12,7 @@ export async function deleteActor(actor: CacheableRemoteUser, uri: string): Prom const user = await Users.findOneByOrFail({ id: actor.id }); if (user.isDeleted) { - logger.info('skip: already deleted'); + apLogger.info('skip: already deleted'); } const job = await createDeleteAccountJob(actor); diff --git a/packages/backend/src/remote/activitypub/kernel/delete/note.ts b/packages/backend/src/remote/activitypub/kernel/delete/note.ts index 6f64b66e2..9eee00732 100644 --- a/packages/backend/src/remote/activitypub/kernel/delete/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/delete/note.ts @@ -5,10 +5,8 @@ import { deleteMessage } from '@/services/messages/delete.js'; import DbResolver from '@/remote/activitypub/db-resolver.js'; import { apLogger } from '@/remote/activitypub/logger.js'; -const logger = apLogger; - export default async function(actor: CacheableRemoteUser, uri: string): Promise { - logger.info(`Deleting the Note: ${uri}`); + apLogger.info(`Deleting the Note: ${uri}`); const unlock = await getApLock(uri); @@ -25,7 +23,6 @@ export default async function(actor: CacheableRemoteUser, uri: string): Promise< } await deleteMessage(message); - return 'ok: message deleted'; } diff --git a/packages/backend/src/remote/activitypub/kernel/reject/index.ts b/packages/backend/src/remote/activitypub/kernel/reject/index.ts index 138b7e35f..f75b8b44f 100644 --- a/packages/backend/src/remote/activitypub/kernel/reject/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/reject/index.ts @@ -4,17 +4,15 @@ import { IReject, isFollow, getApType } from '../../type.js'; import Resolver from '../../resolver.js'; import rejectFollow from './follow.js'; -const logger = apLogger; - export default async (actor: CacheableRemoteUser, activity: IReject): Promise => { const uri = activity.id || activity; - logger.info(`Reject: ${uri}`); + apLogger.info(`Reject: ${uri}`); const resolver = new Resolver(); const object = await resolver.resolve(activity.object).catch(e => { - logger.error(`Resolution failed: ${e}`); + apLogger.error(`Resolution failed: ${e}`); throw e; }); diff --git a/packages/backend/src/remote/activitypub/kernel/undo/index.ts b/packages/backend/src/remote/activitypub/kernel/undo/index.ts index d69dd0f47..d85a68fdc 100644 --- a/packages/backend/src/remote/activitypub/kernel/undo/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/undo/index.ts @@ -8,8 +8,6 @@ import undoLike from './like.js'; import undoAccept from './accept.js'; import { undoAnnounce } from './announce.js'; -const logger = apLogger; - export default async (actor: CacheableRemoteUser, activity: IUndo): Promise => { if ('actor' in activity && actor.uri !== activity.actor) { throw new Error('invalid actor'); @@ -17,12 +15,11 @@ export default async (actor: CacheableRemoteUser, activity: IUndo): Promise { - logger.error(`Resolution failed: ${e}`); + apLogger.error(`Resolution failed: ${e}`); throw e; }); diff --git a/packages/backend/src/remote/activitypub/models/image.ts b/packages/backend/src/remote/activitypub/models/image.ts index 84b86a0ef..d9d533f4d 100644 --- a/packages/backend/src/remote/activitypub/models/image.ts +++ b/packages/backend/src/remote/activitypub/models/image.ts @@ -8,8 +8,6 @@ import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js'; import Resolver from '../resolver.js'; import { apLogger } from '../logger.js'; -const logger = apLogger; - /** * Imageを作成します。 */ @@ -25,7 +23,7 @@ export async function createImage(actor: CacheableRemoteUser, value: any): Promi throw new Error('invalid image: url not privided'); } - logger.info(`Creating the Image: ${image.url}`); + apLogger.info(`Creating the Image: ${image.url}`); const instance = await fetchMeta(); diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index c63684809..528d1b2db 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -28,8 +28,6 @@ import { extractApHashtags } from './tag.js'; import { extractPollFromQuestion } from './question.js'; import { extractApMentions } from './mention.js'; -const logger = apLogger; - export function validateNote(object: any, uri: string) { const expectHost = extractDbHost(uri); @@ -71,7 +69,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver = const entryUri = getApId(value); const err = validateNote(object, entryUri); if (err) { - logger.error(`${err.message}`, { + apLogger.error(`${err.message}`, { resolver: { history: resolver.getHistory(), }, @@ -83,9 +81,9 @@ export async function createNote(value: string | IObject, resolver?: Resolver = const note: IPost = object; - logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`); + apLogger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`); - logger.info(`Creating the Note: ${note.id}`); + apLogger.info(`Creating the Note: ${note.id}`); // 投稿者をフェッチ const actor = await resolvePerson(getOneApId(note.attributedTo), resolver) as CacheableRemoteUser; @@ -129,7 +127,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver = const reply: Note | null = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver).then(x => { if (x == null) { - logger.warn('Specified inReplyTo, but nout found'); + apLogger.warn('Specified inReplyTo, but nout found'); throw new Error('inReplyTo not found'); } else { return x; @@ -146,7 +144,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver = } } - logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`); + apLogger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`); throw e; }) : null; @@ -210,9 +208,9 @@ export async function createNote(value: string | IObject, resolver?: Resolver = const tryCreateVote = async (name: string, index: number): Promise => { if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) { - logger.warn(`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); + apLogger.warn(`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); } else if (index >= 0) { - logger.info(`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); + apLogger.info(`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); await vote(actor, reply, index); // リモートフォロワーにUpdate配信 @@ -227,7 +225,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver = } const emojis = await extractEmojis(note.tag || [], actor.host).catch(e => { - logger.info(`extractEmojis: ${e}`); + apLogger.info(`extractEmojis: ${e}`); return [] as Emoji[]; }); @@ -341,7 +339,7 @@ export async function extractEmojis(tags: IObject | IObject[], idnHost: string): return exists; } - logger.info(`register emoji host=${host}, name=${name}`); + apLogger.info(`register emoji host=${host}, name=${name}`); return await Emojis.insert({ id: genId(), diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index f5bb0f280..cf13c1cec 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -32,8 +32,6 @@ import { extractApHashtags } from './tag.js'; import { resolveNote, extractEmojis } from './note.js'; import { resolveImage } from './image.js'; -const logger = apLogger; - const nameLength = 128; const summaryLength = 2048; @@ -145,7 +143,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv const person = validateActor(object, uri); - logger.info(`Creating the Person: ${person.id}`); + apLogger.info(`Creating the Person: ${person.id}`); const host = toPuny(new URL(object.id).hostname); @@ -217,7 +215,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv throw new Error('already registered'); } } else { - logger.error(e instanceof Error ? e : new Error(e as string)); + apLogger.error(e instanceof Error ? e : new Error(e as string)); throw e; } } @@ -258,7 +256,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv //#region カスタム絵文字取得 const emojis = await extractEmojis(person.tag || [], host).catch(e => { - logger.info(`extractEmojis: ${e}`); + apLogger.info(`extractEmojis: ${e}`); return [] as Emoji[]; }); @@ -269,7 +267,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv }); //#endregion - await updateFeatured(user!.id, resolver).catch(err => logger.error(err)); + await updateFeatured(user!.id, resolver).catch(err => apLogger.error(err)); return user!; } @@ -301,7 +299,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv const person = validateActor(object, uri); - logger.info(`Updating the Person: ${person.id}`); + apLogger.info(`Updating the Person: ${person.id}`); // アバターとヘッダー画像をフェッチ const [avatar, banner] = await Promise.all([ @@ -315,7 +313,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv // カスタム絵文字取得 const emojis = await extractEmojis(person.tag || [], exist.host).catch(e => { - logger.info(`extractEmojis: ${e}`); + apLogger.info(`extractEmojis: ${e}`); return [] as Emoji[]; }); @@ -380,7 +378,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv followerSharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined), }); - await updateFeatured(exist.id, resolver).catch(err => logger.error(err)); + await updateFeatured(exist.id, resolver).catch(err => apLogger.error(err)); } /** @@ -463,7 +461,7 @@ export async function updateFeatured(userId: User['id'], resolver?: Resolver) { if (!Users.isRemoteUser(user)) return; if (!user.featured) return; - logger.info(`Updating the featured: ${user.uri}`); + apLogger.info(`Updating the featured: ${user.uri}`); if (resolver == null) resolver = new Resolver();