1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

adjust keygen to use uuid only for notes (uuid on storage/folders woud need more refactoring)

This commit is contained in:
mirsch
2018-03-05 00:02:30 +01:00
parent fa2d34dcfc
commit b74ba22c44
4 changed files with 16 additions and 10 deletions

View File

@@ -1,5 +1,11 @@
const crypto = require('crypto')
const _ = require('lodash')
const uuidv4 = require('uuid/v4')
module.exports = function () {
return uuidv4()
module.exports = function (uuid) {
if (typeof uuid === typeof true && uuid) {
return uuidv4()
}
const length = 10
return crypto.randomBytes(length).toString('hex')
}

View File

@@ -52,12 +52,12 @@ function createNote (storageKey, input) {
return storage
})
.then(function saveNote (storage) {
let key = keygen()
let key = keygen(true)
let isUnique = false
while (!isUnique) {
try {
sander.statSync(path.join(storage.path, 'notes', key + '.cson'))
key = keygen()
key = keygen(true)
} catch (err) {
if (err.code === 'ENOENT') {
isUnique = true

View File

@@ -37,12 +37,12 @@ function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
return resolveStorageData(newStorage)
.then(function findNewNoteKey (_newStorage) {
newStorage = _newStorage
newNoteKey = keygen()
newNoteKey = keygen(true)
let isUnique = false
while (!isUnique) {
try {
sander.statSync(path.join(newStorage.path, 'notes', newNoteKey + '.cson'))
newNoteKey = keygen()
newNoteKey = keygen(true)
} catch (err) {
if (err.code === 'ENOENT') {
isUnique = true

View File

@@ -107,9 +107,9 @@ function dummyStorage (storagePath, override = {}) {
var notesData = []
var noteCount = Math.floor((Math.random() * 15)) + 1
for (var i = 0; i < noteCount; i++) {
var key = keygen()
var key = keygen(true)
while (notesData.some((note) => note.key === key)) {
key = keygen()
key = keygen(true)
}
var noteData = dummyNote({
@@ -149,9 +149,9 @@ function dummyLegacyStorage (storagePath, override = {}) {
var folderNotes = []
var noteCount = Math.floor((Math.random() * 5)) + 1
for (var i = 0; i < noteCount; i++) {
var key = keygen()
var key = keygen(true)
while (folderNotes.some((note) => note.key === key)) {
key = keygen()
key = keygen(true)
}
var noteData = dummyNote({