mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 19:21:52 +00:00
Merge pull request #2801 from MiloTodt/issue-2799-add_storage
Removal of USB drive will no longer cause irreparable damage.
This commit is contained in:
@@ -4,6 +4,7 @@ const resolveStorageData = require('./resolveStorageData')
|
|||||||
const resolveStorageNotes = require('./resolveStorageNotes')
|
const resolveStorageNotes = require('./resolveStorageNotes')
|
||||||
const consts = require('browser/lib/consts')
|
const consts = require('browser/lib/consts')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
const CSON = require('@rokt33r/season')
|
const CSON = require('@rokt33r/season')
|
||||||
/**
|
/**
|
||||||
* @return {Object} all storages and notes
|
* @return {Object} all storages and notes
|
||||||
@@ -19,11 +20,14 @@ const CSON = require('@rokt33r/season')
|
|||||||
* 2. legacy
|
* 2. legacy
|
||||||
* 3. empty directory
|
* 3. empty directory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
const fetchStorages = function () {
|
const fetchStorages = function () {
|
||||||
let rawStorages
|
let rawStorages
|
||||||
try {
|
try {
|
||||||
rawStorages = JSON.parse(window.localStorage.getItem('storages'))
|
rawStorages = JSON.parse(window.localStorage.getItem('storages'))
|
||||||
|
// Remove storages who's location is inaccesible.
|
||||||
|
rawStorages = rawStorages.filter(storage => fs.existsSync(storage.path))
|
||||||
if (!_.isArray(rawStorages)) throw new Error('Cached data is not valid.')
|
if (!_.isArray(rawStorages)) throw new Error('Cached data is not valid.')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to parse cached data from localStorage', e)
|
console.warn('Failed to parse cached data from localStorage', e)
|
||||||
@@ -36,6 +40,7 @@ function init () {
|
|||||||
|
|
||||||
const fetchNotes = function (storages) {
|
const fetchNotes = function (storages) {
|
||||||
const findNotesFromEachStorage = storages
|
const findNotesFromEachStorage = storages
|
||||||
|
.filter(storage => fs.existsSync(storage.path))
|
||||||
.map((storage) => {
|
.map((storage) => {
|
||||||
return resolveStorageNotes(storage)
|
return resolveStorageNotes(storage)
|
||||||
.then((notes) => {
|
.then((notes) => {
|
||||||
@@ -51,7 +56,11 @@ function init () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (unknownCount > 0) {
|
if (unknownCount > 0) {
|
||||||
|
try {
|
||||||
CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version']))
|
CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version']))
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error writting boostnote.json: ' + e + ' from init.js')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return notes
|
return notes
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user