Merge pull request #421 from shocknet/fix/chandler-call

fix channels call
This commit is contained in:
CapDog 2021-07-14 15:18:21 -04:00 committed by GitHub
commit 0f616c24d5

View file

@ -5,28 +5,19 @@ const { listPeers, connectPeer,getInfo } = require('./v2')
const handlerBaseUrl = "https://channels.shock.network:4444"
/**
*
* @param {string} inviteFromAuth
*/
module.exports = async (inviteFromAuth) => {
module.exports = async () => {
/**
* @type string | undefined
*/
const invite = inviteFromAuth || process.env.HOSTING_INVITE
const invite = process.env.HOSTING_INVITE
if(!invite) {
return
}
try{
await Storage.getItem('processedInvites')
} catch(e) {
await Storage.setItem('processedInvites',[])
}
try {
/**
* @type string[]
*/
const invites = await Storage.getItem('processedInvites')
const invites = await Storage.getItem('processedInvites') || []
if(invites.includes(invite)){
return
}
@ -46,17 +37,22 @@ module.exports = async (inviteFromAuth) => {
if(peers.findIndex(peer => peer.pub_key === pub) === -1){
await connectPeer(pub,host)
}
const channelReq = {
userPubKey:identity_pubkey,
invite,
lndTo:pub,
}
//@ts-expect-error
const res = await fetch(`${handlerBaseUrl}/channel`,{
method:'POST',
body:JSON.stringify({
userPubKey:identity_pubkey,
invite,
lndTo:pub,
})
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify(channelReq)
})
if(res.status !== 200 ){
return
}
invites.push(invite)
await Storage.setItem('processedInvites',invites)