mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 23:01:05 +08:00
65 lines
No EOL
1.9 KiB
JavaScript
65 lines
No EOL
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const ws = require('./ws.js');
|
|
|
|
// importId => ImportContext
|
|
const importContexts = {};
|
|
|
|
class ImportContext {
|
|
constructor(importId, options) {
|
|
// 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 = options.safeImport;
|
|
this.shrinkImages = options.shrinkImages;
|
|
this.codeImportedAsCode = options.codeImportedAsCode;
|
|
this.textImportedAsText = options.textImportedAsText;
|
|
|
|
// // 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();
|
|
}
|
|
|
|
/** @return {ImportContext} */
|
|
static getInstance(importId, options) {
|
|
if (!importContexts[importId]) {
|
|
importContexts[importId] = new ImportContext(importId, options);
|
|
}
|
|
|
|
return importContexts[importId];
|
|
}
|
|
|
|
async increaseProgressCount() {
|
|
this.progressCount++;
|
|
|
|
if (Date.now() - this.lastSentCountTs >= 1000) {
|
|
this.lastSentCountTs = Date.now();
|
|
|
|
await ws.sendMessageToAllClients({
|
|
importId: this.importId,
|
|
type: 'import-progress-count',
|
|
progressCount: this.progressCount
|
|
});
|
|
}
|
|
}
|
|
|
|
// must remaing non-static
|
|
async reportError(message) {
|
|
await ws.sendMessageToAllClients({
|
|
type: 'import-error',
|
|
message: message
|
|
});
|
|
}
|
|
|
|
// must remaing non-static
|
|
async importSucceeded(parentNoteId, importedNoteId) {
|
|
await ws.sendMessageToAllClients({
|
|
type: 'import-succeeded',
|
|
parentNoteId: parentNoteId,
|
|
importedNoteId: importedNoteId
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = ImportContext; |