This commit is contained in:
zadam
2023-03-16 12:11:00 +01:00
parent dc97400dbf
commit eee05a4d01
13 changed files with 37 additions and 32 deletions

View File

@@ -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;
}

View File

@@ -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');

View File

@@ -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,

View File

@@ -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 = {

View File

@@ -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');

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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}) => {

View File

@@ -338,6 +338,7 @@ ${markdownContent}`;
taskContext.increaseProgressCount();
for (const attachmentMeta of noteMeta.attachments || []) {
// FIXME
const noteAttachment = note.getNoteAttachmentByName(attachmentMeta.name);
const content = noteAttachment.getContent();

View File

@@ -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
});

View File

@@ -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]);
}