diff --git a/index.js b/index.js index 4e14918..3ee41ed 100644 --- a/index.js +++ b/index.js @@ -10,14 +10,13 @@ const { Eta } = require("eta"); const { match } = require("path-to-regexp"); const bcrypt = require("bcrypt"); const cheerio = require("cheerio"); -const webPush = require('web-push'); const app = express(); const _expressWs = require("express-ws")(app); const bodyParser = require("body-parser"); -const model = require("./db") +const model = require("./db"); const PORT = 3000; -const db = model.db +const db = model.db; let viewpath = path.join(__dirname, "views"); let eta = new Eta({ views: viewpath, cache: false, autoEscape: true }); @@ -28,16 +27,6 @@ app.use(bodyParser.urlencoded({ extended: true })); app.use(express.static("public")); app.use(fileUpload()); -const publicVapidKey = 'BCW4o4mLShjgONRK21jwTT44ri49JZfrIeJ-W089TVatopdDh8UNujEptonafxM2ttbUPm4wbZF39GvY3dZWAO0'; -const privateVapidKey = 'sXpmx2nRwvVWhGt7uBysZnmFStf9QjaafGd9Ereo4Gw'; - -// Configure web-push with your VAPID details -webPush.setVapidDetails( - 'mailto:signups@sheepmail.net', // a mailto URL or URL - publicVapidKey, - privateVapidKey -); - app.use( session({ store: new SQLiteStore({ client: db, expired: { clear: true } }), @@ -45,7 +34,7 @@ app.use( resave: false, saveUninitialized: true, cookie: { secure: false }, - }) + }), ); function bootstrapContext(db, structureId, routeId, initContext) { @@ -70,19 +59,22 @@ function bootstrapContext(db, structureId, routeId, initContext) { console: { log: function (...content) { const s = content.reduce((acc, curr) => { - console.log(curr) - return acc + (acc ? ' ' : '') + `${util.inspect(curr, { - showHidden: false, - depth: null, // `null` lets you see the full depth of the object - colors: false, // Setting this to true uses ANSI color codes - compact: false - }) - }`; - }, ''); + console.log(curr); + return ( + acc + + (acc ? " " : "") + + `${util.inspect(curr, { + showHidden: false, + depth: null, // `null` lets you see the full depth of the object + colors: false, // Setting this to true uses ANSI color codes + compact: false, + })}` + ); + }, ""); - model.createLog(db, structureId, routeId, s) - } - } + model.createLog(db, structureId, routeId, s); + }, + }, }); for (let appDb of dbs) { let dbInstance = model.getDbInstance(appDb.id); @@ -110,7 +102,7 @@ function bootstrapWebsocketHandler(route) { const context = bootstrapContext(db, route.structure_id, route.id, { app }); let result = vm.runInContext( route.handler + `\n\napp.ws("${routeWithPrefix(route)}", handler)`, - context + context, ); model.updateRoute(db, { ...route, error: null }); return result; @@ -153,7 +145,6 @@ buildRoutes(); // | | _____| || |___ | | | | // |_______||_______||_______||___| |_| - app.post("/register", async (req, res) => { try { const { username, password } = req.body; @@ -178,7 +169,7 @@ app.post("/login", async (req, res) => { return res.send( eta.render("auth/login", { error: "are you sure you entered that right?", - }) + }), ); }); @@ -216,7 +207,7 @@ function bootstrapTemplateWithHTMXetc( blissClone, blissCopy, headInjection, - htmxRequest = false + htmxRequest = false, ) { if ( htmlString.toLowerCase().startsWith("") || @@ -282,8 +273,8 @@ app.get("/workshop", (req, res) => { bootstrapTemplateWithHTMXetc( eta.render("workshop/index", { structures: model.getStructures(db), - }) - ) + }), + ), ); }); @@ -308,8 +299,8 @@ function sidebarStuff(db, structId) { app.get("/workshop/:structure_id", (req, res) => { return res.send( bootstrapTemplateWithHTMXetc( - eta.render("workshop/editor", sidebarStuff(db, req.params.structure_id)) - ) + eta.render("workshop/editor", sidebarStuff(db, req.params.structure_id)), + ), ); }); @@ -324,7 +315,7 @@ app.post("/workshop/:structure_id/clone", (req, res) => { 1, // req.session.userId, routePrefix, - req.body.clone_dbs + req.body.clone_dbs, ); buildRoutes(); } catch (e) { @@ -349,7 +340,7 @@ app.get("/workshop/:structure_id/db/:db_id", (req, res) => { const structdb = model.getDbForStructure( db, req.params.structure_id, - req.params.db_id + req.params.db_id, ); if (!structdb) { return res.send("uh oh"); @@ -359,8 +350,8 @@ app.get("/workshop/:structure_id/db/:db_id", (req, res) => { eta.render("workshop/db_garden", { db: structdb, ...sidebarStuff(db, req.params.structure_id), - }) - ) + }), + ), ); }); @@ -385,14 +376,14 @@ app.post("/workshop/:structure_id/route", (req, res) => { req.body.verb, p[0] == "/" ? p.substring(1) : "/" + p, req.params.structure_id, - dummyHandler + dummyHandler, ); // todo optimize by only adding new, don't just rebuild all buildRoutes(); return smartRedirect( req, res, - `/workshop/${req.params.structure_id}/route/${route}` + `/workshop/${req.params.structure_id}/route/${route}`, ); }); @@ -419,14 +410,16 @@ app.put("/workshop/:structure_id/db/:db_id/library", (req, res) => { }, }); let evaledCode = vm.runInContext(appDb.library, context); - let stdout = capturedOutput.map(v => { - return util.inspect(v, { - showHidden: false, - depth: null, // `null` lets you see the full depth of the object - colors: false, // Setting this to true uses ANSI color codes - compact: false - }) - }).join("\n"); + let stdout = capturedOutput + .map((v) => { + return util.inspect(v, { + showHidden: false, + depth: null, // `null` lets you see the full depth of the object + colors: false, // Setting this to true uses ANSI color codes + compact: false, + }); + }) + .join("\n"); return res.send(`${stdout}\n\n> ${evaledCode}`.trim()); } catch (e) { return res.send(`${e}\n\n${e.stack}`); @@ -443,16 +436,19 @@ app.post("/workshop/:structure_id/db/:db_id/repl", (req, res) => { module: { exports: null }, sql: dbInstance, console: { - log: (...args) => capturedOutput.push( - args.map(v => { - return util.inspect(v, { - showHidden: false, - depth: null, // `null` lets you see the full depth of the object - colors: false, // Setting this to true uses ANSI color codes - compact: false - }) - } - ).join(" ")), + log: (...args) => + capturedOutput.push( + args + .map((v) => { + return util.inspect(v, { + showHidden: false, + depth: null, // `null` lets you see the full depth of the object + colors: false, // Setting this to true uses ANSI color codes + compact: false, + }); + }) + .join(" "), + ), }, }); const libraryScript = new vm.Script(appDb.library); @@ -475,13 +471,13 @@ app.post("/workshop/:structure_id/template", (req, res) => { req.params.structure_id, name, "