mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-05-02 10:21:09 -05:00
relation between notes and images
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user