From 679d417bd9622d46b54612c8a629eb8ccc0cc623 Mon Sep 17 00:00:00 2001 From: emad-salah Date: Thu, 4 Mar 2021 17:02:31 +0100 Subject: [PATCH 1/2] Add support for calling GunDB "open" through HTTP --- src/routes.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/routes.js b/src/routes.js index c52b7757..37bcfc32 100644 --- a/src/routes.js +++ b/src/routes.js @@ -2981,6 +2981,7 @@ module.exports = async ( if (type === 'once') node.once(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 { path, publicKey } = req.params - res.status(200).json({ - data: await handleGunFetch({ - path, - startFromUserGraph: false, - type: 'once', - publicKey, - publicKeyForDecryption - }) - }) - }) + const { path, publicKey, type } = req.params + + if (!allowedTypes.includes(type)) { + res.status(400).json({ + errorMessage: 'Invalid type specified' + }) + return + } - 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({ data: await handleGunFetch({ path, startFromUserGraph: false, - type: 'load', + type, publicKey, publicKeyForDecryption }) From 5864c62d28f801c02893c7b2a7935a62d6bb9c4d Mon Sep 17 00:00:00 2001 From: emad-salah Date: Thu, 4 Mar 2021 17:05:30 +0100 Subject: [PATCH 2/2] Fix typing --- src/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 37bcfc32..11481455 100644 --- a/src/routes.js +++ b/src/routes.js @@ -2937,7 +2937,7 @@ module.exports = async ( /** * @typedef {object} HandleGunFetchParams - * @prop {'once'|'load'} type + * @prop {'once'|'load'|'open'} type * @prop {boolean} startFromUserGraph * @prop {string} path * @prop {string=} publicKey