fix initial document setup

This commit is contained in:
zadam
2019-02-20 23:07:57 +01:00
parent 60cbfdcabd
commit 3533160bef
6 changed files with 83 additions and 64 deletions

View File

@@ -5,55 +5,11 @@ const enexImportService = require('../../services/import/enex');
const opmlImportService = require('../../services/import/opml');
const tarImportService = require('../../services/import/tar');
const singleImportService = require('../../services/import/single');
const messagingService = require('../../services/messaging');
const cls = require('../../services/cls');
const path = require('path');
const noteCacheService = require('../../services/note_cache');
const log = require('../../services/log');
class ImportContext {
constructor(importId, safeImport) {
// importId is to distinguish between different import events - it is possible (though not recommended)
// to have multiple imports going at the same time
this.importId = importId;
this.safeImport = safeImport;
// // count is mean to represent count of exported notes where practical, otherwise it's just some measure of progress
this.progressCount = 0;
this.lastSentCountTs = Date.now();
}
async increaseProgressCount() {
this.progressCount++;
if (Date.now() - this.lastSentCountTs >= 500) {
this.lastSentCountTs = Date.now();
await messagingService.sendMessageToAllClients({
importId: this.importId,
type: 'import-progress-count',
progressCount: this.progressCount
});
}
}
async importFinished(noteId) {
await messagingService.sendMessageToAllClients({
importId: this.importId,
type: 'import-finished',
noteId: noteId
});
}
// must remaing non-static
async reportError(message) {
await messagingService.sendMessageToAllClients({
type: 'import-error',
message: message
});
}
}
const ImportContext = require('../../services/import_context');
async function importToBranch(req) {
let {parentNoteId, importId, safeImport} = req.params;