mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01: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 = () => {
|
||||
const sql = require("../../src/services/sql");
|
||||
const utils = require("../../src/services/utils");
|
||||
|
@ -1,16 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS "note_attachments"
|
||||
(
|
||||
noteAttachmentId TEXT not null primary key,
|
||||
noteId TEXT not null,
|
||||
name TEXT not null,
|
||||
parentId TEXT not null,
|
||||
role TEXT not null,
|
||||
mime TEXT not null,
|
||||
title TEXT not null,
|
||||
isProtected INT not null DEFAULT 0,
|
||||
blobId TEXT not null,
|
||||
utcDateModified TEXT not null,
|
||||
isDeleted INT not null,
|
||||
`deleteId` TEXT DEFAULT NULL);
|
||||
deleteId TEXT DEFAULT NULL);
|
||||
|
||||
CREATE INDEX IDX_note_attachments_name
|
||||
on note_attachments (name);
|
||||
CREATE UNIQUE INDEX IDX_note_attachments_noteId_name
|
||||
on note_attachments (noteId, name);
|
||||
CREATE UNIQUE INDEX IDX_note_attachments_parentId_role
|
||||
on note_attachments (parentId, role);
|
||||
|
@ -125,7 +125,7 @@ class Becca {
|
||||
getNoteAttachment(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;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ const dateUtils = require('../../services/date_utils');
|
||||
const entityChangesService = require('../../services/entity_changes');
|
||||
const AbstractBeccaEntity = require("./abstract_becca_entity");
|
||||
const BNoteRevision = require("./bnote_revision");
|
||||
const BNoteAttachment = require("./bnote_attachment.js");
|
||||
const BNoteAttachment = require("./bnote_attachment");
|
||||
const TaskContext = require("../../services/task_context");
|
||||
const dayjs = require("dayjs");
|
||||
const utc = require('dayjs/plugin/utc');
|
||||
|
@ -17,27 +17,31 @@ const AbstractBeccaEntity = require("./abstract_becca_entity");
|
||||
class BNoteAttachment extends AbstractBeccaEntity {
|
||||
static get entityName() { return "note_attachments"; }
|
||||
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) {
|
||||
super();
|
||||
|
||||
if (!row.noteId) {
|
||||
if (!row.parentId?.trim()) {
|
||||
throw new Error("'noteId' must be given to initialize a NoteAttachment entity");
|
||||
}
|
||||
|
||||
if (!row.name) {
|
||||
throw new Error("'name' 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");
|
||||
} else if (!row.mime?.trim()) {
|
||||
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() */
|
||||
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} */
|
||||
this.noteId = row.noteId;
|
||||
/** @type {string} */
|
||||
this.name = row.name;
|
||||
this.role = row.role;
|
||||
/** @type {string} */
|
||||
this.mime = row.mime;
|
||||
/** @type {string} */
|
||||
this.title = row.title;
|
||||
/** @type {boolean} */
|
||||
this.isProtected = !!row.isProtected;
|
||||
/** @type {string} */
|
||||
@ -45,7 +49,7 @@ class BNoteAttachment extends AbstractBeccaEntity {
|
||||
}
|
||||
|
||||
getNote() {
|
||||
return becca.notes[this.noteId];
|
||||
return becca.notes[this.parentId];
|
||||
}
|
||||
|
||||
/** @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.`);
|
||||
}
|
||||
|
||||
this.noteAttachmentId = `${this.noteId}_${this.name}`;
|
||||
this.noteAttachmentId = `${this.noteId}_${this.name}`; // FIXME
|
||||
|
||||
super.beforeSaving();
|
||||
|
||||
@ -137,7 +141,7 @@ class BNoteAttachment extends AbstractBeccaEntity {
|
||||
getPojo() {
|
||||
return {
|
||||
noteAttachmentId: this.noteAttachmentId,
|
||||
noteId: this.noteId,
|
||||
parentId: this.parentId,
|
||||
name: this.name,
|
||||
mime: this.mime,
|
||||
isProtected: !!this.isProtected,
|
||||
|
@ -120,7 +120,7 @@ class BNoteRevision extends AbstractBeccaEntity {
|
||||
|
||||
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) {
|
||||
const pojo = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
const BNote = require('./entities/bnote');
|
||||
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 BAttribute = require('./entities/battribute');
|
||||
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 importService = await import("../services/import.js");
|
||||
const importService = await import('../services/import.js');
|
||||
|
||||
importService.uploadFiles(activeNote.noteId, files, {
|
||||
safeImport: true,
|
||||
|
@ -12,7 +12,7 @@ const syncOptions = require('../../services/sync_options');
|
||||
const dateUtils = require('../../services/date_utils');
|
||||
const utils = require('../../services/utils');
|
||||
const ws = require('../../services/ws');
|
||||
const becca = require("../../becca/becca.js");
|
||||
const becca = require("../../becca/becca");
|
||||
|
||||
async function testSync() {
|
||||
try {
|
||||
|
@ -217,7 +217,7 @@ class ConsistencyChecks {
|
||||
this.findAndFixIssues(`
|
||||
SELECT noteAttachmentId, note_attachments.noteId AS noteId
|
||||
FROM note_attachments
|
||||
LEFT JOIN notes USING (noteId)
|
||||
LEFT JOIN notes ON notes.noteId = note_attachments.parentId
|
||||
WHERE notes.noteId IS NULL
|
||||
AND note_attachments.isDeleted = 0`,
|
||||
({noteAttachmentId, noteId}) => {
|
||||
|
@ -338,6 +338,7 @@ ${markdownContent}`;
|
||||
taskContext.increaseProgressCount();
|
||||
|
||||
for (const attachmentMeta of noteMeta.attachments || []) {
|
||||
// FIXME
|
||||
const noteAttachment = note.getNoteAttachmentByName(attachmentMeta.name);
|
||||
const content = noteAttachment.getContent();
|
||||
|
||||
|
@ -14,7 +14,7 @@ const treeService = require("../tree");
|
||||
const yauzl = require("yauzl");
|
||||
const htmlSanitizer = require('../html_sanitizer');
|
||||
const becca = require("../../becca/becca");
|
||||
const BNoteAttachment = require("../../becca/entities/bnote_attachment.js");
|
||||
const BNoteAttachment = require("../../becca/entities/bnote_attachment");
|
||||
|
||||
/**
|
||||
* @param {TaskContext} taskContext
|
||||
@ -380,8 +380,9 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
|
||||
|
||||
if (attachmentMeta) {
|
||||
const noteAttachment = new BNoteAttachment({
|
||||
noteId,
|
||||
name: attachmentMeta.name,
|
||||
parentId: noteId,
|
||||
title: attachmentMeta.title,
|
||||
role: attachmentMeta.role,
|
||||
mime: attachmentMeta.mime
|
||||
});
|
||||
|
||||
|
@ -135,7 +135,7 @@ function fillInAdditionalProperties(entityChange) {
|
||||
if (!entityChange.entity) {
|
||||
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]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user