mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
use uuid in keygen, remove storage.key from note hash
This commit is contained in:
@@ -504,9 +504,20 @@ export default class MarkdownPreview extends React.Component {
|
||||
|
||||
handlelinkClick (e) {
|
||||
const noteHash = e.target.href.split('/').pop()
|
||||
const regexIsNoteLink = /^(.{20})-(.{20})$/
|
||||
// this will match the new uuid v4 hash and the old hash
|
||||
// e.g.
|
||||
// :note:1c211eb7dcb463de6490 and
|
||||
// :note:7dd23275-f2b4-49cb-9e93-3454daf1af9c
|
||||
const regexIsNoteLink = /^:note:([a-zA-Z0-9-]{20,36})$/
|
||||
if (regexIsNoteLink.test(noteHash)) {
|
||||
eventEmitter.emit('list:jump', noteHash)
|
||||
eventEmitter.emit('list:jump', noteHash.replace(':note:', ''))
|
||||
}
|
||||
// this will match the old link format storage.key-note.key
|
||||
// e.g.
|
||||
// 877f99c3268608328037-1c211eb7dcb463de6490
|
||||
const regexIsLegacyNoteLink = /^(.{20})-(.{20})$/
|
||||
if (regexIsLegacyNoteLink.test(noteHash)) {
|
||||
eventEmitter.emit('list:jump', noteHash.split('-')[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ const NoteItem = ({
|
||||
? 'item--active'
|
||||
: 'item'
|
||||
}
|
||||
key={`${note.storage}-${note.key}`}
|
||||
onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)}
|
||||
onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)}
|
||||
key={note.key}
|
||||
onClick={e => handleNoteClick(e, note.key)}
|
||||
onContextMenu={e => handleNoteContextMenu(e, note.key)}
|
||||
onDragStart={e => handleDragStart(e, note)}
|
||||
draggable='true'
|
||||
>
|
||||
|
||||
@@ -28,9 +28,9 @@ const NoteItemSimple = ({
|
||||
? 'item-simple--active'
|
||||
: 'item-simple'
|
||||
}
|
||||
key={`${note.storage}-${note.key}`}
|
||||
onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)}
|
||||
onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)}
|
||||
key={note.key}
|
||||
onClick={e => handleNoteClick(e, note.key)}
|
||||
onContextMenu={e => handleNoteContextMenu(e, note.key)}
|
||||
onDragStart={e => handleDragStart(e, note)}
|
||||
draggable='true'
|
||||
>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
const crypto = require('crypto')
|
||||
const _ = require('lodash')
|
||||
const uuidv4 = require('uuid/v4')
|
||||
|
||||
module.exports = function (length) {
|
||||
if (!_.isFinite(length)) length = 10
|
||||
return crypto.randomBytes(length).toString('hex')
|
||||
module.exports = function () {
|
||||
return uuidv4()
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class MarkdownNoteDetail extends React.Component {
|
||||
hashHistory.replace({
|
||||
pathname: location.pathname,
|
||||
query: {
|
||||
key: newNote.storage + '-' + newNote.key
|
||||
key: newNote.key
|
||||
}
|
||||
})
|
||||
this.setState({
|
||||
@@ -393,7 +393,7 @@ class MarkdownNoteDetail extends React.Component {
|
||||
<InfoPanel
|
||||
storageName={currentOption.storage.name}
|
||||
folderName={currentOption.folder.name}
|
||||
noteLink={`[${note.title}](${location.query.key})`}
|
||||
noteLink={`[${note.title}](:note:${location.query.key})`}
|
||||
updatedAt={formatDate(note.updatedAt)}
|
||||
createdAt={formatDate(note.createdAt)}
|
||||
exportAsMd={this.exportAsMd}
|
||||
|
||||
@@ -147,7 +147,7 @@ class SnippetNoteDetail extends React.Component {
|
||||
hashHistory.replace({
|
||||
pathname: location.pathname,
|
||||
query: {
|
||||
key: newNote.storage + '-' + newNote.key
|
||||
key: newNote.key
|
||||
}
|
||||
})
|
||||
this.setState({
|
||||
@@ -647,7 +647,7 @@ class SnippetNoteDetail extends React.Component {
|
||||
<InfoPanel
|
||||
storageName={currentOption.storage.name}
|
||||
folderName={currentOption.folder.name}
|
||||
noteLink={`[${note.title}](${location.query.key})`}
|
||||
noteLink={`[${note.title}](:note:${location.query.key})`}
|
||||
updatedAt={formatDate(note.updatedAt)}
|
||||
createdAt={formatDate(note.createdAt)}
|
||||
exportAsMd={this.showWarning}
|
||||
|
||||
@@ -56,11 +56,8 @@ class Detail extends React.Component {
|
||||
const { location, data, config } = this.props
|
||||
let note = null
|
||||
if (location.query.key != null) {
|
||||
const splitted = location.query.key.split('-')
|
||||
const storageKey = splitted.shift()
|
||||
const noteKey = splitted.shift()
|
||||
|
||||
note = data.noteMap.get(storageKey + '-' + noteKey)
|
||||
const noteKey = location.query.key
|
||||
note = data.noteMap.get(noteKey)
|
||||
}
|
||||
|
||||
if (note == null) {
|
||||
|
||||
@@ -31,7 +31,7 @@ function sortByUpdatedAt (a, b) {
|
||||
}
|
||||
|
||||
function findNoteByKey (notes, noteKey) {
|
||||
return notes.find((note) => `${note.storage}-${note.key}` === noteKey)
|
||||
return notes.find((note) => note.key === noteKey)
|
||||
}
|
||||
|
||||
function findNotesByKeys (notes, noteKeys) {
|
||||
@@ -39,7 +39,7 @@ function findNotesByKeys (notes, noteKeys) {
|
||||
}
|
||||
|
||||
function getNoteKey (note) {
|
||||
return `${note.storage}-${note.key}`
|
||||
return note.key
|
||||
}
|
||||
|
||||
class NoteList extends React.Component {
|
||||
@@ -114,10 +114,10 @@ class NoteList extends React.Component {
|
||||
componentDidUpdate (prevProps) {
|
||||
const { location } = this.props
|
||||
const { selectedNoteKeys } = this.state
|
||||
const visibleNoteKeys = this.notes.map(note => `${note.storage}-${note.key}`)
|
||||
const visibleNoteKeys = this.notes.map(note => note.key)
|
||||
const note = this.notes[0]
|
||||
const prevKey = prevProps.location.query.key
|
||||
const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && `${note.storage}-${note.key}`
|
||||
const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && note.key
|
||||
|
||||
if (note && location.query.key == null) {
|
||||
const { router } = this.context
|
||||
@@ -613,19 +613,18 @@ class NoteList extends React.Component {
|
||||
content: firstNote.content
|
||||
})
|
||||
.then((note) => {
|
||||
const uniqueKey = note.storage + '-' + note.key
|
||||
dispatch({
|
||||
type: 'UPDATE_NOTE',
|
||||
note: note
|
||||
})
|
||||
|
||||
this.setState({
|
||||
selectedNoteKeys: [uniqueKey]
|
||||
selectedNoteKeys: [note.key]
|
||||
})
|
||||
|
||||
hashHistory.push({
|
||||
pathname: location.pathname,
|
||||
query: {key: uniqueKey}
|
||||
query: {key: note.key}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class NewNoteModal extends React.Component {
|
||||
content: ''
|
||||
})
|
||||
.then((note) => {
|
||||
const noteHash = `${note.storage}-${note.key}`
|
||||
const noteHash = note.key
|
||||
dispatch({
|
||||
type: 'UPDATE_NOTE',
|
||||
note: note
|
||||
@@ -75,7 +75,7 @@ class NewNoteModal extends React.Component {
|
||||
}]
|
||||
})
|
||||
.then((note) => {
|
||||
const noteHash = `${note.storage}-${note.key}`
|
||||
const noteHash = note.key
|
||||
dispatch({
|
||||
type: 'UPDATE_NOTE',
|
||||
note: note
|
||||
|
||||
@@ -27,7 +27,7 @@ function data (state = defaultDataMap(), action) {
|
||||
|
||||
action.notes.some((note) => {
|
||||
if (note === undefined) return true
|
||||
const uniqueKey = note.storage + '-' + note.key
|
||||
const uniqueKey = note.key
|
||||
const folderKey = note.storage + '-' + note.folder
|
||||
state.noteMap.set(uniqueKey, note)
|
||||
|
||||
@@ -66,7 +66,7 @@ function data (state = defaultDataMap(), action) {
|
||||
case 'UPDATE_NOTE':
|
||||
{
|
||||
const note = action.note
|
||||
const uniqueKey = note.storage + '-' + note.key
|
||||
const uniqueKey = note.key
|
||||
const folderKey = note.storage + '-' + note.folder
|
||||
const oldNote = state.noteMap.get(uniqueKey)
|
||||
|
||||
@@ -162,9 +162,9 @@ function data (state = defaultDataMap(), action) {
|
||||
case 'MOVE_NOTE':
|
||||
{
|
||||
const originNote = action.originNote
|
||||
const originKey = originNote.storage + '-' + originNote.key
|
||||
const originKey = originNote.key
|
||||
const note = action.note
|
||||
const uniqueKey = note.storage + '-' + note.key
|
||||
const uniqueKey = note.key
|
||||
const folderKey = note.storage + '-' + note.folder
|
||||
const oldNote = state.noteMap.get(uniqueKey)
|
||||
|
||||
@@ -423,7 +423,7 @@ function data (state = defaultDataMap(), action) {
|
||||
state.folderNoteMap = new Map(state.folderNoteMap)
|
||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||
action.notes.forEach((note) => {
|
||||
const uniqueKey = note.storage + '-' + note.key
|
||||
const uniqueKey = note.key
|
||||
const folderKey = note.storage + '-' + note.folder
|
||||
state.noteMap.set(uniqueKey, note)
|
||||
|
||||
@@ -483,7 +483,7 @@ function data (state = defaultDataMap(), action) {
|
||||
state.tagNoteMap = new Map(state.tagNoteMap)
|
||||
state.starredSet = new Set(state.starredSet)
|
||||
notes.forEach((note) => {
|
||||
const noteKey = storage.key + '-' + note.key
|
||||
const noteKey = note.key
|
||||
state.noteMap.delete(noteKey)
|
||||
state.starredSet.delete(noteKey)
|
||||
note.tags.forEach((tag) => {
|
||||
|
||||
Reference in New Issue
Block a user