mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
added document_id for sync identification
This commit is contained in:
parent
c5f80051ae
commit
724f4b43b7
5
app.js
5
app.js
@ -95,6 +95,11 @@ app.use((req, res, next) => {
|
||||
// error handler
|
||||
app.use((err, req, res, next) => {
|
||||
log.error(err.message);
|
||||
|
||||
res.status(err.status || 500);
|
||||
res.send({
|
||||
message: err.message
|
||||
});
|
||||
});
|
||||
|
||||
// triggers sync timer
|
||||
|
1
migrations/0017__document_id.sql
Normal file
1
migrations/0017__document_id.sql
Normal file
@ -0,0 +1 @@
|
||||
INSERT INTO options (opt_name, opt_value) VALUES ('document_id', '');
|
@ -3,7 +3,7 @@ const sql = require('./sql');
|
||||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
|
||||
const APP_DB_VERSION = 16;
|
||||
const APP_DB_VERSION = 17;
|
||||
const MIGRATIONS_DIR = "./migrations";
|
||||
|
||||
async function migrate() {
|
||||
|
@ -34,9 +34,14 @@ async function rollback() {
|
||||
}
|
||||
|
||||
async function getOption(optName) {
|
||||
const row = await getSingleResult("SELECT opt_value FROM options WHERE opt_name = ?", [optName]);
|
||||
try {
|
||||
const row = await getSingleResult("SELECT opt_value FROM options WHERE opt_name = ?", [optName]);
|
||||
|
||||
return row['opt_value'];
|
||||
return row['opt_value'];
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error("Option " + optName + " doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
async function setOption(optName, optValue) {
|
||||
|
@ -112,6 +112,7 @@ async function sync() {
|
||||
|
||||
async function getChangedSince(since) {
|
||||
return {
|
||||
'documentId': await getDocumentId(),
|
||||
'syncTimestamp': utils.nowTimestamp(),
|
||||
'tree': await sql.getResults("select * from notes_tree where date_modified >= ?", [since]),
|
||||
'notes': await sql.getFlattenedResults('note_id', "select note_id from notes where date_modified >= ?", [since]),
|
||||
@ -167,6 +168,22 @@ async function putNote(note) {
|
||||
log.info("Update/sync note " + note.detail.note_id);
|
||||
}
|
||||
|
||||
let documentIdCache = null;
|
||||
|
||||
async function getDocumentId() {
|
||||
if (!documentIdCache) {
|
||||
documentIdCache = await sql.getOption('document_id');
|
||||
|
||||
if (!documentIdCache) {
|
||||
documentIdCache = utils.randomString(16);
|
||||
|
||||
await sql.setOption('document_id', documentIdCache);
|
||||
}
|
||||
}
|
||||
|
||||
return documentIdCache;
|
||||
}
|
||||
|
||||
if (SYNC_SERVER) {
|
||||
log.info("Setting up sync");
|
||||
|
||||
|
@ -6,7 +6,7 @@ function newNoteId() {
|
||||
|
||||
const ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
function randomString(length, chars) {
|
||||
function randomString(length) {
|
||||
let result = '';
|
||||
|
||||
for (let i = length; i > 0; --i) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user