mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
small refactorings and fixes
This commit is contained in:
@@ -215,7 +215,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @property {boolean} [params.isProtected=false]
|
||||
* @property {boolean} [params.isExpanded=false]
|
||||
* @property {string} [params.prefix='']
|
||||
* @property {integer} [params.notePosition] - default is last existing notePosition in a parent + 10
|
||||
* @property {int} [params.notePosition] - default is last existing notePosition in a parent + 10
|
||||
* @returns {{note: BNote, branch: BBranch}} object contains newly created entities note and branch
|
||||
*/
|
||||
this.createNewNote = noteService.createNewNote;
|
||||
@@ -412,7 +412,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
|
||||
*
|
||||
* @method
|
||||
* @param {integer} length of the string
|
||||
* @param {int} length of the string
|
||||
* @returns {string} random string
|
||||
*/
|
||||
this.randomString = utils.randomString;
|
||||
|
||||
@@ -59,9 +59,9 @@ function cloneNoteToBranch(noteId, parentBranchId, prefix) {
|
||||
}
|
||||
|
||||
function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
||||
if (isNoteDeleted(noteId)) {
|
||||
if (!(noteId in becca.notes)) {
|
||||
return { branch: null, success: false, message: `Note '${noteId}' is deleted.` };
|
||||
} else if (isNoteDeleted(parentNoteId)) {
|
||||
} else if (!(parentNoteId in becca.notes)) {
|
||||
return { branch: null, success: false, message: `Note '${parentNoteId}' is deleted.` };
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
|
||||
const noteIdToMeta = {};
|
||||
|
||||
/**
|
||||
* @param {Object.<string, integer>} existingFileNames
|
||||
* @param {Object.<string, int>} existingFileNames
|
||||
* @param {string} fileName
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
|
||||
|
||||
return `${index}_${fileName}`;
|
||||
}
|
||||
else {[]
|
||||
else {
|
||||
existingFileNames[lcFileName] = 1;
|
||||
|
||||
return fileName;
|
||||
@@ -71,7 +71,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
|
||||
* @param {string|null} type
|
||||
* @param {string} mime
|
||||
* @param {string} baseFileName
|
||||
* @param {Object.<string, integer>} existingFileNames
|
||||
* @param {Object.<string, int>} existingFileNames
|
||||
* @return {string}
|
||||
*/
|
||||
function getDataFileName(type, mime, baseFileName, existingFileNames) {
|
||||
@@ -119,7 +119,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
|
||||
/**
|
||||
* @param {BBranch} branch
|
||||
* @param {NoteMeta} parentMeta
|
||||
* @param {Object.<string, integer>} existingFileNames
|
||||
* @param {Object.<string, int>} existingFileNames
|
||||
* @returns {NoteMeta|null}
|
||||
*/
|
||||
function createNoteMeta(branch, parentMeta, existingFileNames) {
|
||||
|
||||
@@ -7,7 +7,7 @@ class AttachmentMeta {
|
||||
role;
|
||||
/** @type {string} */
|
||||
mime;
|
||||
/** @type {integer} */
|
||||
/** @type {int} */
|
||||
position;
|
||||
/** @type {string} */
|
||||
dataFileName;
|
||||
|
||||
@@ -7,7 +7,7 @@ class AttributeMeta {
|
||||
value;
|
||||
/** @type {boolean} */
|
||||
isInheritable;
|
||||
/** @type {integer} */
|
||||
/** @type {int} */
|
||||
position;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class NoteMeta {
|
||||
isClone;
|
||||
/** @type {string} */
|
||||
title;
|
||||
/** @type {integer} */
|
||||
/** @type {int} */
|
||||
notePosition;
|
||||
/** @type {string} */
|
||||
prefix;
|
||||
|
||||
@@ -152,7 +152,7 @@ function getAndValidateParent(params) {
|
||||
* - {boolean} isProtected - default is false
|
||||
* - {boolean} isExpanded - default is false
|
||||
* - {string} prefix - default is empty string
|
||||
* - {integer} notePosition - default is last existing notePosition in a parent + 10
|
||||
* - {int} notePosition - default is last existing notePosition in a parent + 10
|
||||
*
|
||||
* @param params
|
||||
* @returns {{note: BNote, branch: BBranch}}
|
||||
|
||||
@@ -26,7 +26,7 @@ function getOption(name) {
|
||||
return val;
|
||||
}
|
||||
|
||||
/** @returns {integer} */
|
||||
/** @returns {int} */
|
||||
function getOptionInt(name, defaultValue = undefined) {
|
||||
const val = getOption(name);
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ const escape = require('escape-html');
|
||||
const sanitize = require("sanitize-filename");
|
||||
const mimeTypes = require('mime-types');
|
||||
const path = require('path');
|
||||
const log = require('./log');
|
||||
|
||||
function newEntityId() {
|
||||
return randomString(12);
|
||||
@@ -33,11 +32,6 @@ function hashedBlobId(content) {
|
||||
return base64Hash.substr(0, 20);
|
||||
}
|
||||
|
||||
function randomBlobId(content) {
|
||||
// underscore prefix to easily differentiate the random as opposed to hashed
|
||||
return '_' + randomString(19);
|
||||
}
|
||||
|
||||
function toBase64(plainText) {
|
||||
return Buffer.from(plainText).toString('base64');
|
||||
}
|
||||
@@ -71,30 +65,6 @@ function sanitizeSqlIdentifier(str) {
|
||||
return str.replace(/[^A-Za-z0-9_]/g, "");
|
||||
}
|
||||
|
||||
function prepareSqlForLike(prefix, str, suffix) {
|
||||
const value = str
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/'/g, "''")
|
||||
.replace(/_/g, "\\_")
|
||||
.replace(/%/g, "\\%");
|
||||
|
||||
return `'${prefix}${value}${suffix}' ESCAPE '\\'`;
|
||||
}
|
||||
|
||||
function stopWatch(what, func, timeLimit = 0) {
|
||||
const start = Date.now();
|
||||
|
||||
const ret = func();
|
||||
|
||||
const tookMs = Date.now() - start;
|
||||
|
||||
if (tookMs >= timeLimit) {
|
||||
log.info(`${what} took ${tookMs}ms`);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return escape(str);
|
||||
}
|
||||
@@ -119,10 +89,6 @@ function stripTags(text) {
|
||||
return text.replace(/<(?:.|\n)*?>/gm, '');
|
||||
}
|
||||
|
||||
function intersection(a, b) {
|
||||
return a.filter(value => b.indexOf(value) !== -1);
|
||||
}
|
||||
|
||||
function union(a, b) {
|
||||
const obj = {};
|
||||
|
||||
@@ -231,7 +197,7 @@ function formatDownloadTitle(fileName, type, mime) {
|
||||
|
||||
if (mime === 'application/octet-stream') {
|
||||
// we didn't find any good guess for this one, it will be better to just return
|
||||
// the current name without fake extension. It's possible that the title still preserves to correct
|
||||
// the current name without a fake extension. It's possible that the title still preserves the correct
|
||||
// extension too
|
||||
|
||||
return fileName;
|
||||
@@ -318,10 +284,6 @@ function normalize(str) {
|
||||
return removeDiacritic(str).toLowerCase();
|
||||
}
|
||||
|
||||
function filterAttributeName(name) {
|
||||
return name.replace(/[^\p{L}\p{N}_:]/ug, "");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
randomSecureToken,
|
||||
randomString,
|
||||
@@ -334,17 +296,13 @@ module.exports = {
|
||||
hash,
|
||||
isEmptyOrWhitespace,
|
||||
sanitizeSqlIdentifier,
|
||||
prepareSqlForLike,
|
||||
stopWatch,
|
||||
escapeHtml,
|
||||
unescapeHtml,
|
||||
toObject,
|
||||
stripTags,
|
||||
intersection,
|
||||
union,
|
||||
escapeRegExp,
|
||||
crash,
|
||||
sanitizeFilenameForHeader,
|
||||
getContentDisposition,
|
||||
isStringNote,
|
||||
quoteRegex,
|
||||
@@ -356,7 +314,5 @@ module.exports = {
|
||||
deferred,
|
||||
removeDiacritic,
|
||||
normalize,
|
||||
filterAttributeName,
|
||||
hashedBlobId,
|
||||
randomBlobId
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user