Merge pull request #314 from shocknet/feature/gun-http-open
Added "open" method to GunDB
This commit is contained in:
commit
64007596c6
1 changed files with 13 additions and 17 deletions
|
|
@ -2937,7 +2937,7 @@ module.exports = async (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} HandleGunFetchParams
|
* @typedef {object} HandleGunFetchParams
|
||||||
* @prop {'once'|'load'} type
|
* @prop {'once'|'load'|'open'} type
|
||||||
* @prop {boolean} startFromUserGraph
|
* @prop {boolean} startFromUserGraph
|
||||||
* @prop {string} path
|
* @prop {string} path
|
||||||
* @prop {string=} publicKey
|
* @prop {string=} publicKey
|
||||||
|
|
@ -2981,6 +2981,7 @@ module.exports = async (
|
||||||
|
|
||||||
if (type === 'once') node.once(listener)
|
if (type === 'once') node.once(listener)
|
||||||
if (type === 'load') node.load(listener)
|
if (type === 'load') node.load(listener)
|
||||||
|
if (type === 'open') node.open(listener)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -3042,28 +3043,23 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
ap.get('/api/gun/otheruser/:publicKey/once/:path', async (req, res) => {
|
ap.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => {
|
||||||
|
const allowedTypes = ['once', 'load', 'open']
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
const { path, publicKey } = req.params
|
const { path, publicKey, type } = req.params
|
||||||
res.status(200).json({
|
|
||||||
data: await handleGunFetch({
|
if (!allowedTypes.includes(type)) {
|
||||||
path,
|
res.status(400).json({
|
||||||
startFromUserGraph: false,
|
errorMessage: 'Invalid type specified'
|
||||||
type: 'once',
|
})
|
||||||
publicKey,
|
return
|
||||||
publicKeyForDecryption
|
}
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
ap.get('/api/gun/otheruser/:publicKey/load/:path', async (req, res) => {
|
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
|
||||||
const { path, publicKey } = req.params
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
data: await handleGunFetch({
|
data: await handleGunFetch({
|
||||||
path,
|
path,
|
||||||
startFromUserGraph: false,
|
startFromUserGraph: false,
|
||||||
type: 'load',
|
type,
|
||||||
publicKey,
|
publicKey,
|
||||||
publicKeyForDecryption
|
publicKeyForDecryption
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue