server: remove unnecessary apLogger aliases

This commit is contained in:
Johann150 2022-12-02 18:58:19 +01:00
parent 7d3d0f858c
commit e49b8d0ef3
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
11 changed files with 34 additions and 61 deletions

View file

@ -4,17 +4,15 @@ import Resolver from '@/remote/activitypub/resolver.js';
import { IAccept, isFollow, getApType } from '@/remote/activitypub/type.js'; import { IAccept, isFollow, getApType } from '@/remote/activitypub/type.js';
import acceptFollow from './follow.js'; import acceptFollow from './follow.js';
const logger = apLogger;
export default async (actor: CacheableRemoteUser, activity: IAccept): Promise<string> => { export default async (actor: CacheableRemoteUser, activity: IAccept): Promise<string> => {
const uri = activity.id || activity; const uri = activity.id || activity;
logger.info(`Accept: ${uri}`); apLogger.info(`Accept: ${uri}`);
const resolver = new Resolver(); const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch(e => { const object = await resolver.resolve(activity.object).catch(e => {
logger.error(`Resolution failed: ${e}`); apLogger.error(`Resolution failed: ${e}`);
throw e; throw e;
}); });

View file

@ -4,12 +4,10 @@ import Resolver from '@/remote/activitypub/resolver.js';
import { IAnnounce, getApId } from '@/remote/activitypub/type.js'; import { IAnnounce, getApId } from '@/remote/activitypub/type.js';
import announceNote from './note.js'; import announceNote from './note.js';
const logger = apLogger;
export default async (actor: CacheableRemoteUser, activity: IAnnounce): Promise<void> => { export default async (actor: CacheableRemoteUser, activity: IAnnounce): Promise<void> => {
const uri = getApId(activity); const uri = getApId(activity);
logger.info(`Announce: ${uri}`); apLogger.info(`Announce: ${uri}`);
const resolver = new Resolver(); const resolver = new Resolver();

View file

@ -11,11 +11,6 @@ import { fetchNote, resolveNote } from '@/remote/activitypub/models/note.js';
import Resolver from '@/remote/activitypub/resolver.js'; import Resolver from '@/remote/activitypub/resolver.js';
import { IAnnounce, getApId } from '@/remote/activitypub/type.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<void> { export default async function(resolver: Resolver, actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
const uri = getApId(activity); const uri = getApId(activity);
@ -44,18 +39,18 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac
// 対象が4xxならスキップ // 対象が4xxならスキップ
if (e instanceof StatusError) { if (e instanceof StatusError) {
if (e.isClientError) { if (e.isClientError) {
logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`); apLogger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`);
return; return;
} }
logger.warn(`Error in announce target ${targetUri} - ${e.statusCode || e}`); apLogger.warn(`Error in announce target ${targetUri} - ${e.statusCode || e}`);
} }
throw e; throw e;
} }
if (!await Notes.isVisibleForMe(renote, actor.id)) return 'skip: invalid actor for this activity'; 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); const activityAudience = await parseAudience(actor, activity.to, activity.cc);

View file

@ -5,12 +5,10 @@ import { ICreate, getApId, isPost, getApType } from '../../type.js';
import { apLogger } from '../../logger.js'; import { apLogger } from '../../logger.js';
import createNote from './note.js'; import createNote from './note.js';
const logger = apLogger;
export default async (actor: CacheableRemoteUser, activity: ICreate): Promise<void> => { export default async (actor: CacheableRemoteUser, activity: ICreate): Promise<void> => {
const uri = getApId(activity); const uri = getApId(activity);
logger.info(`Create: ${uri}`); apLogger.info(`Create: ${uri}`);
// copy audiences between activity <=> object. // copy audiences between activity <=> object.
if (typeof activity.object === 'object') { if (typeof activity.object === 'object') {
@ -31,13 +29,13 @@ export default async (actor: CacheableRemoteUser, activity: ICreate): Promise<vo
const resolver = new Resolver(); const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch(e => { const object = await resolver.resolve(activity.object).catch(e => {
logger.error(`Resolution failed: ${e}`); apLogger.error(`Resolution failed: ${e}`);
throw e; throw e;
}); });
if (isPost(object)) { if (isPost(object)) {
createNote(resolver, actor, object, false, activity); createNote(resolver, actor, object, false, activity);
} else { } else {
logger.warn(`Unknown type: ${getApType(object)}`); apLogger.warn(`Unknown type: ${getApType(object)}`);
} }
}; };

View file

@ -3,10 +3,8 @@ import { CacheableRemoteUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js'; import { Users } from '@/models/index.js';
import { apLogger } from '@/remote/activitypub/logger.js'; import { apLogger } from '@/remote/activitypub/logger.js';
const logger = apLogger;
export async function deleteActor(actor: CacheableRemoteUser, uri: string): Promise<string> { export async function deleteActor(actor: CacheableRemoteUser, uri: string): Promise<string> {
logger.info(`Deleting the Actor: ${uri}`); apLogger.info(`Deleting the Actor: ${uri}`);
if (actor.uri !== uri) { if (actor.uri !== uri) {
return `skip: delete actor ${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 }); const user = await Users.findOneByOrFail({ id: actor.id });
if (user.isDeleted) { if (user.isDeleted) {
logger.info('skip: already deleted'); apLogger.info('skip: already deleted');
} }
const job = await createDeleteAccountJob(actor); const job = await createDeleteAccountJob(actor);

View file

@ -5,10 +5,8 @@ import { deleteMessage } from '@/services/messages/delete.js';
import DbResolver from '@/remote/activitypub/db-resolver.js'; import DbResolver from '@/remote/activitypub/db-resolver.js';
import { apLogger } from '@/remote/activitypub/logger.js'; import { apLogger } from '@/remote/activitypub/logger.js';
const logger = apLogger;
export default async function(actor: CacheableRemoteUser, uri: string): Promise<string> { export default async function(actor: CacheableRemoteUser, uri: string): Promise<string> {
logger.info(`Deleting the Note: ${uri}`); apLogger.info(`Deleting the Note: ${uri}`);
const unlock = await getApLock(uri); const unlock = await getApLock(uri);
@ -25,7 +23,6 @@ export default async function(actor: CacheableRemoteUser, uri: string): Promise<
} }
await deleteMessage(message); await deleteMessage(message);
return 'ok: message deleted'; return 'ok: message deleted';
} }

View file

@ -4,17 +4,15 @@ import { IReject, isFollow, getApType } from '../../type.js';
import Resolver from '../../resolver.js'; import Resolver from '../../resolver.js';
import rejectFollow from './follow.js'; import rejectFollow from './follow.js';
const logger = apLogger;
export default async (actor: CacheableRemoteUser, activity: IReject): Promise<string> => { export default async (actor: CacheableRemoteUser, activity: IReject): Promise<string> => {
const uri = activity.id || activity; const uri = activity.id || activity;
logger.info(`Reject: ${uri}`); apLogger.info(`Reject: ${uri}`);
const resolver = new Resolver(); const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch(e => { const object = await resolver.resolve(activity.object).catch(e => {
logger.error(`Resolution failed: ${e}`); apLogger.error(`Resolution failed: ${e}`);
throw e; throw e;
}); });

View file

@ -8,8 +8,6 @@ import undoLike from './like.js';
import undoAccept from './accept.js'; import undoAccept from './accept.js';
import { undoAnnounce } from './announce.js'; import { undoAnnounce } from './announce.js';
const logger = apLogger;
export default async (actor: CacheableRemoteUser, activity: IUndo): Promise<string> => { export default async (actor: CacheableRemoteUser, activity: IUndo): Promise<string> => {
if ('actor' in activity && actor.uri !== activity.actor) { if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor'); throw new Error('invalid actor');
@ -17,12 +15,11 @@ export default async (actor: CacheableRemoteUser, activity: IUndo): Promise<stri
const uri = activity.id || activity; const uri = activity.id || activity;
logger.info(`Undo: ${uri}`); apLogger.info(`Undo: ${uri}`);
const resolver = new Resolver(); const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch(e => { const object = await resolver.resolve(activity.object).catch(e => {
logger.error(`Resolution failed: ${e}`); apLogger.error(`Resolution failed: ${e}`);
throw e; throw e;
}); });

View file

@ -8,8 +8,6 @@ import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js';
import Resolver from '../resolver.js'; import Resolver from '../resolver.js';
import { apLogger } from '../logger.js'; import { apLogger } from '../logger.js';
const logger = apLogger;
/** /**
* Imageを作成します * Imageを作成します
*/ */
@ -25,7 +23,7 @@ export async function createImage(actor: CacheableRemoteUser, value: any): Promi
throw new Error('invalid image: url not privided'); 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(); const instance = await fetchMeta();

View file

@ -28,8 +28,6 @@ import { extractApHashtags } from './tag.js';
import { extractPollFromQuestion } from './question.js'; import { extractPollFromQuestion } from './question.js';
import { extractApMentions } from './mention.js'; import { extractApMentions } from './mention.js';
const logger = apLogger;
export function validateNote(object: any, uri: string) { export function validateNote(object: any, uri: string) {
const expectHost = extractDbHost(uri); const expectHost = extractDbHost(uri);
@ -71,7 +69,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver =
const entryUri = getApId(value); const entryUri = getApId(value);
const err = validateNote(object, entryUri); const err = validateNote(object, entryUri);
if (err) { if (err) {
logger.error(`${err.message}`, { apLogger.error(`${err.message}`, {
resolver: { resolver: {
history: resolver.getHistory(), history: resolver.getHistory(),
}, },
@ -83,9 +81,9 @@ export async function createNote(value: string | IObject, resolver?: Resolver =
const note: IPost = object; 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; 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 const reply: Note | null = note.inReplyTo
? await resolveNote(note.inReplyTo, resolver).then(x => { ? await resolveNote(note.inReplyTo, resolver).then(x => {
if (x == null) { if (x == null) {
logger.warn('Specified inReplyTo, but nout found'); apLogger.warn('Specified inReplyTo, but nout found');
throw new Error('inReplyTo not found'); throw new Error('inReplyTo not found');
} else { } else {
return x; 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; throw e;
}) })
: null; : null;
@ -210,9 +208,9 @@ export async function createNote(value: string | IObject, resolver?: Resolver =
const tryCreateVote = async (name: string, index: number): Promise<null> => { const tryCreateVote = async (name: string, index: number): Promise<null> => {
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) { 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) { } 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); await vote(actor, reply, index);
// リモートフォロワーにUpdate配信 // リモートフォロワーにUpdate配信
@ -227,7 +225,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver =
} }
const emojis = await extractEmojis(note.tag || [], actor.host).catch(e => { const emojis = await extractEmojis(note.tag || [], actor.host).catch(e => {
logger.info(`extractEmojis: ${e}`); apLogger.info(`extractEmojis: ${e}`);
return [] as Emoji[]; return [] as Emoji[];
}); });
@ -341,7 +339,7 @@ export async function extractEmojis(tags: IObject | IObject[], idnHost: string):
return exists; return exists;
} }
logger.info(`register emoji host=${host}, name=${name}`); apLogger.info(`register emoji host=${host}, name=${name}`);
return await Emojis.insert({ return await Emojis.insert({
id: genId(), id: genId(),

View file

@ -32,8 +32,6 @@ import { extractApHashtags } from './tag.js';
import { resolveNote, extractEmojis } from './note.js'; import { resolveNote, extractEmojis } from './note.js';
import { resolveImage } from './image.js'; import { resolveImage } from './image.js';
const logger = apLogger;
const nameLength = 128; const nameLength = 128;
const summaryLength = 2048; const summaryLength = 2048;
@ -145,7 +143,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
const person = validateActor(object, uri); 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); 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'); throw new Error('already registered');
} }
} else { } 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; throw e;
} }
} }
@ -258,7 +256,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
//#region カスタム絵文字取得 //#region カスタム絵文字取得
const emojis = await extractEmojis(person.tag || [], host).catch(e => { const emojis = await extractEmojis(person.tag || [], host).catch(e => {
logger.info(`extractEmojis: ${e}`); apLogger.info(`extractEmojis: ${e}`);
return [] as Emoji[]; return [] as Emoji[];
}); });
@ -269,7 +267,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
}); });
//#endregion //#endregion
await updateFeatured(user!.id, resolver).catch(err => logger.error(err)); await updateFeatured(user!.id, resolver).catch(err => apLogger.error(err));
return user!; return user!;
} }
@ -301,7 +299,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv
const person = validateActor(object, uri); 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([ 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 => { const emojis = await extractEmojis(person.tag || [], exist.host).catch(e => {
logger.info(`extractEmojis: ${e}`); apLogger.info(`extractEmojis: ${e}`);
return [] as Emoji[]; 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), 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 (!Users.isRemoteUser(user)) return;
if (!user.featured) 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(); if (resolver == null) resolver = new Resolver();