diff --git a/docs/backend_api/becca_entities_bnote.js.html b/docs/backend_api/becca_entities_bnote.js.html index b28fbc47c..51a90a0d8 100644 --- a/docs/backend_api/becca_entities_bnote.js.html +++ b/docs/backend_api/becca_entities_bnote.js.html @@ -1202,14 +1202,8 @@ class BNote extends AbstractBeccaEntity { /** @returns {BAttachment} */ getAttachmentByTitle(title) { - return sql.getRows(` - SELECT attachments.* - FROM attachments - WHERE ownerId = ? - AND title = ? - AND isDeleted = 0 - ORDER BY position`, [this.noteId, title]) - .map(row => new BAttachment(row))[0]; + // cannot use SQL to filter by title since it can be encrypted + return this.getAttachments().filter(attachment => attachment.title === title)[0]; } /** diff --git a/docs/backend_api/becca_entities_brevision.js.html b/docs/backend_api/becca_entities_brevision.js.html index 7a44335ab..dc47085b0 100644 --- a/docs/backend_api/becca_entities_brevision.js.html +++ b/docs/backend_api/becca_entities_brevision.js.html @@ -185,14 +185,8 @@ class BRevision extends AbstractBeccaEntity { /** @returns {BAttachment} */ getAttachmentByTitle(title) { - return sql.getRows(` - SELECT attachments.* - FROM attachments - WHERE ownerId = ? - AND title = ? - AND isDeleted = 0 - ORDER BY position`, [this.revisionId, title]) - .map(row => new BAttachment(row))[0]; + // cannot use SQL to filter by title since it can be encrypted + return this.getAttachments().filter(attachment => attachment.title === title)[0]; } beforeSaving() { diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index ba593f4c8..e3e5b5b36 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -19,7 +19,8 @@ const SpacedUpdate = require("./spaced_update"); const specialNotesService = require("./special_notes"); const branchService = require("./branches"); const exportService = require("./export/zip"); -const syncMutex = require("./sync_mutex.js"); +const syncMutex = require("./sync_mutex"); +const backupService = require("./backup"); const optionsService = require("./options"); @@ -663,6 +664,13 @@ function BackendScriptApi(currentNote, apiParams) { */ this.runOutsideOfSync = syncMutex.doExclusively; + /** + * @method + * @param {string} backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file + * @returns {Promise} - resolves once the backup is finished + */ + this.backupNow = backupService.backupNow; + /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * diff --git a/src/services/request.js b/src/services/request.js index 0af02b7ea..5a7158007 100644 --- a/src/services/request.js +++ b/src/services/request.js @@ -160,6 +160,8 @@ function getImage(imageUrl) { }); } +const HTTP = 'http:', HTTPS = 'https:'; + function getProxyAgent(opts) { if (!opts.proxy) { return null; @@ -167,15 +169,15 @@ function getProxyAgent(opts) { const {protocol} = url.parse(opts.url); - if (protocol === 'http:' || protocol === 'https:') { - const protoNoColon = protocol.substr(0, protocol.length - 1); - const AgentClass = require(`${protoNoColon}-proxy-agent`); - - return new AgentClass(opts.proxy); - } - else { + if (![HTTP, HTTPS].includes(protocol)) { return null; } + + const AgentClass = HTTP === protocol + ? require("http-proxy-agent").HttpProxyAgent + : require("https-proxy-agent").HttpsProxyAgent; + + return new AgentClass(opts.proxy); } function getClient(opts) {