Merge pull request #450 from shocknet/misc-fixes

Try catch in gun rpc endpoints
This commit is contained in:
CapDog 2021-08-20 16:27:17 -04:00 committed by GitHub
commit 6a107adb64

View file

@ -2410,70 +2410,103 @@ module.exports = async (
const EPUB_FOR_DECRYPT_HEADER = 'epub-for-decryption' const EPUB_FOR_DECRYPT_HEADER = 'epub-for-decryption'
ap.get('/api/gun/once/:path', async (req, res) => { ap.get('/api/gun/once/:path', async (req, res) => {
try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun ONCE: ${path}`) logger.info(`gun ONCE: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: false, startFromUserGraph: false,
type: 'once', type: 'once',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.get('/api/gun/load/:path', async (req, res) => { ap.get('/api/gun/load/:path', async (req, res) => {
try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun LOAD: ${path}`) logger.info(`gun LOAD: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: false, startFromUserGraph: false,
type: 'load', type: 'load',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.get('/api/gun/user/once/:path', async (req, res) => { ap.get('/api/gun/user/once/:path', async (req, res) => {
try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun otheruser ONCE: ${path}`) logger.info(`gun otheruser ONCE: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: true, startFromUserGraph: true,
type: 'once', type: 'once',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.get('/api/gun/user/load/:path', async (req, res) => { ap.get('/api/gun/user/load/:path', async (req, res) => {
try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun self user LOAD: ${path}`) logger.info(`gun self user LOAD: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: true, startFromUserGraph: true,
type: 'load', type: 'load',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => { ap.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => {
try {
const allowedTypes = ['once', 'load', 'open'] const allowedTypes = ['once', 'load', 'open']
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2493,9 +2526,7 @@ module.exports = async (
}) })
return return
} }
try { const data = await handleGunFetch({
res.status(200).json({
data: await handleGunFetch({
path, path,
startFromUserGraph: false, startFromUserGraph: false,
type, type,
@ -2503,6 +2534,9 @@ module.exports = async (
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
try {
res.status(200).json({
data
}) })
} catch (err) { } catch (err) {
res res
@ -2513,6 +2547,12 @@ module.exports = async (
errorMessage: err.message errorMessage: err.message
}) })
} }
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.post('/api/lnd/cb/:methodName', (req, res) => { ap.post('/api/lnd/cb/:methodName', (req, res) => {
@ -2556,6 +2596,7 @@ module.exports = async (
ok: true ok: true
}) })
} catch (err) { } catch (err) {
logger.error(err)
res res
.status( .status(
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500 err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
@ -2577,6 +2618,7 @@ module.exports = async (
id id
}) })
} catch (err) { } catch (err) {
logger.error(err)
res res
.status( .status(
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500 err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
@ -2610,6 +2652,7 @@ module.exports = async (
res.status(200).json(results) res.status(200).json(results)
} catch (e) { } catch (e) {
logger.error(e)
res res
.status(e.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500) .status(e.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
.json({ .json({
@ -2619,9 +2662,17 @@ module.exports = async (
}) })
//this is for OBS notifications, not wired with UI. //this is for OBS notifications, not wired with UI.
ap.get('/api/subscribeStream', (req, res) => { ap.get('/api/subscribeStream', (req, res) => {
try {
res.sendFile(path.join(__dirname, '/index.html')) res.sendFile(path.join(__dirname, '/index.html'))
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
ap.post('/api/enableNotificationsOverlay', (req, res) => { ap.post('/api/enableNotificationsOverlay', (req, res) => {
try {
const { postID } = req.body const { postID } = req.body
if (!postID) { if (!postID) {
return res.status(400).json({ return res.status(400).json({
@ -2632,6 +2683,12 @@ module.exports = async (
res.json({ res.json({
accessId accessId
}) })
} catch (e) {
logger.error(e)
res.status(500).json({
errorMessage: e.message
})
}
}) })
//this is for wasLive/isLive status //this is for wasLive/isLive status
ap.post('/api/listenStream', (req, res) => { ap.post('/api/listenStream', (req, res) => {