Skip to content

Commit

Permalink
export notes with files (#2471)
Browse files Browse the repository at this point in the history
include actual file url to have complete backup
  • Loading branch information
CGsama authored Jul 30, 2023
1 parent 8374d38 commit 7743500
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/queue/processors/db/export-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from 'fs';
import { queueLogger } from '../../logger';
import addFile from '../../../services/drive/add-file';
import dateFormat = require('dateformat');
import { Users, Notes, Polls } from '../../../models';
import { DriveFiles, Users, Notes, Polls } from '../../../models';
import { MoreThan } from 'typeorm';
import { Note } from '../../../models/entities/note';
import { Poll } from '../../../models/entities/poll';
Expand Down Expand Up @@ -73,7 +73,8 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
if (note.hasPoll) {
poll = await Polls.findOne({ noteId: note.id }).then(ensure);
}
const content = JSON.stringify(serialize(note, poll));
const files = await DriveFiles.packMany(note.fileIds);
const content = JSON.stringify(serialize(note, poll, files));
await new Promise((res, rej) => {
stream.write(exportedNotesCount === 0 ? content : ',\n' + content, err => {
if (err) {
Expand Down Expand Up @@ -116,12 +117,13 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
done();
}

function serialize(note: Note, poll: Poll | null = null): any {
function serialize(note: Note, poll: Poll | null = null, files: any[]): any {
return {
id: note.id,
text: note.text,
createdAt: note.createdAt,
fileIds: note.fileIds,
files: files,
replyId: note.replyId,
renoteId: note.renoteId,
poll: poll,
Expand Down

0 comments on commit 7743500

Please sign in to comment.