Merge pull request #422 from shocknet/debug/channel-req

logs
This commit is contained in:
CapDog 2021-07-15 14:49:22 -04:00 committed by GitHub
commit 003393d8fc

View file

@ -6,11 +6,13 @@ const { listPeers, connectPeer,getInfo } = require('./v2')
const handlerBaseUrl = "https://channels.shock.network:4444"
module.exports = async () => {
console.log("DOING CHANNEL INVITE THING: START")
/**
* @type string | undefined
*/
const invite = process.env.HOSTING_INVITE
if(!invite) {
console.log("DOING CHANNEL INVITE THING: NVM NO INVITE")
return
}
try {
@ -19,17 +21,17 @@ module.exports = async () => {
*/
const invites = await Storage.getItem('processedInvites') || []
if(invites.includes(invite)){
console.log("DOING CHANNEL INVITE THING: INVITE PROCESSED ALREADY")
return
}
const me = await getInfo()
const {identity_pubkey} = me
//@ts-expect-error
const connectReq = await fetch(`${handlerBaseUrl}/connect`)
if(connectReq.status !== 200 ){
console.log("DOING CHANNEL INVITE THING: CONNECT FAILED")
return
}
const connJson = await connectReq.json()
const [uri] = connJson.uris
const [pub,host] = uri.split("@")
@ -51,13 +53,15 @@ module.exports = async () => {
body:JSON.stringify(channelReq)
})
if(res.status !== 200 ){
console.log("DOING CHANNEL INVITE THING: FAILED ")
return
}
invites.push(invite)
await Storage.setItem('processedInvites',invites)
console.log("DOING CHANNEL INVITE THING: DONE!")
} catch(e){
logger.error("error sending invite to channels handler")
console.log("DOING CHANNEL INVITE THING: :(")
console.error(e)
}