From f0fec4725e8bbbad1ae80c030d1e24b38df7de23 Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Mon, 7 Oct 2019 10:00:52 -0400 Subject: [PATCH] save to server context --- cf.js | 13 +++++++++---- view/vcontextmenu.js | 3 +-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cf.js b/cf.js index 1fd6910..3adfa8f 100644 --- a/cf.js +++ b/cf.js @@ -5,6 +5,7 @@ const app = express() // this include lets us read data out of put requests, const bodyparser = require('body-parser') // our fs tools, +const fs = require('fs') const filesys = require('./filesys.js') // will use these to figure where tf we are const os = require('os') @@ -44,10 +45,14 @@ app.get('/fileList', (req, res) => { // we also handle file-saving this way, app.post('/save/contexts/:context/:file', (req, res) => { // this is probably fine for now, but I kind of want a websocket to do this kind of stuff ? - console.log('put req to context' + req.params.context, 'with name', req.params.file) - console.log('the file as', req.body) - // now we fs.write() this thing, and reply... - res.send({ok: true}) + console.log('put req to context :' + req.params.context + ': with name :' + req.params.file + ':') + console.log('the file as', typeof req.body, req.body) + let serialized = JSON.stringify(req.body, null, 2) + fs.writeFile(`save/contexts/${req.params.context}/${req.params.file}.json`, serialized, (err) => { + if (err) throw err; + console.log('the file saved') + res.send({ok: true}) + }) }) let port = 8080 diff --git a/view/vcontextmenu.js b/view/vcontextmenu.js index 3b37280..eb94594 100644 --- a/view/vcontextmenu.js +++ b/view/vcontextmenu.js @@ -230,8 +230,7 @@ function cfContextMenu(evt, view, dt) { addContextOption('<i class="em em-blue_book"></i> save this context', (ce) => { let ptch = scope.patchset.writeCurrent() setupForSave(ce, (name) => { - let serialized = JSON.stringify(ptch) - jQuery.post(`/save/contexts/${scope.interpreterName}/${name}`, serialized, (res) => { + jQuery.post(`/save/contexts/${scope.interpreterName}/${name}`, ptch, (res) => { console.log('post result', res) }, 'json') }) -- GitLab