Merge pull request #421 from shocknet/fix/chandler-call
fix channels call
This commit is contained in:
commit
0f616c24d5
1 changed files with 15 additions and 19 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
//@ts-expect-error
|
||||
const res = await fetch(`${handlerBaseUrl}/channel`,{
|
||||
method:'POST',
|
||||
body:JSON.stringify({
|
||||
const channelReq = {
|
||||
userPubKey:identity_pubkey,
|
||||
invite,
|
||||
lndTo:pub,
|
||||
}
|
||||
//@ts-expect-error
|
||||
const res = await fetch(`${handlerBaseUrl}/channel`,{
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body:JSON.stringify(channelReq)
|
||||
})
|
||||
})
|
||||
|
||||
if(res.status !== 200 ){
|
||||
return
|
||||
}
|
||||
invites.push(invite)
|
||||
await Storage.setItem('processedInvites',invites)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue