1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

added fetch snippet

refactored some code

fixed snippet content empty on changed from list

fixed snippet name not updating on list when changed
This commit is contained in:
Nguyễn Việt Hưng
2018-04-27 08:22:54 +07:00
parent a7d0a4bdac
commit e88694b049
6 changed files with 95 additions and 65 deletions

View File

@@ -0,0 +1,21 @@
import fs from 'fs'
import crypto from 'crypto'
import consts from 'browser/lib/consts'
function fetchSnippet (id) {
return new Promise((resolve, reject) => {
fs.readFile(consts.SNIPPET_FILE, 'utf8', (err, data) => {
if (err) {
reject(err)
}
const snippets = JSON.parse(data)
if (id) {
const snippet = snippets.find(snippet => { return snippet.id === id })
resolve(snippet)
}
resolve(snippets)
})
})
}
module.exports = fetchSnippet