relation between notes and images

This commit is contained in:
azivner
2018-01-06 21:49:02 -05:00
parent 784cd62df1
commit c0e45a73a8
12 changed files with 117 additions and 7 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../package');
const APP_DB_VERSION = 63;
const APP_DB_VERSION = 65;
module.exports = {
app_version: packageJson.version,
+2
View File
@@ -181,6 +181,8 @@ async function runAllChecks() {
await runSyncRowChecks("notes_history", "note_history_id", errorList);
await runSyncRowChecks("notes_tree", "note_tree_id", errorList);
await runSyncRowChecks("recent_notes", "note_tree_id", errorList);
await runSyncRowChecks("images", "image_id", errorList);
await runSyncRowChecks("notes_image", "note_image_id", errorList);
if (errorList.length === 0) {
// we run this only if basic checks passed since this assumes basic data consistency
+3
View File
@@ -224,6 +224,9 @@ async function pushEntity(sync, syncContext) {
entity.data = entity.data.toString('base64');
}
}
else if (sync.entity_name === 'notes_image') {
entity = await sql.getFirst('SELECT * FROM notes_image WHERE note_image_id = ?', [sync.entity_id]);
}
else {
throw new Error(`Unrecognized entity type ${sync.entity_name} in sync #${sync.id}`);
}
+6
View File
@@ -32,6 +32,10 @@ async function addImageSync(imageId, sourceId) {
await addEntitySync("images", imageId, sourceId);
}
async function addNoteImageSync(imageId, sourceId) {
await addEntitySync("notes_image", imageId, sourceId);
}
async function addEntitySync(entityName, entityId, sourceId) {
await sql.replace("sync", {
entity_name: entityName,
@@ -83,6 +87,7 @@ async function fillAllSyncRows() {
await fillSyncRows("notes_history", "note_history_id");
await fillSyncRows("recent_notes", "note_tree_id");
await fillSyncRows("images", "image_id");
await fillSyncRows("notes_image", "note_image_id");
}
module.exports = {
@@ -93,6 +98,7 @@ module.exports = {
addOptionsSync,
addRecentNoteSync,
addImageSync,
addNoteImageSync,
cleanupSyncRowsForMissingEntities,
fillAllSyncRows
};
+16 -1
View File
@@ -110,6 +110,20 @@ async function updateImage(entity, sourceId) {
}
}
async function updateNoteImage(entity, sourceId) {
const origNoteImage = await sql.getFirst("SELECT * FROM notes_image WHERE note_image_id = ?", [entity.note_image_id]);
if (!origNoteImage || origNoteImage.date_modified <= entity.date_modified) {
await sql.doInTransaction(async () => {
await sql.replace("notes_image", entity);
await sync_table.addNoteImageSync(entity.note_image_id, sourceId);
});
log.info("Update/sync note image " + entity.note_image_id);
}
}
module.exports = {
updateNote,
updateNoteTree,
@@ -117,5 +131,6 @@ module.exports = {
updateNoteReordering,
updateOptions,
updateRecentNotes,
updateImage
updateImage,
updateNoteImage
};
+10
View File
@@ -15,6 +15,14 @@ function newNoteHistoryId() {
return randomString(12);
}
function newImageId() {
return randomString(12);
}
function newNoteImageId() {
return randomString(12);
}
function randomString(length) {
return randtoken.generate(length);
}
@@ -96,6 +104,8 @@ module.exports = {
newNoteId,
newNoteTreeId,
newNoteHistoryId,
newImageId,
newNoteImageId,
toBase64,
fromBase64,
hmac,