Indexation of files to nodes
This commit is contained in:
parent
70b5285e16
commit
f3ca7b9a44
3 changed files with 115 additions and 43 deletions
|
|
@ -453,6 +453,8 @@ export class Node {
|
|||
}//}}}
|
||||
|
||||
reset() {// {{{
|
||||
// this._content is the runtime content in the editor.
|
||||
// this.data.Content is the original data.
|
||||
this._content = this.data.Content
|
||||
this._modified = false
|
||||
}// }}}
|
||||
|
|
@ -522,10 +524,7 @@ export class Node {
|
|||
return this.data.Special
|
||||
}// }}}
|
||||
content() {//{{{
|
||||
/* TODO - implement crypto
|
||||
if (this.CryptoKeyID != 0 && !this._decrypted)
|
||||
this.#decrypt()
|
||||
*/
|
||||
// TODO - implement crypto
|
||||
return this._content
|
||||
}//}}}
|
||||
setContent(new_content) {//{{{
|
||||
|
|
@ -542,48 +541,67 @@ export class Node {
|
|||
_mbus.dispatch('NODE_MODIFIED', { node: this })
|
||||
}// }}}
|
||||
async save() {//{{{
|
||||
// Just safeguarding not using the root node,
|
||||
// which sort of exist but isn't supposed to communicate to server.
|
||||
if (this.UUID == ROOT_NODE)
|
||||
return
|
||||
try {
|
||||
const dblink = /db:\/\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi
|
||||
|
||||
this.data.Content = this._content
|
||||
this.data.Updated = new Date().toISOString()
|
||||
this.data.HistoryUUID = uuidv7() // every time the node is saved a new history UUID identifies the changed node.
|
||||
this._modified = false
|
||||
// Just safeguarding not using the root node,
|
||||
// which sort of exist but isn't supposed to communicate to server.
|
||||
if (this.UUID == ROOT_NODE)
|
||||
return
|
||||
|
||||
_mbus.dispatch('NODE_UNMODIFIED')
|
||||
|
||||
// When stored into database and ancestry was changed,
|
||||
// the ancestry path could be interesting.
|
||||
/*
|
||||
const ancestors = await nodeStore.getNodeAncestry(this)
|
||||
this.data.Ancestors = ancestors.map(a => a.get('Name')).reverse()
|
||||
*/
|
||||
/* The node history is a local store for node history.
|
||||
* This could be provisioned from the server or cleared if
|
||||
* deemed unnecessary.
|
||||
*
|
||||
* The send queue is what will be sent back to the server
|
||||
* to have a recorded history of the notes.
|
||||
*
|
||||
* A setting to be implemented in the future could be to
|
||||
* not save the history locally at all. */
|
||||
// File links from the original, unmodified content are found to compare to links from the new content.
|
||||
// All files (images) needs to be indexed to nodes in order to track orphaned files.
|
||||
const before = new Set([...this.data.Content.matchAll(dblink)].map(m => m[1]))
|
||||
const after = new Set([...this._content.matchAll(dblink)].map(m => m[1]))
|
||||
const removed = before.difference(after)
|
||||
const added = after.difference(before)
|
||||
|
||||
// Current node is added to history. It will be duplicated with the "nodes" store
|
||||
// for simplicity, to hopefully avoid bugs.
|
||||
const history = nodeStore.nodesHistory.add(this)
|
||||
await nodeStore.filesNodelink.removeFileUUIDs(this.UUID, removed)
|
||||
await nodeStore.filesNodelink.addFileUUIDs(this.UUID, added)
|
||||
|
||||
// Updated node is added to the send queue to be stored on server.
|
||||
// Authoritative content and metadata is set to prepare it for IndexedDB update.
|
||||
this.data.Content = this._content
|
||||
this.data.Updated = new Date().toISOString()
|
||||
this.data.HistoryUUID = uuidv7() // every time the node is saved a new history UUID identifies the changed node.
|
||||
|
||||
const sendQueue = nodeStore.sendQueue.add(this)
|
||||
_mbus.dispatch('NODE_UNMODIFIED')
|
||||
this._modified = false
|
||||
|
||||
// Updated node is saved to the primary node store.
|
||||
const nodeStoreAdding = nodeStore.add([this])
|
||||
// When stored into database and ancestry was changed,
|
||||
// the ancestry path could be interesting.
|
||||
/*
|
||||
const ancestors = await nodeStore.getNodeAncestry(this)
|
||||
this.data.Ancestors = ancestors.map(a => a.get('Name')).reverse()
|
||||
*/
|
||||
|
||||
console.log('waiting')
|
||||
await Promise.all([history, sendQueue, nodeStoreAdding])
|
||||
console.log('waiting done')
|
||||
/* The node history is a local store for node history.
|
||||
* This could be provisioned from the server or cleared if
|
||||
* deemed unnecessary.
|
||||
*
|
||||
* The send queue is what will be sent back to the server
|
||||
* to have a recorded history of the notes.
|
||||
*
|
||||
* A setting to be implemented in the future could be to
|
||||
* not save the history locally at all. */
|
||||
|
||||
// Current node is added to history. It will be duplicated with the "nodes" store
|
||||
// for simplicity, to hopefully avoid bugs.
|
||||
const history = nodeStore.nodesHistory.add(this)
|
||||
|
||||
// Updated node is added to the send queue to be stored on server.
|
||||
|
||||
const sendQueue = nodeStore.sendQueue.add(this)
|
||||
|
||||
// Updated node is saved to the primary node store.
|
||||
const nodeStoreAdding = nodeStore.add([this])
|
||||
|
||||
await Promise.all([history, sendQueue, nodeStoreAdding])
|
||||
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
alert(err.message)
|
||||
}
|
||||
|
||||
return
|
||||
}//}}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue