mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
sync fixes
This commit is contained in:
parent
15abee3ed0
commit
0df7b0bfcf
@ -17,7 +17,7 @@ router.post('/now', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
|
|
||||||
router.get('/changed', auth.checkApiAuth, async (req, res, next) => {
|
router.get('/changed', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const lastSyncId = parseInt(req.query.lastSyncId);
|
const lastSyncId = parseInt(req.query.lastSyncId);
|
||||||
const sourceId = parseInt(req.query.sourceId);
|
const sourceId = req.query.sourceId;
|
||||||
|
|
||||||
const result = await sync.getChanged(lastSyncId, sourceId);
|
const result = await sync.getChanged(lastSyncId, sourceId);
|
||||||
|
|
||||||
|
@ -25,19 +25,19 @@ async function checkAuthWithoutMigration(req, res, next) {
|
|||||||
|
|
||||||
async function checkApiAuth(req, res, next) {
|
async function checkApiAuth(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
res.status(401).send({});
|
res.status(401).send("Not authorized");
|
||||||
}
|
}
|
||||||
else if (await migration.isDbUpToDate()) {
|
else if (await migration.isDbUpToDate()) {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.status(409).send({}); // need better response than that
|
res.status(409).send("Mismatched app versions"); // need better response than that
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkApiAuthWithoutMigration(req, res, next) {
|
async function checkApiAuthWithoutMigration(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn) {
|
||||||
res.status(401).send({});
|
res.status(401).send("Not authorized");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
next();
|
next();
|
||||||
|
@ -19,6 +19,8 @@ async function pullSync(cookieJar, syncLog) {
|
|||||||
let syncRows;
|
let syncRows;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
logSync("Pulling changes: " + SYNC_SERVER + '/api/sync/changed?lastSyncId=' + lastSyncedPull + "&sourceId=" + SOURCE_ID);
|
||||||
|
|
||||||
syncRows = await rp({
|
syncRows = await rp({
|
||||||
uri: SYNC_SERVER + '/api/sync/changed?lastSyncId=' + lastSyncedPull + "&sourceId=" + SOURCE_ID,
|
uri: SYNC_SERVER + '/api/sync/changed?lastSyncId=' + lastSyncedPull + "&sourceId=" + SOURCE_ID,
|
||||||
jar: cookieJar,
|
jar: cookieJar,
|
||||||
@ -45,24 +47,24 @@ async function pullSync(cookieJar, syncLog) {
|
|||||||
throw new Error("Can't pull " + sync.entity_name + " " + sync.entity_id + ", inner exception: " + e.stack);
|
throw new Error("Can't pull " + sync.entity_name + " " + sync.entity_id + ", inner exception: " + e.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
// TODO: ideally this should be in transaction
|
||||||
if (sync.entity_name === 'notes') {
|
|
||||||
await updateNote(resp.entity, resp.links, sync.source_id, syncLog)
|
|
||||||
}
|
|
||||||
else if (sync.entity_name === 'notes_tree') {
|
|
||||||
await updateNoteTree(resp.entity, sync.source_id, syncLog)
|
|
||||||
}
|
|
||||||
else if (sync.entity_name === 'notes_history') {
|
|
||||||
await updateNoteHistory(resp.entity, sync.source_id, syncLog)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logSync("Unrecognized entity type " + sync.entity_name, syncLog);
|
|
||||||
|
|
||||||
throw new Error("Unrecognized entity type " + sync.entity_name);
|
if (sync.entity_name === 'notes') {
|
||||||
}
|
await updateNote(resp.entity, resp.links, sync.source_id, syncLog)
|
||||||
|
}
|
||||||
|
else if (sync.entity_name === 'notes_tree') {
|
||||||
|
await updateNoteTree(resp, sync.source_id, syncLog)
|
||||||
|
}
|
||||||
|
else if (sync.entity_name === 'notes_history') {
|
||||||
|
await updateNoteHistory(resp, sync.source_id, syncLog)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logSync("Unrecognized entity type " + sync.entity_name, syncLog);
|
||||||
|
|
||||||
await sql.setOption('last_synced_pull', sync.id);
|
throw new Error("Unrecognized entity type " + sync.entity_name);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
await sql.setOption('last_synced_pull', sync.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
logSync("Finished pull");
|
logSync("Finished pull");
|
||||||
@ -210,6 +212,8 @@ function logSync(message, syncLog) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getChanged(lastSyncId, sourceId) {
|
async function getChanged(lastSyncId, sourceId) {
|
||||||
|
console.log([lastSyncId, sourceId]);
|
||||||
|
|
||||||
return await sql.getResults("SELECT * FROM sync WHERE id > ? AND source_id != ?", [lastSyncId, sourceId]);
|
return await sql.getResults("SELECT * FROM sync WHERE id > ? AND source_id != ?", [lastSyncId, sourceId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user