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

attempt to recover invalid boostnote.json

This commit is contained in:
Dick Choi
2016-09-20 13:53:58 +09:00
parent cd0bede2f2
commit 240b5daf3e
2 changed files with 46 additions and 3 deletions

View File

@@ -2,6 +2,9 @@
const _ = require('lodash')
const resolveStorageData = require('./resolveStorageData')
const resolveStorageNotes = require('./resolveStorageNotes')
const consts = require('browser/lib/consts')
const path = require('path')
const CSON = require('season')
/**
* @return {Object} all storages and notes
* ```
@@ -33,7 +36,26 @@ function init () {
let fetchNotes = function (storages) {
let findNotesFromEachStorage = storages
.map(resolveStorageNotes)
.map((storage) => {
return resolveStorageNotes(storage)
.then((notes) => {
let unknownCount = 0
notes.forEach((note) => {
if (!storage.folders.some((folder) => note.folder === folder.key)) {
unknownCount++
storage.folders.push({
key: note.folder,
color: consts.FOLDER_COLORS[(unknownCount - 1) % 7],
name: 'Unknown ' + unknownCount
})
}
})
if (unknownCount > 0) {
CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version']))
}
return notes
})
})
return Promise.all(findNotesFromEachStorage)
.then(function concatNoteGroup (noteGroups) {
return noteGroups.reduce(function (sum, group) {