From 3386cd790e5b8351be889a72c6eaf24de41b44a4 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 29 Nov 2017 20:47:01 -0500 Subject: [PATCH] cleaned up images and links which are not used nor supported --- public/javascripts/note_editor.js | 25 +------------------------ routes/api/notes.js | 1 - routes/api/sync.js | 5 ++--- services/backup.js | 1 + services/notes.js | 14 -------------- services/sync.js | 16 ++++++++-------- services/sync_update.js | 10 +--------- 7 files changed, 13 insertions(+), 59 deletions(-) diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index 6053e3ea5..5bc286c02 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -59,31 +59,8 @@ const noteEditor = (function() { } } - function parseHtml(contents, note) { - note.links = []; - note.images = []; - - note.detail.note_text = contents; - - if (!note.detail.is_protected) { - const linkRegexp = /]+?href="[^"]*app#([A-Za-z0-9/]+)"[^>]*?>[^<]+?<\/a>/g; - let match; - - while (match = linkRegexp.exec(contents)) { - console.log("adding link for " + match[1]); - - note.links.push({ - note_id: note.detail.note_id, - target_note_id: match[1] - }); - } - } - } - function updateNoteFromInputs(note) { - const contents = noteDetailEl.summernote('code'); - - parseHtml(contents, note); + note.detail.note_text = noteDetailEl.summernote('code'); const title = noteTitleEl.val(); diff --git a/routes/api/notes.js b/routes/api/notes.js index d08d5a110..44d96371b 100644 --- a/routes/api/notes.js +++ b/routes/api/notes.js @@ -31,7 +31,6 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => { res.send({ detail: detail, - images: await sql.getResults("SELECT * FROM images WHERE note_id = ? order by note_offset", [detail.note_id]), loadTime: utils.nowTimestamp() }); }); diff --git a/routes/api/sync.js b/routes/api/sync.js index c5494ce72..18fc9c640 100644 --- a/routes/api/sync.js +++ b/routes/api/sync.js @@ -30,8 +30,7 @@ router.get('/notes/:noteId', auth.checkApiAuth, async (req, res, next) => { const noteId = req.params.noteId; res.send({ - entity: await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]), - links: await sql.getResults("SELECT * FROM links WHERE note_id = ?", [noteId]) + entity: await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]) }); }); @@ -74,7 +73,7 @@ router.get('/recent_notes/:notePath', auth.checkApiAuth, async (req, res, next) }); router.put('/notes', auth.checkApiAuth, async (req, res, next) => { - await syncUpdate.updateNote(req.body.entity, req.body.links, req.body.sourceId); + await syncUpdate.updateNote(req.body.entity, req.body.sourceId); res.send({}); }); diff --git a/services/backup.js b/services/backup.js index 0ef9fdbaf..513ba932e 100644 --- a/services/backup.js +++ b/services/backup.js @@ -5,6 +5,7 @@ const options = require('./options'); const fs = require('fs-extra'); const dataDir = require('./data_dir'); const log = require('./log'); +const sql = require('./sql'); async function regularBackup() { const now = utils.nowTimestamp(); diff --git a/services/notes.js b/services/notes.js index 664e22769..8b817dd84 100644 --- a/services/notes.js +++ b/services/notes.js @@ -171,20 +171,6 @@ async function updateNote(noteId, newNote, ctx) { now, noteId]); - await sql.remove("images", noteId); - - for (const img of newNote.images) { - img.image_data = atob(img.image_data); - - await sql.insert("images", img); - } - - await sql.remove("links", noteId); - - for (const link in newNote.links) { - //await sql.insert("links", link); - } - await sync_table.addNoteSync(noteId); }); } diff --git a/services/sync.js b/services/sync.js index 9277a4ba6..43686c69f 100644 --- a/services/sync.js +++ b/services/sync.js @@ -136,7 +136,7 @@ async function pullSync(syncContext) { } if (sync.entity_name === 'notes') { - await syncUpdate.updateNote(resp.entity, resp.links, syncContext.sourceId); + await syncUpdate.updateNote(resp.entity, syncContext.sourceId); } else if (sync.entity_name === 'notes_tree') { await syncUpdate.updateNoteTree(resp, syncContext.sourceId); @@ -167,6 +167,12 @@ async function getLastSyncedPush() { return parseInt(await options.getOption('last_synced_push')); } +async function setLastSyncedPush(lastSyncedPush) { + await sql.doInTransaction(async () => { + await options.setOption('last_synced_push', lastSyncedPush); + }); +} + async function pushSync(syncContext) { let lastSyncedPush = await getLastSyncedPush(); @@ -190,9 +196,7 @@ async function pushSync(syncContext) { lastSyncedPush = sync.id; - await sql.doInTransaction(async () => { - await options.setOption('last_synced_push', lastSyncedPush); - }); + await setLastSyncedPush(lastSyncedPush); } } @@ -240,10 +244,6 @@ async function sendEntity(syncContext, entity, entityName) { entity: entity }; - if (entityName === 'notes') { - payload.links = await sql.getResults('SELECT * FROM links WHERE note_id = ?', [entity.note_id]); - } - await syncRequest(syncContext, 'PUT', '/api/sync/' + entityName, payload); } diff --git a/services/sync_update.js b/services/sync_update.js index d10cb69f8..034fe03f1 100644 --- a/services/sync_update.js +++ b/services/sync_update.js @@ -6,21 +6,13 @@ const eventLog = require('./event_log'); const notes = require('./notes'); const sync_table = require('./sync_table'); -async function updateNote(entity, links, sourceId) { +async function updateNote(entity, sourceId) { const origNote = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [entity.note_id]); if (!origNote || origNote.date_modified <= entity.date_modified) { await sql.doInTransaction(async () => { await sql.replace("notes", entity); - await sql.remove("links", entity.note_id); - - for (const link of links) { - delete link['lnk_id']; - - //await sql.insert('link', link); - } - await sync_table.addNoteSync(entity.note_id, sourceId); await eventLog.addNoteEvent(entity.note_id, "Synced note "); });