Browse Source

TMP

asyncify-app
Damien Cassou 4 years ago
parent
commit
998ef0674d
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
1 changed files with 18 additions and 13 deletions
  1. +18
    -13
      app/index.js

+ 18
- 13
app/index.js View File

@ -15,8 +15,8 @@ const input = new Input()
*/
function readStdin (chunk) {
const arr = input.decode(chunk)
Array.isArray(arr) && arr.length && arr.forEach(msg => {
msg && handleMsg(msg)
Array.isArray(arr) && arr.length && arr.forEach(async msg => {
msg && await handleMsg(msg)
})
}
@ -25,18 +25,18 @@ function readStdin (chunk) {
* @param {*} msg - message
* @returns {Promise.<Array>} - results of each handler
*/
function handleMsg (msg) {
async function handleMsg (msg) {
switch (msg.action) {
case 'list':
handleList()
await handleList()
break
case 'read':
handleRead(msg.passEntry)
await handleRead(msg.passEntry)
break
}
}
function handleRead (passEntry) {
async function handleRead (passEntry) {
let entryPath = getEntryPath(getStorePath(), passEntry)
let entryStat = statSync(entryPath)
@ -47,14 +47,19 @@ function handleRead (passEntry) {
return
}
gpg.decryptFile(entryPath, (err, contents) => {
if (err) {
console.error(`There was an error decrypting ${entryPath}: ${err}`)
return
}
const contents = await decryptFile(entryPath)
// contents is a Buffer: https://nodejs.org/api/buffer.html
handleEntryContent(contents.toString())
}
// contents is a Buffer: https://nodejs.org/api/buffer.html
handleEntryContent(contents.toString())
async function decryptFile (entryPath) {
return new Promise((resolve, reject) => {
gpg.decryptFile(entryPath, (err, contents) => {
if (err) {
return reject(err)
}
return resolve(contents)
})
})
}


Loading…
Cancel
Save