feat: AIによるNSFW検出を無視できるポリシーを追加 (MisskeyIO#500)

* feat: AIによるNSFW検出を無視できるポリシーを追加

* refactor: skipNsfwCheckの条件を同じようにまとめた
This commit is contained in:
kabo2468 2024-03-03 03:48:47 +09:00 committed by GitHub
parent c0dbdd78c1
commit d624547874
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 52 additions and 11 deletions

View file

@ -459,15 +459,14 @@ export class DriveService {
}: AddFileArgs): Promise<MiDriveFile> {
let skipNsfwCheck = false;
const instance = await this.metaService.fetch();
const userRoleNSFW = user && (await this.roleService.getUserPolicies(user.id)).alwaysMarkNsfw;
if (user == null) {
skipNsfwCheck = true;
} else if (userRoleNSFW) {
skipNsfwCheck = true;
}
if (instance.sensitiveMediaDetection === 'none') skipNsfwCheck = true;
if (user && instance.sensitiveMediaDetection === 'local' && this.userEntityService.isRemoteUser(user)) skipNsfwCheck = true;
if (user && instance.sensitiveMediaDetection === 'remote' && this.userEntityService.isLocalUser(user)) skipNsfwCheck = true;
const policies = user && await this.roleService.getUserPolicies(user.id);
const userRoleNSFW = policies?.alwaysMarkNsfw;
skipNsfwCheck ||= user == null;
skipNsfwCheck ||= !!userRoleNSFW;
skipNsfwCheck ||= !!policies?.skipNsfwDetection;
skipNsfwCheck ||= instance.sensitiveMediaDetection === 'none';
skipNsfwCheck ||= !!(user && instance.sensitiveMediaDetection === 'local' && this.userEntityService.isRemoteUser(user));
skipNsfwCheck ||= !!(user && instance.sensitiveMediaDetection === 'remote' && this.userEntityService.isLocalUser(user));
const info = await this.fileInfoService.getFileInfo(path, {
skipSensitiveDetection: skipNsfwCheck,
@ -511,11 +510,10 @@ export class DriveService {
this.registerLogger.debug(`ADD DRIVE FILE: user ${user?.id ?? 'not set'}, name ${detectedName}, tmp ${path}`);
//#region Check drive usage
if (user && !isLink) {
if (user && policies && !isLink) {
const usage = await this.driveFileEntityService.calcDriveUsageOf(user);
const isLocalUser = this.userEntityService.isLocalUser(user);
const policies = await this.roleService.getUserPolicies(user.id);
const driveCapacity = 1024 * 1024 * policies.driveCapacityMb;
this.registerLogger.debug('drive capacity override applied');
this.registerLogger.debug(`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${usage + info.size}bytes`);

View file

@ -55,6 +55,7 @@ export type RolePolicies = {
canHideAds: boolean;
driveCapacityMb: number;
alwaysMarkNsfw: boolean;
skipNsfwDetection: boolean;
pinLimit: number;
antennaLimit: number;
antennaNotesLimit: number;
@ -91,6 +92,7 @@ export const DEFAULT_POLICIES: RolePolicies = {
canHideAds: false,
driveCapacityMb: 100,
alwaysMarkNsfw: false,
skipNsfwDetection: false,
pinLimit: 5,
antennaLimit: 5,
antennaNotesLimit: 200,
@ -366,6 +368,7 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
canHideAds: calc('canHideAds', vs => vs.some(v => v === true)),
driveCapacityMb: calc('driveCapacityMb', vs => Math.max(...vs)),
alwaysMarkNsfw: calc('alwaysMarkNsfw', vs => vs.some(v => v === true)),
skipNsfwDetection: calc('skipNsfwDetection', vs => vs.some(v => v === true)),
pinLimit: calc('pinLimit', vs => Math.max(...vs)),
antennaLimit: calc('antennaLimit', vs => Math.max(...vs)),
antennaNotesLimit: calc('antennaNotesLimit', vs => Math.max(...vs)),