Do not retry and wait, let GunSmith handle
This commit is contained in:
parent
289fe1c918
commit
6ec931e1fa
1 changed files with 26 additions and 39 deletions
|
|
@ -2288,48 +2288,35 @@ module.exports = async (
|
||||||
epubForDecryption
|
epubForDecryption
|
||||||
}) => {
|
}) => {
|
||||||
const keys = path.split('>')
|
const keys = path.split('>')
|
||||||
const { tryAndWait } = require('../services/gunDB/contact-api/utils')
|
const { gun, user } = require('../services/gunDB/Mediator')
|
||||||
return tryAndWait((gun, user) => {
|
|
||||||
// eslint-disable-next-line no-nested-ternary
|
|
||||||
let node = startFromUserGraph
|
|
||||||
? user
|
|
||||||
: publicKey
|
|
||||||
? gun.user(publicKey)
|
|
||||||
: gun
|
|
||||||
logger.info(`fetching: ${keys}`)
|
|
||||||
keys.forEach(key => (node = node.get(key)))
|
|
||||||
|
|
||||||
if (!publicKeyForDecryption || !epubForDecryption) {
|
// eslint-disable-next-line no-nested-ternary
|
||||||
logger.warn('[GUN] Missing public key for decryption!', {
|
let node = startFromUserGraph
|
||||||
publicKeyForDecryption,
|
? user
|
||||||
epubForDecryption
|
: publicKey
|
||||||
})
|
? gun.user(publicKey)
|
||||||
|
: gun
|
||||||
|
keys.forEach(key => (node = node.get(key)))
|
||||||
|
logger.info(`fetching: ${keys}`)
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
const listener = data => {
|
||||||
|
logger.info(`got res for: ${keys}`)
|
||||||
|
logger.info(data || 'falsey data (does not get logged)')
|
||||||
|
if (publicKeyForDecryption) {
|
||||||
|
GunWriteRPC.deepDecryptIfNeeded(
|
||||||
|
data,
|
||||||
|
publicKeyForDecryption,
|
||||||
|
epubForDecryption
|
||||||
|
)
|
||||||
|
.then(res)
|
||||||
|
.catch(rej)
|
||||||
|
} else {
|
||||||
|
res(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
if (type === 'once') node.once(listener)
|
||||||
try {
|
if (type === 'load') node.load(listener)
|
||||||
const listener = data => {
|
|
||||||
logger.info(`got res for: ${keys}`)
|
|
||||||
logger.info(data || 'falsey data (does not get logged)')
|
|
||||||
if (publicKeyForDecryption) {
|
|
||||||
GunWriteRPC.deepDecryptIfNeeded(
|
|
||||||
data,
|
|
||||||
publicKeyForDecryption,
|
|
||||||
epubForDecryption
|
|
||||||
)
|
|
||||||
.then(res)
|
|
||||||
.catch(rej)
|
|
||||||
} else {
|
|
||||||
res(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'once') node.once(listener)
|
|
||||||
if (type === 'load') node.load(listener)
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('Gun Fetch Error:', err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue