commit
003393d8fc
1 changed files with 7 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue