Notes/src/services/blob.js

29 lines
763 B
JavaScript
Raw Normal View History

2023-05-05 16:37:39 +02:00
const becca = require('../becca/becca');
const NotFoundError = require("../errors/not_found_error");
function getBlobPojo(entityName, entityId, opts = {}) {
2023-05-05 22:21:51 +02:00
opts.preview = !!opts.preview;
2023-05-05 16:37:39 +02:00
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;
2023-05-05 22:21:51 +02:00
} else if (opts.preview && pojo.content.length > 10000) {
2023-05-05 16:37:39 +02:00
pojo.content = `${pojo.content.substr(0, 10000)}\r\n\r\n... and ${pojo.content.length - 10000} more characters.`;
}
return pojo;
}
module.exports = {
getBlobPojo
2023-05-05 22:21:51 +02:00
};