mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added contentLength to note entity
This commit is contained in:
parent
5aa5ec3af1
commit
7c7beb5502
34
db/migrations/0152__add_contentLength_to_note.sql
Normal file
34
db/migrations/0152__add_contentLength_to_note.sql
Normal file
@ -0,0 +1,34 @@
|
||||
CREATE TABLE IF NOT EXISTS "notes_mig" (
|
||||
`noteId` TEXT NOT NULL,
|
||||
`title` TEXT NOT NULL DEFAULT "note",
|
||||
`contentLength` INT NOT NULL,
|
||||
`isProtected` INT NOT NULL DEFAULT 0,
|
||||
`type` TEXT NOT NULL DEFAULT 'text',
|
||||
`mime` TEXT NOT NULL DEFAULT 'text/html',
|
||||
`hash` TEXT DEFAULT "" NOT NULL,
|
||||
`isDeleted` INT NOT NULL DEFAULT 0,
|
||||
`isErased` INT NOT NULL DEFAULT 0,
|
||||
`dateCreated` TEXT NOT NULL,
|
||||
`dateModified` TEXT NOT NULL,
|
||||
`utcDateCreated` TEXT NOT NULL,
|
||||
`utcDateModified` TEXT NOT NULL,
|
||||
PRIMARY KEY(`noteId`));
|
||||
|
||||
INSERT INTO notes_mig (noteId, title, contentLength, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified)
|
||||
SELECT noteId, title, -1, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes;
|
||||
|
||||
DROP TABLE notes;
|
||||
ALTER TABLE notes_mig RENAME TO notes;
|
||||
|
||||
UPDATE notes SET contentLength = (SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId);
|
||||
|
||||
CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`);
|
||||
CREATE INDEX `IDX_notes_title` ON `notes` (`title`);
|
||||
CREATE INDEX `IDX_notes_type` ON `notes` (`type`);
|
||||
CREATE INDEX `IDX_notes_dateCreated` ON `notes` (`dateCreated`);
|
||||
CREATE INDEX `IDX_notes_dateModified` ON `notes` (`dateModified`);
|
||||
CREATE INDEX `IDX_notes_utcDateModified` ON `notes` (`utcDateModified`);
|
||||
CREATE INDEX `IDX_notes_utcDateCreated` ON `notes` (`utcDateCreated`);
|
||||
|
||||
-- should be OK since sync protocol changes so all instances must upgrade
|
||||
UPDATE attributes SET isDeleted = 1 WHERE name = 'fileSize';
|
@ -6,10 +6,10 @@ const dateUtils = require('../services/date_utils');
|
||||
/**
|
||||
* ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender.
|
||||
*
|
||||
* @param {string} apiTokenId - primary key
|
||||
* @param {string} token
|
||||
* @param {boolean} isDeleted - true if API token is deleted
|
||||
* @param {string} utcDateCreated
|
||||
* @property {string} apiTokenId - primary key
|
||||
* @property {string} token
|
||||
* @property {boolean} isDeleted - true if API token is deleted
|
||||
* @property {string} utcDateCreated
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -8,16 +8,16 @@ const sql = require('../services/sql');
|
||||
/**
|
||||
* Attribute is key value pair owned by a note.
|
||||
*
|
||||
* @param {string} attributeId
|
||||
* @param {string} noteId
|
||||
* @param {string} type
|
||||
* @param {string} name
|
||||
* @param {string} value
|
||||
* @param {int} position
|
||||
* @param {boolean} isInheritable
|
||||
* @param {boolean} isDeleted
|
||||
* @param {string} utcDateCreated
|
||||
* @param {string} utcDateModified
|
||||
* @property {string} attributeId
|
||||
* @property {string} noteId
|
||||
* @property {string} type
|
||||
* @property {string} name
|
||||
* @property {string} value
|
||||
* @property {int} position
|
||||
* @property {boolean} isInheritable
|
||||
* @property {boolean} isDeleted
|
||||
* @property {string} utcDateCreated
|
||||
* @property {string} utcDateModified
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -9,15 +9,15 @@ const sql = require('../services/sql');
|
||||
* Branch represents note's placement in the tree - it's essentially pair of noteId and parentNoteId.
|
||||
* Each note can have multiple (at least one) branches, meaning it can be placed into multiple places in the tree.
|
||||
*
|
||||
* @param {string} branchId - primary key
|
||||
* @param {string} noteId
|
||||
* @param {string} parentNoteId
|
||||
* @param {int} notePosition
|
||||
* @param {string} prefix
|
||||
* @param {boolean} isExpanded
|
||||
* @param {boolean} isDeleted
|
||||
* @param {string} utcDateModified
|
||||
* @param {string} utcDateCreated
|
||||
* @property {string} branchId - primary key
|
||||
* @property {string} noteId
|
||||
* @property {string} parentNoteId
|
||||
* @property {int} notePosition
|
||||
* @property {string} prefix
|
||||
* @property {boolean} isExpanded
|
||||
* @property {boolean} isDeleted
|
||||
* @property {string} utcDateModified
|
||||
* @property {string} utcDateCreated
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ const RELATION_DEFINITION = 'relation-definition';
|
||||
* @property {string} type - one of "text", "code", "file" or "render"
|
||||
* @property {string} mime - MIME type, e.g. "text/html"
|
||||
* @property {string} title - note title
|
||||
* @property {int} contentLength - length of content
|
||||
* @property {boolean} isProtected - true if note is protected
|
||||
* @property {boolean} isDeleted - true if note is deleted
|
||||
* @property {boolean} isErased - true if note's content is erased after it has been deleted
|
||||
@ -115,6 +116,7 @@ class Note extends Entity {
|
||||
async setContent(content) {
|
||||
// force updating note itself so that dateModified is represented correctly even for the content
|
||||
this.forcedChange = true;
|
||||
this.contentLength = content.length;
|
||||
await this.save();
|
||||
|
||||
this.content = content;
|
||||
@ -739,6 +741,10 @@ class Note extends Entity {
|
||||
this.utcDateCreated = dateUtils.utcNowDateTime();
|
||||
}
|
||||
|
||||
if (this.contentLength === undefined) {
|
||||
this.contentLength = -1;
|
||||
}
|
||||
|
||||
super.beforeSaving();
|
||||
|
||||
if (this.isChanged) {
|
||||
|
@ -11,17 +11,18 @@ const syncTableService = require('../services/sync_table');
|
||||
/**
|
||||
* NoteRevision represents snapshot of note's title and content at some point in the past. It's used for seamless note versioning.
|
||||
*
|
||||
* @param {string} noteRevisionId
|
||||
* @param {string} noteId
|
||||
* @param {string} type
|
||||
* @param {string} mime
|
||||
* @param {string} title
|
||||
* @param {string} isProtected
|
||||
* @param {string} dateLastEdited
|
||||
* @param {string} dateCreated
|
||||
* @param {string} utcDateLastEdited
|
||||
* @param {string} utcDateCreated
|
||||
* @param {string} utcDateModified
|
||||
* @property {string} noteRevisionId
|
||||
* @property {string} noteId
|
||||
* @property {string} type
|
||||
* @property {string} mime
|
||||
* @property {string} title
|
||||
* @property {int} contentLength - length of content
|
||||
* @property {string} isProtected
|
||||
* @property {string} dateLastEdited
|
||||
* @property {string} dateCreated
|
||||
* @property {string} utcDateLastEdited
|
||||
* @property {string} utcDateCreated
|
||||
* @property {string} utcDateModified
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -6,11 +6,11 @@ const dateUtils = require('../services/date_utils');
|
||||
/**
|
||||
* Option represents name-value pair, either directly configurable by the user or some system property.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {string} value
|
||||
* @param {boolean} isSynced
|
||||
* @param {string} utcDateModified
|
||||
* @param {string} utcDateCreated
|
||||
* @property {string} name
|
||||
* @property {string} value
|
||||
* @property {boolean} isSynced
|
||||
* @property {string} utcDateModified
|
||||
* @property {string} utcDateCreated
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -6,10 +6,10 @@ const dateUtils = require('../services/date_utils');
|
||||
/**
|
||||
* RecentNote represents recently visited note.
|
||||
*
|
||||
* @param {string} noteId
|
||||
* @param {string} notePath
|
||||
* @param {boolean} isDeleted
|
||||
* @param {string} utcDateModified
|
||||
* @property {string} noteId
|
||||
* @property {string} notePath
|
||||
* @property {boolean} isDeleted
|
||||
* @property {string} utcDateModified
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
|
@ -21,6 +21,8 @@ class NoteShort {
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} */
|
||||
this.title = row.title;
|
||||
/** @param {int} */
|
||||
this.contentLength = row.contentLength;
|
||||
/** @param {boolean} */
|
||||
this.isProtected = row.isProtected;
|
||||
/** @param {string} one of 'text', 'code', 'file' or 'render' */
|
||||
|
@ -39,7 +39,7 @@ class NoteDetailFile {
|
||||
|
||||
this.$fileNoteId.text(this.ctx.note.noteId);
|
||||
this.$fileName.text(attributeMap.originalFileName || "?");
|
||||
this.$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
||||
this.$fileSize.text(this.ctx.note.contentLength + " bytes");
|
||||
this.$fileType.text(this.ctx.note.mime);
|
||||
|
||||
if (this.ctx.note.content) {
|
||||
|
@ -81,7 +81,7 @@ class NoteDetailImage {
|
||||
this.$component.show();
|
||||
|
||||
this.$fileName.text(attributeMap.originalFileName || "?");
|
||||
this.$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
||||
this.$fileSize.text(this.ctx.note.contentLength + " bytes");
|
||||
this.$fileType.text(this.ctx.note.mime);
|
||||
|
||||
const imageHash = this.ctx.note.utcDateModified.replace(" ", "_");
|
||||
|
@ -23,10 +23,7 @@ async function uploadFile(req) {
|
||||
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
|
||||
type: mime.startsWith("image/") ? 'image' : 'file',
|
||||
mime: file.mimetype,
|
||||
attributes: [
|
||||
{ type: "label", name: "originalFileName", value: originalName },
|
||||
{ type: "label", name: "fileSize", value: size }
|
||||
]
|
||||
attributes: [{ type: "label", name: "originalFileName", value: originalName }]
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -4,7 +4,7 @@ const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
const {TRILIUM_DATA_DIR} = require('./data_dir');
|
||||
|
||||
const APP_DB_VERSION = 151;
|
||||
const APP_DB_VERSION = 152;
|
||||
const SYNC_VERSION = 11;
|
||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
||||
|
||||
|
@ -60,7 +60,6 @@ async function updateImage(noteId, uploadBuffer, originalName) {
|
||||
await note.setContent(buffer);
|
||||
|
||||
await note.setLabel('originalFileName', originalName);
|
||||
await note.setLabel('fileSize', buffer.byteLength);
|
||||
|
||||
await noteService.protectNoteRevisions(note);
|
||||
}
|
||||
@ -77,10 +76,7 @@ async function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSw
|
||||
type: 'image',
|
||||
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
|
||||
mime: 'image/' + imageFormat.ext.toLowerCase(),
|
||||
attributes: [
|
||||
{ type: 'label', name: 'originalFileName', value: originalName },
|
||||
{ type: 'label', name: 'fileSize', value: buffer.byteLength }
|
||||
]
|
||||
attributes: [{ type: 'label', name: 'originalFileName', value: originalName }]
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -139,12 +139,6 @@ async function importEnex(taskContext, file, parentNote) {
|
||||
text = text.replace(/\s/g, '');
|
||||
|
||||
resource.content = utils.fromBase64(text);
|
||||
|
||||
resource.attributes.push({
|
||||
type: 'label',
|
||||
name: 'fileSize',
|
||||
value: resource.content.length
|
||||
});
|
||||
}
|
||||
else if (currentTag === 'mime') {
|
||||
resource.mime = text.toLowerCase();
|
||||
|
@ -48,10 +48,7 @@ async function importFile(taskContext, file, parentNote) {
|
||||
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
|
||||
type: 'file',
|
||||
mime: mimeService.getMime(originalName) || file.mimetype,
|
||||
attributes: [
|
||||
{ type: "label", name: "originalFileName", value: originalName },
|
||||
{ type: "label", name: "fileSize", value: size }
|
||||
]
|
||||
attributes: [{ type: "label", name: "originalFileName", value: originalName }]
|
||||
});
|
||||
|
||||
taskContext.increaseProgressCount();
|
||||
|
@ -352,13 +352,6 @@ async function importTar(taskContext, fileBuffer, importRootNote) {
|
||||
name: 'originalFileName',
|
||||
value: path.basename(filePath)
|
||||
});
|
||||
|
||||
attributes.push({
|
||||
noteId,
|
||||
type: 'label',
|
||||
name: 'fileSize',
|
||||
value: content.byteLength
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,9 +465,10 @@ async function eraseDeletedNotes() {
|
||||
// it's better to not use repository for this because it will complain about saving protected notes
|
||||
// out of protected session
|
||||
|
||||
// setting contentLength to zero would serve no benefit and it leaves potentially useful trail
|
||||
await sql.executeMany(`
|
||||
UPDATE notes
|
||||
SET isErased = 1,
|
||||
SET isErased = 1,
|
||||
utcDateModified = '${utcNowDateTime}',
|
||||
dateModified = '${localNowDateTime}'
|
||||
WHERE noteId IN (???)`, noteIdsToErase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user