mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-26 04:05:15 +00:00
upd: improve performance for checking if instance is marked as NSFW on images
This commit is contained in:
parent
4ca3c05487
commit
043f26c895
1 changed files with 8 additions and 11 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { DriveFilesRepository, InstancesRepository } from '@/models/_.js';
|
||||
import type { DriveFilesRepository } from '@/models/_.js';
|
||||
import type { MiRemoteUser } from '@/models/User.js';
|
||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
|
@ -15,10 +15,10 @@ import { DriveService } from '@/core/DriveService.js';
|
|||
import type Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { checkHttps } from '@/misc/check-https.js';
|
||||
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
||||
import { ApResolverService } from '../ApResolverService.js';
|
||||
import { ApLoggerService } from '../ApLoggerService.js';
|
||||
import type { IObject } from '../type.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApImageService {
|
||||
|
@ -28,14 +28,11 @@ export class ApImageService {
|
|||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
@Inject(DI.instancesRepository)
|
||||
private instancesRepository: InstancesRepository,
|
||||
|
||||
private metaService: MetaService,
|
||||
private apResolverService: ApResolverService,
|
||||
private driveService: DriveService,
|
||||
private apLoggerService: ApLoggerService,
|
||||
private utilityService: UtilityService,
|
||||
private federatedInstanceService: FederatedInstanceService,
|
||||
) {
|
||||
this.logger = this.apLoggerService.logger;
|
||||
}
|
||||
|
@ -73,11 +70,11 @@ export class ApImageService {
|
|||
// 2. or the image is not sensitive
|
||||
const shouldBeCached = instance.cacheRemoteFiles && (instance.cacheRemoteSensitiveFiles || !image.sensitive);
|
||||
|
||||
const shouldBeSensitive = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(actor.host), isNSFW: true });
|
||||
|
||||
if (shouldBeSensitive) {
|
||||
await this.federatedInstanceService.fetch(actor.host).then(async i => {
|
||||
if (i.isNSFW) {
|
||||
image.sensitive = true;
|
||||
}
|
||||
});
|
||||
|
||||
const file = await this.driveService.uploadFromUrl({
|
||||
url: image.url,
|
||||
|
|
Loading…
Reference in a new issue