mirror of https://github.com/TriliumNext/Notes
getting rid of note complement WIP
parent
9cdcbb3125
commit
5e1f81e53e
@ -0,0 +1,26 @@
|
||||
class BBlob {
|
||||
constructor(row) {
|
||||
/** @type {string} */
|
||||
this.blobId = row.blobId;
|
||||
/** @type {string|Buffer} */
|
||||
this.content = row.content;
|
||||
/** @type {number} */
|
||||
this.contentLength = row.contentLength;
|
||||
/** @type {string} */
|
||||
this.dateModified = row.dateModified;
|
||||
/** @type {string} */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
}
|
||||
|
||||
getPojo() {
|
||||
return {
|
||||
blobId: this.blobId,
|
||||
content: this.content,
|
||||
contentLength: this.contentLength,
|
||||
dateModified: this.dateModified,
|
||||
utcDateModified: this.utcDateModified
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BBlob;
|
||||
@ -0,0 +1,17 @@
|
||||
class FBlob {
|
||||
constructor(row) {
|
||||
/** @type {string} */
|
||||
this.blobId = row.blobId;
|
||||
|
||||
/**
|
||||
* can either contain the whole content (in e.g. string notes), only part (large text notes) or nothing at all (binary notes, images)
|
||||
* @type {string}
|
||||
*/
|
||||
this.content = row.content;
|
||||
|
||||
/** @type {string} */
|
||||
this.dateModified = row.dateModified;
|
||||
/** @type {string} */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
/**
|
||||
* FIXME: probably make it a FBlob
|
||||
* Complements the FNote with the main note content and other extra attributes
|
||||
*/
|
||||
class FNoteComplement {
|
||||
constructor(row) {
|
||||
/** @type {string} */
|
||||
this.noteId = row.noteId;
|
||||
|
||||
/**
|
||||
* can either contain the whole content (in e.g. string notes), only part (large text notes) or nothing at all (binary notes, images)
|
||||
* @type {string}
|
||||
*/
|
||||
this.content = row.content;
|
||||
|
||||
/** @type {int} */
|
||||
this.contentLength = row.contentLength;
|
||||
|
||||
/** @type {string} */
|
||||
this.dateCreated = row.dateCreated;
|
||||
|
||||
/** @type {string} */
|
||||
this.dateModified = row.dateModified;
|
||||
|
||||
/** @type {string} */
|
||||
this.utcDateCreated = row.utcDateCreated;
|
||||
|
||||
/** @type {string} */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
|
||||
// "combined" date modified give larger out of note's and blob's dateModified
|
||||
|
||||
/** @type {string} */
|
||||
this.combinedDateModified = row.combinedDateModified;
|
||||
|
||||
/** @type {string} */
|
||||
this.combinedUtcDateModified = row.combinedUtcDateModified;
|
||||
}
|
||||
}
|
||||
|
||||
export default FNoteComplement;
|
||||
@ -0,0 +1,28 @@
|
||||
const becca = require('../becca/becca');
|
||||
const NotFoundError = require("../errors/not_found_error");
|
||||
|
||||
function getBlobPojo(entityName, entityId, opts = {}) {
|
||||
opts.full = !!opts.full;
|
||||
|
||||
const entity = becca.getEntity(entityName, entityId);
|
||||
|
||||
if (!entity) {
|
||||
throw new NotFoundError(`Entity ${entityName} '${entityId}' was not found.`);
|
||||
}
|
||||
|
||||
const blob = becca.getBlob(entity.blobId);
|
||||
|
||||
const pojo = blob.getPojo();
|
||||
|
||||
if (!entity.hasStringContent()) {
|
||||
pojo.content = null;
|
||||
} else if (!opts.full && pojo.content.length > 10000) {
|
||||
pojo.content = `${pojo.content.substr(0, 10000)}\r\n\r\n... and ${pojo.content.length - 10000} more characters.`;
|
||||
}
|
||||
|
||||
return pojo;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getBlobPojo
|
||||
};
|
||||
Loading…
Reference in New Issue