mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
renew init method
This commit is contained in:
30
browser/main/lib/dataApi/resolveStorageNotes.js
Normal file
30
browser/main/lib/dataApi/resolveStorageNotes.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const sander = require('sander')
|
||||
const path = require('path')
|
||||
const CSON = require('season')
|
||||
|
||||
function resolveStorageNotes (storage) {
|
||||
const notesDirPath = path.join(storage.path, 'notes')
|
||||
let notePathList
|
||||
try {
|
||||
notePathList = sander.readdirSync(notesDirPath)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
console.log(notesDirPath, ' doesn\'t exist.')
|
||||
sander.mkdirSync(notesDirPath)
|
||||
} else {
|
||||
console.warn('Failed to find note dir', notesDirPath, err)
|
||||
}
|
||||
notePathList = []
|
||||
}
|
||||
let notes = notePathList
|
||||
.map(function parseCSONFile (notePath) {
|
||||
let data = CSON.readFileSync(path.join(notesDirPath, notePath))
|
||||
data.key = path.basename(notePath, '.cson')
|
||||
data.storage = storage.key
|
||||
return data
|
||||
})
|
||||
|
||||
return Promise.resolve(notes)
|
||||
}
|
||||
|
||||
module.exports = resolveStorageNotes
|
||||
Reference in New Issue
Block a user