mirror of https://codeberg.org/pzp/pzp-dict.git
add a try catch, plus minor renaming
This commit is contained in:
parent
cf207f9553
commit
2f885fd807
28
lib/index.js
28
lib/index.js
|
@ -183,13 +183,13 @@ module.exports = {
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} rootID
|
||||
* @param {Msg} root
|
||||
* @param {string} mootID
|
||||
* @param {Msg} moot
|
||||
*/
|
||||
function learnRecordRoot(rootID, root) {
|
||||
const subdomain = toSubdomain(root.metadata.domain)
|
||||
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID)
|
||||
tangle.add(rootID, root)
|
||||
function learnRecordMoot(mootID, moot) {
|
||||
const subdomain = toSubdomain(moot.metadata.domain)
|
||||
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
|
||||
tangle.add(mootID, moot)
|
||||
tangles.set(subdomain, tangle)
|
||||
}
|
||||
|
||||
|
@ -200,9 +200,9 @@ module.exports = {
|
|||
*/
|
||||
function learnRecordUpdate(msgID, msg) {
|
||||
const { account, domain } = msg.metadata
|
||||
const rootID = MsgV3.getMootID(account, domain)
|
||||
const mootID = MsgV3.getMootID(account, domain)
|
||||
const subdomain = toSubdomain(domain)
|
||||
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID)
|
||||
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
|
||||
tangle.add(msgID, msg)
|
||||
tangles.set(subdomain, tangle)
|
||||
|
||||
|
@ -231,7 +231,7 @@ module.exports = {
|
|||
function maybeLearnAboutRecord(msgID, msg) {
|
||||
if (msg.metadata.account !== accountID) return
|
||||
if (isValidRecordMoot(msg)) {
|
||||
learnRecordRoot(msgID, msg)
|
||||
learnRecordMoot(msgID, msg)
|
||||
return
|
||||
}
|
||||
if (isValidRecordMsg(msg)) {
|
||||
|
@ -317,9 +317,13 @@ module.exports = {
|
|||
}
|
||||
cancelOnRecordAdded = peer.db.onRecordAdded(
|
||||
(/** @type {RecPresent} */ rec) => {
|
||||
if (!rec.msg) return
|
||||
maybeLearnAboutRecord(rec.id, rec.msg)
|
||||
})
|
||||
try {
|
||||
maybeLearnAboutRecord(rec.id, rec.msg)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
)
|
||||
resolve()
|
||||
cb()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue