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

Binary file not shown.

View file

@ -96,19 +96,6 @@ CREATE TABLE attributes
hash TEXT default "" not null, isInheritable int DEFAULT 0 NULL);
CREATE INDEX IDX_attributes_name_value
on attributes (name, value);
CREATE TABLE IF NOT EXISTS "notes" (
`noteId` TEXT NOT NULL,
`title` TEXT NOT NULL DEFAULT "note",
`content` TEXT NULL DEFAULT NULL,
`isProtected` INT NOT NULL DEFAULT 0,
`type` TEXT NOT NULL DEFAULT 'text',
`mime` TEXT NOT NULL DEFAULT 'text/html',
`hash` TEXT DEFAULT "" NOT NULL,
`isDeleted` INT NOT NULL DEFAULT 0,
`dateCreated` TEXT NOT NULL,
`dateModified` TEXT NOT NULL,
PRIMARY KEY(`noteId`)
);
CREATE TABLE IF NOT EXISTS "links" (
`linkId` TEXT NOT NULL,
`noteId` TEXT NOT NULL,
@ -130,3 +117,26 @@ CREATE INDEX IDX_attributes_noteId_index
on attributes (noteId);
CREATE INDEX IDX_attributes_value_index
on attributes (value);
CREATE TABLE IF NOT EXISTS "note_contents" (
`noteContentId` TEXT NOT NULL,
`noteId` TEXT NOT NULL,
`isProtected` INT NOT NULL DEFAULT 0,
`content` TEXT NULL DEFAULT NULL,
`hash` TEXT DEFAULT "" NOT NULL,
`dateCreated` TEXT NOT NULL,
`dateModified` TEXT NOT NULL,
PRIMARY KEY(`noteContentId`)
);
CREATE UNIQUE INDEX `IDX_note_contents_noteId` ON `note_contents` (`noteId`);
CREATE TABLE IF NOT EXISTS "notes" (
`noteId` TEXT NOT NULL,
`title` TEXT NOT NULL DEFAULT "note",
`isProtected` INT NOT NULL DEFAULT 0,
`type` TEXT NOT NULL DEFAULT 'text',
`mime` TEXT NOT NULL DEFAULT 'text/html',
`hash` TEXT DEFAULT "" NOT NULL,
`isDeleted` INT NOT NULL DEFAULT 0,
`dateCreated` TEXT NOT NULL,
`dateModified` TEXT NOT NULL,
PRIMARY KEY(`noteId`)
);

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;

View file

@ -13,9 +13,7 @@ const stream = require('stream');
const path = require('path');
const commonmark = require('commonmark');
const mimeTypes = require('mime-types');
let importNoteCount;
let lastSentCountTs = Date.now();
const ImportContext = require('../import_context');
/**
* @param {ImportContext} importContext
@ -24,7 +22,8 @@ let lastSentCountTs = Date.now();
* @return {Promise<*>}
*/
async function importTar(importContext, fileBuffer, importRootNote) {
importNoteCount = 0;
importContext = importContext || new ImportContext("1", false);
// maps from original noteId (in tar file) to newly generated noteId
const noteIdMap = {};
const attributes = [];

View file

@ -0,0 +1,49 @@
"use strict";
const messagingService = require('./messaging');
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
});
}
}
module.exports = ImportContext;

View file

@ -77,16 +77,21 @@ async function createInitialDatabase(username, password) {
await sql.executeScript(schema);
const Note = require("../entities/note");
const NoteContent = require("../entities/note_content");
const Branch = require("../entities/branch");
const rootNote = await new Note({
noteId: 'root',
title: 'root',
content: '',
type: 'text',
mime: 'text/html'
}).save();
const rootNoteContent = await new NoteContent({
noteId: rootNote.noteId,
content: ''
}).save();
await new Branch({
branchId: 'root',
noteId: 'root',
@ -96,7 +101,7 @@ async function createInitialDatabase(username, password) {
}).save();
const tarImportService = require("./import/tar");
await tarImportService.importTar(demoFile, rootNote);
await tarImportService.importTar(null, demoFile, rootNote);
const startNoteId = await sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition");