repository is now stateless

This commit is contained in:
azivner
2018-03-31 09:07:58 -04:00
parent 05676f3459
commit 088fb00ca9
9 changed files with 87 additions and 98 deletions

View File

@@ -4,17 +4,16 @@ const sql = require('../../services/sql');
const html = require('html');
const tar = require('tar-stream');
const sanitize = require("sanitize-filename");
const Repository = require("../../services/repository");
const repository = require("../../services/repository");
async function exportNote(req, res) {
const noteId = req.params.noteId;
const repo = new Repository(req);
const branchId = await sql.getValue('SELECT branchId FROM branches WHERE noteId = ?', [noteId]);
const pack = tar.pack();
const name = await exportNoteInner(branchId, '', pack, repo);
const name = await exportNoteInner(branchId, '', pack);
pack.finalize();
@@ -24,9 +23,9 @@ async function exportNote(req, res) {
pack.pipe(res);
}
async function exportNoteInner(branchId, directory, pack, repo) {
async function exportNoteInner(branchId, directory, pack) {
const branch = await sql.getRow("SELECT * FROM branches WHERE branchId = ?", [branchId]);
const note = await repo.getEntity("SELECT notes.* FROM notes WHERE noteId = ?", [branch.noteId]);
const note = await repository.getEntity("SELECT notes.* FROM notes WHERE noteId = ?", [branch.noteId]);
if (note.isProtected) {
return;
@@ -51,7 +50,7 @@ async function exportNoteInner(branchId, directory, pack, repo) {
if (children.length > 0) {
for (const child of children) {
await exportNoteInner(child.branchId, childFileName + "/", pack, repo);
await exportNoteInner(child.branchId, childFileName + "/", pack);
}
}

View File

@@ -2,7 +2,7 @@
const labels = require('../../services/labels');
const script = require('../../services/script');
const Repository = require('../../services/repository');
const repository = require('../../services/repository');
async function exec(req) {
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
@@ -13,7 +13,6 @@ async function exec(req) {
}
async function run(req) {
const repository = new Repository(req);
const note = await repository.getNote(req.params.noteId);
const ret = await script.executeNote(req, note);
@@ -24,8 +23,7 @@ async function run(req) {
}
async function getStartupBundles(req) {
const repository = new Repository(req);
const notes = await labels.getNotesWithLabel(repository, "run", "frontend_startup");
const notes = await labels.getNotesWithLabel("run", "frontend_startup");
const bundles = [];
@@ -41,11 +39,8 @@ async function getStartupBundles(req) {
}
async function getBundle(req) {
const repository = new Repository(req);
const note = await repository.getNote(req.params.noteId);
const bundle = await script.getScriptBundle(note);
return bundle;
return await script.getScriptBundle(note);
}
module.exports = {