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