mirror of
https://github.com/paricafe/misskey.git
synced 2025-01-10 16:40:50 -06:00
c1514ce91d
Fix #13290
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { UsersRepository } from '@/models/_.js';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireModerator: true,
|
|
kind: 'write:admin:unset-user-avatar',
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['userId'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
@Inject(DI.usersRepository)
|
|
private usersRepository: UsersRepository,
|
|
|
|
private moderationLogService: ModerationLogService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const user = await this.usersRepository.findOneBy({ id: ps.userId });
|
|
|
|
if (user == null) {
|
|
throw new Error('user not found');
|
|
}
|
|
|
|
if (user.avatarId == null) return;
|
|
|
|
await this.usersRepository.update(user.id, {
|
|
avatar: null,
|
|
avatarId: null,
|
|
avatarUrl: null,
|
|
avatarBlurhash: null,
|
|
});
|
|
|
|
this.moderationLogService.log(me, 'unsetUserAvatar', {
|
|
userId: user.id,
|
|
userUsername: user.username,
|
|
userHost: user.host,
|
|
fileId: user.avatarId,
|
|
});
|
|
});
|
|
}
|
|
}
|