Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid committed Nov 4, 2024
1 parent 67505b7 commit 3ea38b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ export class NoteCreateService implements OnApplicationShutdown {
const policies = await this.roleService.getUserPolicies(user.id);

if (!policies.canCreateContent) {
this.logger.error('Request rejected because user has no permission to create content', { user: user.id, note: data });
this.logger.error('Request rejected because user has no permission to create content', { userId: user.id, note: data });
throw new IdentifiableError('5b1c2b67-50a6-4a8a-a59c-0ede40890de3', 'User has no permission to create content.');
}

if (data.visibility === 'public' && data.channel == null) {
const sensitiveWords = meta.sensitiveWords;
if (this.utilityService.isKeyWordIncluded(data.cw ?? this.utilityService.concatNoteContentsForKeyWordCheck({ text: data.text, pollChoices: data.poll?.choices }), sensitiveWords)) {
data.visibility = 'home';
this.logger.warn('Visibility changed to home because sensitive words are included', { user: user.id, note: data });
this.logger.warn('Visibility changed to home because sensitive words are included', { userId: user.id, note: data });
} else if (!policies.canPublicNote) {
data.visibility = 'home';
}
Expand All @@ -281,7 +281,7 @@ export class NoteCreateService implements OnApplicationShutdown {
);

if (hasProhibitedWords) {
this.logger.error('Request rejected because prohibited words are included', { user: user.id, note: data });
this.logger.error('Request rejected because prohibited words are included', { userId: user.id, note: data });
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Notes including prohibited words are not allowed.');
}

Expand Down Expand Up @@ -384,7 +384,7 @@ export class NoteCreateService implements OnApplicationShutdown {
if (process.env.MISSKEY_BLOCK_MENTIONS_FROM_UNFAMILIAR_REMOTE_USERS === 'true' && user.host !== null && willCauseNotification) {
const userEntity = await this.usersRepository.findOneBy({ id: user.id });
if ((userEntity?.followersCount ?? 0) === 0) {
this.logger.error('Request rejected because user has no local followers', { user: user.id, note: data });
this.logger.error('Request rejected because user has no local followers', { userId: user.id, note: data });
throw new IdentifiableError('e11b3a16-f543-4885-8eb1-66cad131dbfd', 'Notes including mentions, replies, or renotes from remote users are not allowed until user has at least one local follower.');
}
}
Expand All @@ -396,7 +396,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|| (data.visibility === 'specified' && data.visibleUsers?.some(u => u.id !== user.id))
|| (this.isQuote(data) && data.renote.userId !== user.id)
) {
this.logger.error('Request rejected because user has no permission to initiate conversation', { user: user.id, note: data });
this.logger.error('Request rejected because user has no permission to initiate conversation', { userId: user.id, note: data });
throw new IdentifiableError('332dd91b-6a00-430a-ac39-620cf60ad34b', 'Notes including mentions, replies, or renotes are not allowed.');
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export default class Logger {
constructor(domain: string | undefined, _color?: KEYWORD, _store = true, parentLogger?: Logger) {
if (parentLogger) {
this.domain = [parentLogger.domain, domain].filter(x => x).join('.') || undefined;
this.context = { ...parentLogger.context };
this.logger = parentLogger.logger.child({ name: this.domain });
return;
this.context = { ...JSON.parse(JSON.stringify(parentLogger.context)) };
} else {
this.domain = domain;
}
Expand All @@ -53,18 +51,20 @@ export default class Logger {
formatters: {
level: (label, number) => ({ severity: label, level: number }),
},
mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context }),
mixin: () => this.mixin(),
}, !envOption.logJson ? pinoPrettyStream : undefined);
}

@bindThis
private mixin(): Record<string, any> {
return { cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context };
}

public createSubLogger(domain?: string, _color?: KEYWORD, _store = true): Logger {
return new Logger(domain, _color, _store, this);
}

@bindThis
public setContext(context: Record<string, any>): void {
this.context = context;
this.context = { ...this.context, ...JSON.parse(JSON.stringify(context)) };
}

@bindThis
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/endpoints/i.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeSecrets: isSecure,
userProfile,
});
logger.info('Returning account information', { username: user.username });
logger.info('Returning account information');
return result;
} catch (error) {
logger.error('Failed to pack user entity', { error });
Expand Down

0 comments on commit 3ea38b1

Please sign in to comment.