1
0
forked from mirror/misskey

Export notes with file detail (#11293)

This commit is contained in:
CGsama 2023-07-16 01:21:49 -04:00 committed by GitHub
parent 96cde67b2c
commit 4417412787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,8 @@ import { bindThis } from '@/decorators.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { DbJobDataWithUser } from '../types.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
import { Packed } from '@/misc/json-schema.js';
@Injectable()
export class ExportNotesProcessorService {
@ -34,6 +36,8 @@ export class ExportNotesProcessorService {
private driveService: DriveService,
private queueLoggerService: QueueLoggerService,
private driveFileEntityService: DriveFileEntityService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('export-notes');
}
@ -97,7 +101,8 @@ export class ExportNotesProcessorService {
if (note.hasPoll) {
poll = await this.pollsRepository.findOneByOrFail({ noteId: note.id });
}
const content = JSON.stringify(serialize(note, poll));
const files = await this.driveFileEntityService.packManyByIds(note.fileIds);
const content = JSON.stringify(serialize(note, poll, files));
const isFirst = exportedNotesCount === 0;
await write(isFirst ? content : ',\n' + content);
exportedNotesCount++;
@ -125,12 +130,13 @@ export class ExportNotesProcessorService {
}
}
function serialize(note: Note, poll: Poll | null = null): Record<string, unknown> {
function serialize(note: Note, poll: Poll | null = null, files: Map<Packed<'DriveFile'>['id'], Packed<'DriveFile'>>): Record<string, unknown> {
return {
id: note.id,
text: note.text,
createdAt: note.createdAt,
fileIds: note.fileIds,
files: files,
replyId: note.replyId,
renoteId: note.renoteId,
poll: poll,