Catch and log in several routes
This commit is contained in:
parent
3d5aa766da
commit
ea22f3bab9
1 changed files with 140 additions and 86 deletions
226
src/routes.js
226
src/routes.js
|
|
@ -2410,108 +2410,145 @@ 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) => {
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
try {
|
||||||
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
const { path } = req.params
|
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
||||||
logger.info(`gun ONCE: ${path}`)
|
const { path } = req.params
|
||||||
res.status(200).json({
|
logger.info(`gun ONCE: ${path}`)
|
||||||
data: await handleGunFetch({
|
const 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) => {
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
try {
|
||||||
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
const { path } = req.params
|
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
||||||
logger.info(`gun LOAD: ${path}`)
|
const { path } = req.params
|
||||||
res.status(200).json({
|
logger.info(`gun LOAD: ${path}`)
|
||||||
data: await handleGunFetch({
|
const 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) => {
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
|
||||||
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
|
||||||
const { path } = req.params
|
|
||||||
logger.info(`gun otheruser ONCE: ${path}`)
|
|
||||||
res.status(200).json({
|
|
||||||
data: await handleGunFetch({
|
|
||||||
path,
|
|
||||||
startFromUserGraph: true,
|
|
||||||
type: 'once',
|
|
||||||
publicKeyForDecryption,
|
|
||||||
epubForDecryption
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
ap.get('/api/gun/user/load/:path', async (req, res) => {
|
|
||||||
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
|
||||||
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
|
||||||
const { path } = req.params
|
|
||||||
logger.info(`gun self user LOAD: ${path}`)
|
|
||||||
res.status(200).json({
|
|
||||||
data: await handleGunFetch({
|
|
||||||
path,
|
|
||||||
startFromUserGraph: true,
|
|
||||||
type: 'load',
|
|
||||||
publicKeyForDecryption,
|
|
||||||
epubForDecryption
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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 epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
|
||||||
const { path /*:rawPath*/, publicKey, type } = req.params
|
|
||||||
logger.info(`gun otheruser ${type}: ${path}`)
|
|
||||||
// const path = decodeURI(rawPath)
|
|
||||||
if (!publicKey || publicKey === 'undefined') {
|
|
||||||
res.status(400).json({
|
|
||||||
errorMessage: 'Invalid publicKey specified'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!allowedTypes.includes(type)) {
|
|
||||||
res.status(400).json({
|
|
||||||
errorMessage: 'Invalid type specified'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
|
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
||||||
|
const { path } = req.params
|
||||||
|
logger.info(`gun otheruser ONCE: ${path}`)
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
data: await handleGunFetch({
|
data: await handleGunFetch({
|
||||||
path,
|
path,
|
||||||
startFromUserGraph: false,
|
startFromUserGraph: true,
|
||||||
type,
|
type: 'once',
|
||||||
publicKey,
|
|
||||||
publicKeyForDecryption,
|
publicKeyForDecryption,
|
||||||
epubForDecryption
|
epubForDecryption
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
res
|
logger.error(e)
|
||||||
.status(
|
res.status(500).json({
|
||||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
errorMessage: e.message
|
||||||
)
|
})
|
||||||
.json({
|
}
|
||||||
errorMessage: err.message
|
})
|
||||||
|
|
||||||
|
ap.get('/api/gun/user/load/:path', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
|
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
||||||
|
const { path } = req.params
|
||||||
|
logger.info(`gun self user LOAD: ${path}`)
|
||||||
|
res.status(200).json({
|
||||||
|
data: await handleGunFetch({
|
||||||
|
path,
|
||||||
|
startFromUserGraph: true,
|
||||||
|
type: 'load',
|
||||||
|
publicKeyForDecryption,
|
||||||
|
epubForDecryption
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e)
|
||||||
|
res.status(500).json({
|
||||||
|
errorMessage: e.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ap.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const allowedTypes = ['once', 'load', 'open']
|
||||||
|
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
|
||||||
|
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
|
||||||
|
const { path /*:rawPath*/, publicKey, type } = req.params
|
||||||
|
logger.info(`gun otheruser ${type}: ${path}`)
|
||||||
|
// const path = decodeURI(rawPath)
|
||||||
|
if (!publicKey || publicKey === 'undefined') {
|
||||||
|
res.status(400).json({
|
||||||
|
errorMessage: 'Invalid publicKey specified'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowedTypes.includes(type)) {
|
||||||
|
res.status(400).json({
|
||||||
|
errorMessage: 'Invalid type specified'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
res.status(200).json({
|
||||||
|
data: await handleGunFetch({
|
||||||
|
path,
|
||||||
|
startFromUserGraph: false,
|
||||||
|
type,
|
||||||
|
publicKey,
|
||||||
|
publicKeyForDecryption,
|
||||||
|
epubForDecryption
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
res
|
||||||
|
.status(
|
||||||
|
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||||
|
)
|
||||||
|
.json({
|
||||||
|
errorMessage: err.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e)
|
||||||
|
res.status(500).json({
|
||||||
|
errorMessage: e.message
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -2556,6 +2593,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 +2615,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 +2649,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,19 +2659,33 @@ 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) => {
|
||||||
res.sendFile(path.join(__dirname, '/index.html'))
|
try {
|
||||||
})
|
res.sendFile(path.join(__dirname, '/index.html'))
|
||||||
ap.post('/api/enableNotificationsOverlay', (req, res) => {
|
} catch (e) {
|
||||||
const { postID } = req.body
|
logger.error(e)
|
||||||
if (!postID) {
|
res.status(500).json({
|
||||||
return res.status(400).json({
|
errorMessage: e.message
|
||||||
errorMessage: 'no post id provided'
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ap.post('/api/enableNotificationsOverlay', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { postID } = req.body
|
||||||
|
if (!postID) {
|
||||||
|
return res.status(400).json({
|
||||||
|
errorMessage: 'no post id provided'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const accessId = TipsForwarder.enablePostNotifications(postID)
|
||||||
|
res.json({
|
||||||
|
accessId
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e)
|
||||||
|
res.status(500).json({
|
||||||
|
errorMessage: e.message
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const accessId = TipsForwarder.enablePostNotifications(postID)
|
|
||||||
res.json({
|
|
||||||
accessId
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
//this is for wasLive/isLive status
|
//this is for wasLive/isLive status
|
||||||
ap.post('/api/listenStream', (req, res) => {
|
ap.post('/api/listenStream', (req, res) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue