From 44174127872738f8ac65252546b2b1dbf53aa389 Mon Sep 17 00:00:00 2001 From: CGsama Date: Sun, 16 Jul 2023 01:21:49 -0400 Subject: [PATCH] Export notes with file detail (#11293) --- .../queue/processors/ExportNotesProcessorService.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts index 75f32ffee3..107c8e4ce8 100644 --- a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts @@ -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 { +function serialize(note: Note, poll: Poll | null = null, files: Map['id'], Packed<'DriveFile'>>): Record { return { id: note.id, text: note.text, createdAt: note.createdAt, fileIds: note.fileIds, + files: files, replyId: note.replyId, renoteId: note.renoteId, poll: poll,