mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
added checksum to note_attachment
This commit is contained in:
parent
a7b103e07a
commit
3c57f08ef7
@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS "note_attachments"
|
||||
name TEXT not null,
|
||||
mime TEXT not null,
|
||||
isProtected INT not null DEFAULT 0,
|
||||
contentCheckSum TEXT not null,
|
||||
utcDateModified TEXT not null,
|
||||
isDeleted INT not null,
|
||||
`deleteId` TEXT DEFAULT NULL);
|
||||
|
@ -1442,17 +1442,22 @@ class BNote extends AbstractBeccaEntity {
|
||||
* @returns {BNoteAttachment}
|
||||
*/
|
||||
saveNoteAttachment(name, mime, content) {
|
||||
this.getNoteAttachments()
|
||||
let noteAttachment = this.getNoteAttachmentByName(name);
|
||||
|
||||
const noteAttachment = new BNoteAttachment({
|
||||
if (noteAttachment
|
||||
&& noteAttachment.mime === mime
|
||||
&& noteAttachment.contentCheckSum === noteAttachment.calculateCheckSum(content)) {
|
||||
|
||||
return noteAttachment; // no change
|
||||
}
|
||||
|
||||
noteAttachment = new BNoteAttachment({
|
||||
noteId: this.noteId,
|
||||
name,
|
||||
mime,
|
||||
isProtected: this.isProtected
|
||||
});
|
||||
|
||||
noteAttachment.save();
|
||||
|
||||
noteAttachment.setContent(content);
|
||||
|
||||
return noteAttachment;
|
||||
|
@ -33,6 +33,8 @@ class BNoteAttachment extends AbstractBeccaEntity {
|
||||
/** @type {boolean} */
|
||||
this.isProtected = !!row.isProtected;
|
||||
/** @type {string} */
|
||||
this.contentCheckSum = row.contentCheckSum;
|
||||
/** @type {string} */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
}
|
||||
|
||||
@ -97,18 +99,22 @@ class BNoteAttachment extends AbstractBeccaEntity {
|
||||
|
||||
sql.upsert("note_attachment_contents", "noteAttachmentId", pojo);
|
||||
|
||||
const hash = utils.hash(`${this.noteAttachmentId}|${pojo.content.toString()}`);
|
||||
this.contentCheckSum = this.calculateCheckSum(pojo.content);
|
||||
|
||||
entityChangesService.addEntityChange({
|
||||
entityName: 'note_attachment_contents',
|
||||
entityId: this.noteAttachmentId,
|
||||
hash: hash,
|
||||
hash: this.contentCheckSum,
|
||||
isErased: false,
|
||||
utcDateChanged: this.getUtcDateChanged(),
|
||||
isSynced: true
|
||||
});
|
||||
}
|
||||
|
||||
calculateCheckSum(content) {
|
||||
return utils.hash(`${this.noteAttachmentId}|${content.toString()}`);
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.name.match(/^[a-z0-9]+$/i)) {
|
||||
throw new Error(`Name must be alphanumerical, "${this.name}" given.`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user