Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Opensearch利用時ファイルのセンシティブ状態が変更されたとき変更されるように #501

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Cherrypick 4.11.1

### Server
- Enhance: リモートユーザーの`/api/clips/show`と`/api/users/clips`の応答にemojisを追加 [#466](https://github.com/yojo-art/cherrypick/pull/466)
- Fix: Opensearch利用時ファイルのセンシティブ状態が変更されたとき変更されるように
- Change: `notes/advanced-search`で`query`が必須ではなくなりました

### Misc
Expand Down
35 changes: 35 additions & 0 deletions packages/backend/src/core/AdvancedSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,41 @@ export class AdvancedSearchService {
this.index(this.opensearchNoteIndex as string, note.id, body);
}

@bindThis
public async updateNoteSensitive(fileId: string) {
if (!this.opensearch) return;

const limit = 100;
let latestid = undefined;

while (true) {
const notes = await this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), latestid, undefined)
.andWhere(':file <@ note.fileIds', { file: [fileId] })
.limit(limit)
.getMany();

if (notes.length === 0 ) break;

notes.forEach((note) => {
this.driveService.getSensitiveFileCount(note.fileIds)
.then((sensitiveCount) => {
const nonSensitiveCount = note.fileIds.length - sensitiveCount;
const body = {
fileIds: note.fileIds,
sensitiveFileCount: sensitiveCount,
nonSensitiveFileCount: nonSensitiveCount,
};
this.opensearch?.update({
id: note.id,
index: this.opensearchNoteIndex as string,
body: { doc: body },
});
});
latestid = note.id;
});
}
}

@bindThis
private async index(index: string, id: string, body: any ) {
if (!this.opensearch) return;
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { randomUUID } from 'node:crypto';
import * as fs from 'node:fs';
import { Inject, Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import sharp from 'sharp';
import { sharpBmp } from '@misskey-dev/sharp-read-bmp';
import { IsNull } from 'typeorm';
Expand Down Expand Up @@ -45,6 +46,7 @@ import { isMimeImage } from '@/misc/is-mime-image.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { RegistryApiService } from '@/core/RegistryApiService.js';
import { AdvancedSearchService } from './AdvancedSearchService.js';

type AddFileArgs = {
/** User who wish to add file */
Expand Down Expand Up @@ -95,6 +97,7 @@ export class DriveService {
private registerLogger: Logger;
private downloaderLogger: Logger;
private deleteLogger: Logger;
private advancedSearchService: AdvancedSearchService;

constructor(
@Inject(DI.config)
Expand Down Expand Up @@ -131,13 +134,18 @@ export class DriveService {
private instanceChart: InstanceChart,
private utilityService: UtilityService,
private registryApiService: RegistryApiService,
private moduleRef: ModuleRef,
) {
const logger = new Logger('drive', 'blue');
this.registerLogger = logger.createSubLogger('register', 'yellow');
this.downloaderLogger = logger.createSubLogger('downloader');
this.deleteLogger = logger.createSubLogger('delete');
}

onModuleInit() {
this.advancedSearchService = this.moduleRef.get('AdvancedSearchService');
}

/***
* Save file
* @param path Path for original
Expand Down Expand Up @@ -767,6 +775,7 @@ export class DriveService {
}
}
}
this.advancedSearchService.updateNoteSensitive(file.id);

return fileObj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
throw new ApiError(meta.errors.unimplemented);
}
}
throw new ApiError();
throw err;
},
);

Expand Down
Loading