2023-11-17 20:20:11 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* 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';
|
2023-11-19 01:18:57 +00:00
|
|
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
2023-11-17 20:20:11 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2023-12-18 03:32:26 +00:00
|
|
|
kind: 'write:admin',
|
|
|
|
|
2023-11-17 20:20:11 +00:00
|
|
|
requireCredential: true,
|
|
|
|
requireModerator: true,
|
|
|
|
} 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,
|
2023-11-19 01:18:57 +00:00
|
|
|
|
|
|
|
private moderationLogService: ModerationLogService,
|
2023-11-17 20:20:11 +00:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const user = await this.usersRepository.findOneBy({ id: ps.userId });
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
throw new Error('user not found');
|
|
|
|
}
|
2023-12-18 03:32:26 +00:00
|
|
|
|
2023-11-19 01:18:57 +00:00
|
|
|
if (user.avatarId == null) return;
|
2023-11-17 20:20:11 +00:00
|
|
|
|
|
|
|
await this.usersRepository.update(user.id, {
|
|
|
|
avatar: null,
|
|
|
|
avatarId: null,
|
|
|
|
avatarUrl: null,
|
|
|
|
avatarBlurhash: null,
|
|
|
|
});
|
2023-11-19 01:18:57 +00:00
|
|
|
|
|
|
|
this.moderationLogService.log(me, 'unsetUserAvatar', {
|
|
|
|
userId: user.id,
|
|
|
|
userUsername: user.username,
|
|
|
|
userHost: user.host,
|
|
|
|
fileId: user.avatarId,
|
|
|
|
});
|
2023-11-17 20:20:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|