1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-11-25 15:46:39 +09:00
This commit is contained in:
syuilo 2021-12-12 06:21:48 +09:00
parent 6d918f195a
commit c599a304c8
2 changed files with 37 additions and 64 deletions

View File

@ -39,16 +39,20 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
const metaStream = fs.createWriteStream(metaPath, { flags: 'a' }); const metaStream = fs.createWriteStream(metaPath, { flags: 'a' });
await new Promise<void>((res, rej) => { const writeMeta = (text: string): Promise<void> => {
metaStream.write('[', err => { return new Promise<void>((res, rej) => {
if (err) { metaStream.write(text, err => {
logger.error(err); if (err) {
rej(err); logger.error(err);
} else { rej(err);
res(); } else {
} res();
}
});
}); });
}); };
await writeMeta('[');
const customEmojis = await Emojis.find({ const customEmojis = await Emojis.find({
where: { where: {
@ -72,34 +76,17 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
logger.error(e); logger.error(e);
} }
await new Promise<void>((res, rej) => { const content = JSON.stringify({
const content = JSON.stringify({ id: exportId,
id: exportId, downloaded: downloaded,
downloaded: downloaded, emoji: emoji,
emoji: emoji,
});
const isFirst = customEmojis.indexOf(emoji) === 0;
metaStream.write(isFirst ? content : ',\n' + content, err => {
if (err) {
logger.error(err);
rej(err);
} else {
res();
}
});
}); });
const isFirst = customEmojis.indexOf(emoji) === 0;
await writeMeta(isFirst ? content : ',\n' + content);
} }
await new Promise<void>((res, rej) => { await writeMeta(']');
metaStream.write(']', err => {
if (err) {
logger.error(err);
rej(err);
} else {
res();
}
});
});
metaStream.end(); metaStream.end();

View File

@ -34,16 +34,20 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
const stream = fs.createWriteStream(path, { flags: 'a' }); const stream = fs.createWriteStream(path, { flags: 'a' });
await new Promise<void>((res, rej) => { const write = (text: string): Promise<void> => {
stream.write('[', err => { return new Promise<void>((res, rej) => {
if (err) { stream.write(text, err => {
logger.error(err); if (err) {
rej(err); logger.error(err);
} else { rej(err);
res(); } else {
} res();
}
});
}); });
}); };
await write('[');
let exportedNotesCount = 0; let exportedNotesCount = 0;
let cursor: Note['id'] | null = null; 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 }); poll = await Polls.findOneOrFail({ noteId: note.id });
} }
const content = JSON.stringify(serialize(note, poll)); const content = JSON.stringify(serialize(note, poll));
await new Promise<void>((res, rej) => { const isFirst = exportedNotesCount === 0;
const isFirst = exportedNotesCount === 0; await write(isFirst ? content : ',\n' + content);
stream.write(isFirst ? content : ',\n' + content, err => {
if (err) {
logger.error(err);
rej(err);
} else {
res();
}
});
});
exportedNotesCount++; exportedNotesCount++;
} }
@ -94,16 +89,7 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
job.progress(exportedNotesCount / total); job.progress(exportedNotesCount / total);
} }
await new Promise<void>((res, rej) => { await write(']');
stream.write(']', err => {
if (err) {
logger.error(err);
rej(err);
} else {
res();
}
});
});
stream.end(); stream.end();
logger.succ(`Exported to: ${path}`); logger.succ(`Exported to: ${path}`);