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:
21
browser/main/lib/dataApi/fetchSnippet.js
Normal file
21
browser/main/lib/dataApi/fetchSnippet.js
Normal 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
|
||||
Reference in New Issue
Block a user