cleaned up images and links which are not used nor supported

This commit is contained in:
azivner 2017-11-29 20:47:01 -05:00
parent d019d0a690
commit 3386cd790e
7 changed files with 13 additions and 59 deletions

View File

@ -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 = /<a[^>]+?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();

View File

@ -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()
});
});

View File

@ -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({});
});

View File

@ -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();

View File

@ -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);
});
}

View File

@ -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);
}

View File

@ -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 <note>");
});