mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
added delete snippet, update snippet, create snippet and save on snippet change
This commit is contained in:
23
browser/main/lib/dataApi/createSnippet.js
Normal file
23
browser/main/lib/dataApi/createSnippet.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { remote } = require('electron')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import crypto from 'crypto'
|
||||
import consts from 'browser/lib/consts'
|
||||
|
||||
function createSnippet(snippets) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const newSnippet = {
|
||||
id: crypto.randomBytes(16).toString('hex'),
|
||||
name: 'Unnamed snippet',
|
||||
prefix: [],
|
||||
content: ''
|
||||
}
|
||||
snippets.push(newSnippet)
|
||||
fs.writeFile(consts.SNIPPET_FILE, JSON.stringify(snippets, null, 4), (err) => {
|
||||
if (err) reject(err)
|
||||
resolve(snippets)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = createSnippet
|
||||
Reference in New Issue
Block a user