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

parse u2028 char properly

This commit is contained in:
Dick Choi
2016-09-22 11:01:23 +09:00
parent 9c85719270
commit cc24e6b801
25 changed files with 50 additions and 52 deletions

View File

@@ -4,7 +4,7 @@ const resolveStorageData = require('./resolveStorageData')
const resolveStorageNotes = require('./resolveStorageNotes')
const consts = require('browser/lib/consts')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
/**
* @param {Object}
* name, path, type

View File

@@ -2,7 +2,7 @@ const _ = require('lodash')
const keygen = require('browser/lib/keygen')
const path = require('path')
const resolveStorageData = require('./resolveStorageData')
const CSON = require('season')
const CSON = require('@rokt33r/season')
/**
* @param {String} storageKey

View File

@@ -3,7 +3,7 @@ const resolveStorageData = require('./resolveStorageData')
const _ = require('lodash')
const keygen = require('browser/lib/keygen')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
function validateInput (input) {
if (!_.isArray(input.tags)) input.tags = []

View File

@@ -2,7 +2,7 @@ const _ = require('lodash')
const path = require('path')
const resolveStorageData = require('./resolveStorageData')
const resolveStorageNotes = require('./resolveStorageNotes')
const CSON = require('season')
const CSON = require('@rokt33r/season')
const sander = require('sander')
/**

View File

@@ -4,7 +4,7 @@ const resolveStorageData = require('./resolveStorageData')
const resolveStorageNotes = require('./resolveStorageNotes')
const consts = require('browser/lib/consts')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
/**
* @return {Object} all storages and notes
* ```

View File

@@ -2,7 +2,7 @@ const _ = require('lodash')
const keygen = require('browser/lib/keygen')
const resolveStorageData = require('./resolveStorageData')
const consts = require('browser/lib/consts')
const CSON = require('season')
const CSON = require('@rokt33r/season')
const path = require('path')
const sander = require('sander')

View File

@@ -2,7 +2,7 @@ const path = require('path')
const sander = require('sander')
const keygen = require('browser/lib/keygen')
const _ = require('lodash')
const CSON = require('season')
const CSON = require('@rokt33r/season')
function migrateFromV5Storage (storagePath) {
var boostnoteJSONPath = path.join(storagePath, 'boostnote.json')
@@ -45,10 +45,6 @@ function migrateFromV5Storage (storagePath) {
console.warn('Failed to fetch notes from ', folderDataJSONPath, err)
return []
})
.then(function deleteFolderDir (data) {
sander.rimrafSync(path.join(storagePath, folder.key))
return data
})
})
return Promise.all(fetchNotesFromEachFolder)
@@ -58,22 +54,30 @@ function migrateFromV5Storage (storagePath) {
return sum.concat(notes)
}, [])
})
})
.then(function saveNotes (notes) {
notes.forEach(function renewKey (note) {
var newKey = keygen()
while (notes.some((_note) => _note.key === newKey)) {
newKey = keygen()
}
note.key = newKey
})
.then(function saveNotes (notes) {
notes.forEach(function renewKey (note) {
var newKey = keygen()
while (notes.some((_note) => _note.key === newKey)) {
newKey = keygen()
}
note.key = newKey
})
const noteDirPath = path.join(storagePath, 'notes')
notes
.map(function saveNote (note) {
CSON.writeFileSync(path.join(noteDirPath, note.key) + '.cson', note)
const noteDirPath = path.join(storagePath, 'notes')
notes
.map(function saveNote (note) {
CSON.writeFileSync(path.join(noteDirPath, note.key) + '.cson', note)
})
return true
})
.then(function deleteFolderDir (check) {
if (check) {
boostnoteJSONData.folders.forEach((folder) => {
sander.rimrafSync(path.join(storagePath, folder.key))
})
}
return check
})
return true
})
.catch(function handleError (err) {
console.warn(err)

View File

@@ -1,7 +1,7 @@
const resolveStorageData = require('./resolveStorageData')
const _ = require('lodash')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
const keygen = require('browser/lib/keygen')
const sander = require('sander')

View File

@@ -1,6 +1,6 @@
const _ = require('lodash')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
const migrateFromV6Storage = require('./migrateFromV6Storage')
function resolveStorageData (storageCache) {

View File

@@ -1,6 +1,6 @@
const sander = require('sander')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
function resolveStorageNotes (storage) {
const notesDirPath = path.join(storage.path, 'notes')

View File

@@ -1,7 +1,7 @@
const _ = require('lodash')
const path = require('path')
const resolveStorageData = require('./resolveStorageData')
const CSON = require('season')
const CSON = require('@rokt33r/season')
/**
* @param {String} storageKey

View File

@@ -1,7 +1,7 @@
const resolveStorageData = require('./resolveStorageData')
const _ = require('lodash')
const path = require('path')
const CSON = require('season')
const CSON = require('@rokt33r/season')
function validateInput (input) {
let validatedInput = {}
@@ -14,7 +14,7 @@ function validateInput (input) {
if (input.title != null) {
if (!_.isString(input.title)) validatedInput.title = ''
else validatedInput.title = input.title.replace(/[\u2028]+/g, '')
else validatedInput.title = input.title
}
if (input.isStarred != null) {
@@ -26,13 +26,13 @@ function validateInput (input) {
case 'MARKDOWN_NOTE':
if (input.content != null) {
if (!_.isString(input.content)) validatedInput.content = ''
else validatedInput.content = input.content.replace(/[\u2028]+/g, '')
else validatedInput.content = input.content
}
return validatedInput
case 'SNIPPET_NOTE':
if (input.description != null) {
if (!_.isString(input.description)) validatedInput.description = ''
else validatedInput.description = input.description.replace(/[\u2028]+/g, '')
else validatedInput.description = input.description
}
if (input.snippets != null) {
if (!_.isArray(input.snippets)) {
@@ -51,12 +51,6 @@ function validateInput (input) {
if (!_.isString(snippet.content)) return false
return true
})
.map((snippet) => {
snippet.name = snippet.name.replace(/[\u2028]+/g, '')
snippet.mode = snippet.mode.replace(/[\u2028]+/g, '')
snippet.content = snippet.content.replace(/[\u2028]+/g, '')
return snippet
})
}
return validatedInput
default: