mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-07 09:13:52 +09:00
refactor
This commit is contained in:
@ -34,16 +34,20 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
|
||||
|
||||
const stream = fs.createWriteStream(path, { flags: 'a' });
|
||||
|
||||
await new Promise<void>((res, rej) => {
|
||||
stream.write('[', err => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
rej(err);
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
const write = (text: string): Promise<void> => {
|
||||
return new Promise<void>((res, rej) => {
|
||||
stream.write(text, err => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
rej(err);
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
await write('[');
|
||||
|
||||
let exportedNotesCount = 0;
|
||||
let cursor: Note['id'] | null = null;
|
||||
@ -73,17 +77,8 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
|
||||
poll = await Polls.findOneOrFail({ noteId: note.id });
|
||||
}
|
||||
const content = JSON.stringify(serialize(note, poll));
|
||||
await new Promise<void>((res, rej) => {
|
||||
const isFirst = exportedNotesCount === 0;
|
||||
stream.write(isFirst ? content : ',\n' + content, err => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
rej(err);
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
});
|
||||
});
|
||||
const isFirst = exportedNotesCount === 0;
|
||||
await write(isFirst ? content : ',\n' + content);
|
||||
exportedNotesCount++;
|
||||
}
|
||||
|
||||
@ -94,16 +89,7 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
|
||||
job.progress(exportedNotesCount / total);
|
||||
}
|
||||
|
||||
await new Promise<void>((res, rej) => {
|
||||
stream.write(']', err => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
rej(err);
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
});
|
||||
});
|
||||
await write(']');
|
||||
|
||||
stream.end();
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
Reference in New Issue
Block a user