Ind.ie is now Small Technology Foundation.
Commit a5922044 authored by wim-vantomme's avatar wim-vantomme

Added fileUtils library from spike 4

parent 09e3e913
......@@ -15,14 +15,14 @@ app.post('/register', (req, res) => {
const publicKey = JSON.stringify({publickKey: req.body.publicKey})
const privateKey = JSON.stringify({privateKey: req.body.privateKey})
const writeSalt = fileUtils.writeFile('./server/files/salt.json', salt)
const writePublicKey = fileUtils.writeFile('./server/files/publickey.json', publicKey)
const writePrivateKey = fileUtils.writeFile('./server/files/privatekey.json', privateKey)
const writeSalt = fileUtils.writeFile('salt.json', salt, './server/files')
const writePublicKey = fileUtils.writeFile('publickey.json', publicKey, './server/files')
const writePrivateKey = fileUtils.writeFile('privatekey.json', privateKey, './server/files')
Promise.all([writeSalt, writePublicKey, writePrivateKey]).then(() => {
res.status(200).end()
}).catch((er) => {
res.status(500).send('Ooops, something went wrong')
res.status(500).send(er)
})
})
......@@ -46,4 +46,5 @@ app.get('/privatekey', (req, res) => {
})
})
console.log('Server started at port 8080')
app.listen(8080)
const fs = require('fs')
const path = require('path')
// Writes a string to the filesystem.
function writeFile (fileName, value) {
function writeFile (fileName, value, pathName) {
return new Promise((resolve, reject) => {
fs.writeFile(fileName, value, (err) => {
if (err) {
reject(err)
}
makeDir(pathName).then(() => {
fs.writeFile(path.join(pathName, fileName), value, (err) => {
if (err) {
reject(err)
}
resolve()
})
}).catch((err) => reject(err))
})
}
// Creates a dir on the filesystem if it does not exist.
function makeDir (pathName) {
return new Promise((resolve, reject) => {
if (!fs.existsSync(pathName)) {
fs.mkdir(pathName, (err) => {
if (err) {
reject(err)
}
resolve()
})
} else {
resolve()
})
}
})
}
......@@ -23,6 +42,7 @@ function readFile (fileName) {
})
})
}
module.exports = {
writeFile,
readFile
......
......@@ -6,17 +6,6 @@ const indexedDB = require('./indexedDB')
const form = document.getElementById('register')
function loadedKeyPair () {
indexedDB.callOnStore('testkeystore', 'keyStore', (store) => {
const getData = store.get(1)
getData.onsuccess = (event) => {
const keys = getData.result.keys
}
})
}
loadedKeyPair()
form.addEventListener('submit', (e) => {
e.preventDefault()
var saltValue = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment