Merge pull request #34 from shocknet/http-gun

Http gun
This commit is contained in:
Daniel Lugo 2020-02-21 16:37:58 -04:00 committed by GitHub
commit 1c00f194c7
3 changed files with 101 additions and 1 deletions

View file

@ -5,6 +5,8 @@
"prettier/prettier": "error",
"strict": "off",
"no-empty-function": "off",
"no-console": "off",
"max-statements": "off",

View file

@ -436,6 +436,8 @@ const onOutgoing = cb => {
/** @type {Chat[]} */
let currentChats = []
const getChats = () => currentChats
/** @type {Set<ChatsListener>} */
const chatsListeners = new Set()
@ -596,10 +598,12 @@ module.exports = {
onSimplerReceivedRequests: require('./onReceivedReqs').onReceivedReqs,
onSimplerSentRequests: require('./onSentReqs').onSentReqs,
getCurrentSentReqs: require('./onSentReqs').getCurrentSentReqs,
getCurrentReceivedReqs: require('./onReceivedReqs').getReceivedReqs,
onBio,
onSeedBackup,
onChats,
getAvatar,
getDisplayName,
getHandshakeAddress
getHandshakeAddress,
getChats
}

View file

@ -284,6 +284,7 @@ module.exports = async (
errorMessage: "Please create a wallet before using the API"
});
}
next()
} catch (err) {
logger.error(err);
res
@ -1562,6 +1563,99 @@ module.exports = async (
});
});
const GunEvent = require('../services/gunDB/event-constants')
const Events = require('../services/gunDB/contact-api/events')
app.get(`/api/gun/${GunEvent.ON_RECEIVED_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerReceivedRequests(() => {})()
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
app.get(`/api/gun/${GunEvent.ON_SENT_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerSentRequests(() => {})()
const data = Events.getCurrentSentReqs()
res.json({
data,
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
app.get(`/api/gun/${GunEvent.ON_CHATS}`, (_, res) => {
try {
// spinup
Events.onChats(() => {})()
const data = Events.getChats()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
app.get(`/api/gun/${GunEvent.ON_AVATAR}`, (_, res) => {
try {
// spinup
Events.onAvatar(() => {})()
const data = Events.getAvatar()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
app.get(`/api/gun/${GunEvent.ON_DISPLAY_NAME}`, (_, res) => {
try {
// spinup
Events.onDisplayName(() => {})()
const data = Events.getDisplayName()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
app.get(`/api/gun/${GunEvent.ON_HANDSHAKE_ADDRESS}`, (_, res) => {
try {
// spinup
Events.onCurrentHandshakeAddress(() => {})()
const data = Events.getHandshakeAddress()
res.json({
data
})
} catch (err) {
res.status(500).json({
errorMessage: typeof err === 'string' ? err : err.message
})
}
})
/**
* Return app so that it can be used by express.
*/