mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	blob WIP
This commit is contained in:
		
							parent
							
								
									dc97400dbf
								
							
						
					
					
						commit
						eee05a4d01
					
				| @ -1,4 +1,4 @@ | |||||||
| const sql = require("../../src/services/sql.js"); | const sql = require("../../src/services/sql"); | ||||||
| module.exports = () => { | module.exports = () => { | ||||||
|     const sql = require("../../src/services/sql"); |     const sql = require("../../src/services/sql"); | ||||||
|     const utils = require("../../src/services/utils"); |     const utils = require("../../src/services/utils"); | ||||||
|  | |||||||
| @ -1,16 +1,15 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_attachments" | CREATE TABLE IF NOT EXISTS "note_attachments" | ||||||
| ( | ( | ||||||
|     noteAttachmentId      TEXT not null primary key, |     noteAttachmentId      TEXT not null primary key, | ||||||
|     noteId       TEXT not null, |     parentId       TEXT not null, | ||||||
|     name         TEXT not null, |     role         TEXT not null, | ||||||
|     mime         TEXT not null, |     mime         TEXT not null, | ||||||
|  |     title         TEXT not null, | ||||||
|     isProtected    INT  not null DEFAULT 0, |     isProtected    INT  not null DEFAULT 0, | ||||||
|     blobId    TEXT not null, |     blobId    TEXT not null, | ||||||
|     utcDateModified TEXT not null, |     utcDateModified TEXT not null, | ||||||
|     isDeleted    INT  not null, |     isDeleted    INT  not null, | ||||||
|     `deleteId`    TEXT DEFAULT NULL); |     deleteId    TEXT DEFAULT NULL); | ||||||
| 
 | 
 | ||||||
| CREATE INDEX IDX_note_attachments_name | CREATE UNIQUE INDEX IDX_note_attachments_parentId_role | ||||||
|     on note_attachments (name); |     on note_attachments (parentId, role); | ||||||
| CREATE UNIQUE INDEX IDX_note_attachments_noteId_name |  | ||||||
|     on note_attachments (noteId, name); |  | ||||||
|  | |||||||
| @ -125,7 +125,7 @@ class Becca { | |||||||
|     getNoteAttachment(noteAttachmentId) { |     getNoteAttachment(noteAttachmentId) { | ||||||
|         const row = sql.getRow("SELECT * FROM note_attachments WHERE noteAttachmentId = ?", [noteAttachmentId]); |         const row = sql.getRow("SELECT * FROM note_attachments WHERE noteAttachmentId = ?", [noteAttachmentId]); | ||||||
| 
 | 
 | ||||||
|         const BNoteAttachment = require("./entities/bnote_attachment.js"); // avoiding circular dependency problems
 |         const BNoteAttachment = require("./entities/bnote_attachment"); // avoiding circular dependency problems
 | ||||||
|         return row ? new BNoteAttachment(row) : null; |         return row ? new BNoteAttachment(row) : null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ const dateUtils = require('../../services/date_utils'); | |||||||
| const entityChangesService = require('../../services/entity_changes'); | const entityChangesService = require('../../services/entity_changes'); | ||||||
| const AbstractBeccaEntity = require("./abstract_becca_entity"); | const AbstractBeccaEntity = require("./abstract_becca_entity"); | ||||||
| const BNoteRevision = require("./bnote_revision"); | const BNoteRevision = require("./bnote_revision"); | ||||||
| const BNoteAttachment = require("./bnote_attachment.js"); | const BNoteAttachment = require("./bnote_attachment"); | ||||||
| const TaskContext = require("../../services/task_context"); | const TaskContext = require("../../services/task_context"); | ||||||
| const dayjs = require("dayjs"); | const dayjs = require("dayjs"); | ||||||
| const utc = require('dayjs/plugin/utc'); | const utc = require('dayjs/plugin/utc'); | ||||||
|  | |||||||
| @ -17,27 +17,31 @@ const AbstractBeccaEntity = require("./abstract_becca_entity"); | |||||||
| class BNoteAttachment extends AbstractBeccaEntity { | class BNoteAttachment extends AbstractBeccaEntity { | ||||||
|     static get entityName() { return "note_attachments"; } |     static get entityName() { return "note_attachments"; } | ||||||
|     static get primaryKeyName() { return "noteAttachmentId"; } |     static get primaryKeyName() { return "noteAttachmentId"; } | ||||||
|     static get hashedProperties() { return ["noteAttachmentId", "noteId", "name", "content", "utcDateModified"]; } |     static get hashedProperties() { return ["noteAttachmentId", "parentId", "role", "mime", "title", "utcDateModified"]; } | ||||||
| 
 | 
 | ||||||
|     constructor(row) { |     constructor(row) { | ||||||
|         super(); |         super(); | ||||||
| 
 | 
 | ||||||
|         if (!row.noteId) { |         if (!row.parentId?.trim()) { | ||||||
|             throw new Error("'noteId' must be given to initialize a NoteAttachment entity"); |             throw new Error("'noteId' must be given to initialize a NoteAttachment entity"); | ||||||
|         } |         } else if (!row.role?.trim()) { | ||||||
| 
 |             throw new Error("'role' must be given to initialize a NoteAttachment entity"); | ||||||
|         if (!row.name) { |         } else if (!row.mime?.trim()) { | ||||||
|             throw new Error("'name' must be given to initialize a NoteAttachment entity"); |             throw new Error("'mime' must be given to initialize a NoteAttachment entity"); | ||||||
|  |         } else if (!row.title?.trim()) { | ||||||
|  |             throw new Error("'title' must be given to initialize a NoteAttachment entity"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** @type {string} needs to be set at the initialization time since it's used in the .setContent() */ |         /** @type {string} needs to be set at the initialization time since it's used in the .setContent() */ | ||||||
|         this.noteAttachmentId = row.noteAttachmentId || `${this.noteId}_${this.name}`; |         this.noteAttachmentId = row.noteAttachmentId || `${this.noteId}_${this.name}`; // FIXME
 | ||||||
|  |         /** @type {string} either noteId or noteRevisionId to which this attachment belongs */ | ||||||
|  |         this.parentId = row.parentId; | ||||||
|         /** @type {string} */ |         /** @type {string} */ | ||||||
|         this.noteId = row.noteId; |         this.role = row.role; | ||||||
|         /** @type {string} */ |  | ||||||
|         this.name = row.name; |  | ||||||
|         /** @type {string} */ |         /** @type {string} */ | ||||||
|         this.mime = row.mime; |         this.mime = row.mime; | ||||||
|  |         /** @type {string} */ | ||||||
|  |         this.title = row.title; | ||||||
|         /** @type {boolean} */ |         /** @type {boolean} */ | ||||||
|         this.isProtected = !!row.isProtected; |         this.isProtected = !!row.isProtected; | ||||||
|         /** @type {string} */ |         /** @type {string} */ | ||||||
| @ -45,7 +49,7 @@ class BNoteAttachment extends AbstractBeccaEntity { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     getNote() { |     getNote() { | ||||||
|         return becca.notes[this.noteId]; |         return becca.notes[this.parentId]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** @returns {boolean} true if the note has string content (not binary) */ |     /** @returns {boolean} true if the note has string content (not binary) */ | ||||||
| @ -127,7 +131,7 @@ class BNoteAttachment extends AbstractBeccaEntity { | |||||||
|             throw new Error(`Name must be alphanumerical, "${this.name}" given.`); |             throw new Error(`Name must be alphanumerical, "${this.name}" given.`); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.noteAttachmentId = `${this.noteId}_${this.name}`; |         this.noteAttachmentId = `${this.noteId}_${this.name}`; // FIXME
 | ||||||
| 
 | 
 | ||||||
|         super.beforeSaving(); |         super.beforeSaving(); | ||||||
| 
 | 
 | ||||||
| @ -137,7 +141,7 @@ class BNoteAttachment extends AbstractBeccaEntity { | |||||||
|     getPojo() { |     getPojo() { | ||||||
|         return { |         return { | ||||||
|             noteAttachmentId: this.noteAttachmentId, |             noteAttachmentId: this.noteAttachmentId, | ||||||
|             noteId: this.noteId, |             parentId: this.parentId, | ||||||
|             name: this.name, |             name: this.name, | ||||||
|             mime: this.mime, |             mime: this.mime, | ||||||
|             isProtected: !!this.isProtected, |             isProtected: !!this.isProtected, | ||||||
|  | |||||||
| @ -120,7 +120,7 @@ class BNoteRevision extends AbstractBeccaEntity { | |||||||
| 
 | 
 | ||||||
|         this.blobId = utils.hashedBlobId(content); |         this.blobId = utils.hashedBlobId(content); | ||||||
| 
 | 
 | ||||||
|         const blobAlreadyExists = !sql.getValue('SELECT 1 FROM blobs WHERE blobId = ?', [this.blobId]); |         const blobAlreadyExists = !!sql.getValue('SELECT 1 FROM blobs WHERE blobId = ?', [this.blobId]); | ||||||
| 
 | 
 | ||||||
|         if (!blobAlreadyExists) { |         if (!blobAlreadyExists) { | ||||||
|             const pojo = { |             const pojo = { | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| const BNote = require('./entities/bnote'); | const BNote = require('./entities/bnote'); | ||||||
| const BNoteRevision = require('./entities/bnote_revision'); | const BNoteRevision = require('./entities/bnote_revision'); | ||||||
| const BNoteAttachment = require("./entities/bnote_attachment.js"); | const BNoteAttachment = require("./entities/bnote_attachment"); | ||||||
| const BBranch = require('./entities/bbranch'); | const BBranch = require('./entities/bbranch'); | ||||||
| const BAttribute = require('./entities/battribute'); | const BAttribute = require('./entities/battribute'); | ||||||
| const BRecentNote = require('./entities/brecent_note'); | const BRecentNote = require('./entities/brecent_note'); | ||||||
|  | |||||||
| @ -112,7 +112,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { | |||||||
| 
 | 
 | ||||||
|             const files = [...e.originalEvent.dataTransfer.files]; // chrome has issue that dataTransfer.files empties after async operation
 |             const files = [...e.originalEvent.dataTransfer.files]; // chrome has issue that dataTransfer.files empties after async operation
 | ||||||
| 
 | 
 | ||||||
|             const importService = await import("../services/import.js"); |             const importService = await import('../services/import.js'); | ||||||
| 
 | 
 | ||||||
|             importService.uploadFiles(activeNote.noteId, files, { |             importService.uploadFiles(activeNote.noteId, files, { | ||||||
|                 safeImport: true, |                 safeImport: true, | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ const syncOptions = require('../../services/sync_options'); | |||||||
| const dateUtils = require('../../services/date_utils'); | const dateUtils = require('../../services/date_utils'); | ||||||
| const utils = require('../../services/utils'); | const utils = require('../../services/utils'); | ||||||
| const ws = require('../../services/ws'); | const ws = require('../../services/ws'); | ||||||
| const becca = require("../../becca/becca.js"); | const becca = require("../../becca/becca"); | ||||||
| 
 | 
 | ||||||
| async function testSync() { | async function testSync() { | ||||||
|     try { |     try { | ||||||
|  | |||||||
| @ -217,7 +217,7 @@ class ConsistencyChecks { | |||||||
|         this.findAndFixIssues(` |         this.findAndFixIssues(` | ||||||
|                     SELECT noteAttachmentId, note_attachments.noteId AS noteId |                     SELECT noteAttachmentId, note_attachments.noteId AS noteId | ||||||
|                     FROM note_attachments |                     FROM note_attachments | ||||||
|                       LEFT JOIN notes USING (noteId) |                       LEFT JOIN notes ON notes.noteId = note_attachments.parentId | ||||||
|                     WHERE notes.noteId IS NULL |                     WHERE notes.noteId IS NULL | ||||||
|                       AND note_attachments.isDeleted = 0`,
 |                       AND note_attachments.isDeleted = 0`,
 | ||||||
|             ({noteAttachmentId, noteId}) => { |             ({noteAttachmentId, noteId}) => { | ||||||
|  | |||||||
| @ -338,6 +338,7 @@ ${markdownContent}`; | |||||||
|         taskContext.increaseProgressCount(); |         taskContext.increaseProgressCount(); | ||||||
| 
 | 
 | ||||||
|         for (const attachmentMeta of noteMeta.attachments || []) { |         for (const attachmentMeta of noteMeta.attachments || []) { | ||||||
|  |             // FIXME
 | ||||||
|             const noteAttachment = note.getNoteAttachmentByName(attachmentMeta.name); |             const noteAttachment = note.getNoteAttachmentByName(attachmentMeta.name); | ||||||
|             const content = noteAttachment.getContent(); |             const content = noteAttachment.getContent(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ const treeService = require("../tree"); | |||||||
| const yauzl = require("yauzl"); | const yauzl = require("yauzl"); | ||||||
| const htmlSanitizer = require('../html_sanitizer'); | const htmlSanitizer = require('../html_sanitizer'); | ||||||
| const becca = require("../../becca/becca"); | const becca = require("../../becca/becca"); | ||||||
| const BNoteAttachment = require("../../becca/entities/bnote_attachment.js"); | const BNoteAttachment = require("../../becca/entities/bnote_attachment"); | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @param {TaskContext} taskContext |  * @param {TaskContext} taskContext | ||||||
| @ -380,8 +380,9 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
| 
 | 
 | ||||||
|         if (attachmentMeta) { |         if (attachmentMeta) { | ||||||
|             const noteAttachment = new BNoteAttachment({ |             const noteAttachment = new BNoteAttachment({ | ||||||
|                 noteId, |                 parentId: noteId, | ||||||
|                 name: attachmentMeta.name, |                 title: attachmentMeta.title, | ||||||
|  |                 role: attachmentMeta.role, | ||||||
|                 mime: attachmentMeta.mime |                 mime: attachmentMeta.mime | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -135,7 +135,7 @@ function fillInAdditionalProperties(entityChange) { | |||||||
|         if (!entityChange.entity) { |         if (!entityChange.entity) { | ||||||
|             entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]); |             entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]); | ||||||
|         } |         } | ||||||
|     } else if (entityChange.entityName === 'blob') { |     } else if (entityChange.entityName === 'blobs') { | ||||||
|         entityChange.noteIds = sql.getColumn("SELECT noteId FROM notes WHERE blobId = ? AND isDeleted = 0", [entityChange.entityId]); |         entityChange.noteIds = sql.getColumn("SELECT noteId FROM notes WHERE blobId = ? AND isDeleted = 0", [entityChange.entityId]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam