fixies
This commit is contained in:
parent
6d8c82b693
commit
b0c5f40595
2 changed files with 41 additions and 29 deletions
|
|
@ -1112,15 +1112,18 @@ const sendSpontaneousPayment = async (
|
|||
console.log(orderResponse)
|
||||
console.log(Schema.isOrderResponse(orderResponse))
|
||||
|
||||
if (Schema.isOrderResponse(orderResponse)) {
|
||||
//@ts-expect-error
|
||||
if (orderResponse && orderResponse.type === 'orderAck') {
|
||||
//@ts-expect-error
|
||||
res(orderResponse)
|
||||
}
|
||||
})
|
||||
}),
|
||||
v => !Schema.isOrderResponse(v)
|
||||
//@ts-expect-error
|
||||
v => !v || !v.type
|
||||
)
|
||||
|
||||
if (!Schema.isOrderResponse(encryptedOrderAckRes)) {
|
||||
if (!encryptedOrderAckRes || !encryptedOrderAckRes.type) {
|
||||
const e = TypeError(
|
||||
`Expected encryptedOrderAckRes got: ${typeof encryptedOrderAckRes}`
|
||||
)
|
||||
|
|
@ -1361,17 +1364,17 @@ const createPostNew = async (tags, title, content, SEA) => {
|
|||
}
|
||||
const mySecret = require('../Mediator').getMySecret()
|
||||
await Common.Utils.asyncForEach(content, async c => {
|
||||
const cBis = c
|
||||
if (
|
||||
(cBis.type === 'image/embedded' || cBis.type === 'video/embedded') &&
|
||||
cBis.isPrivate
|
||||
) {
|
||||
const encryptedMagnet = await SEA.encrypt(cBis.magnetURI, mySecret)
|
||||
cBis.magnetURI = encryptedMagnet
|
||||
}
|
||||
// @ts-expect-error
|
||||
const uuid = Gun.text.random()
|
||||
newPost.contentItems[uuid] = cBis
|
||||
if (
|
||||
(c.type === 'image/embedded' || c.type === 'video/embedded') &&
|
||||
c.isPrivate
|
||||
) {
|
||||
const encryptedMagnet = await SEA.encrypt(c.magnetURI, mySecret)
|
||||
newPost.contentItems[uuid] = { ...c, magnetURI: encryptedMagnet }
|
||||
} else {
|
||||
newPost.contentItems[uuid] = c
|
||||
}
|
||||
})
|
||||
|
||||
/** @type {string} */
|
||||
|
|
|
|||
|
|
@ -357,6 +357,11 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
}
|
||||
case 'torrentSeed': {
|
||||
console.log('TORRENT')
|
||||
const numberOfTokens = Number(ackInfo)
|
||||
if (isNaN(numberOfTokens)) {
|
||||
breakError = 'ackInfo provided is not a valid number'
|
||||
break
|
||||
}
|
||||
const seedUrl = process.env.TORRENT_SEED_URL
|
||||
const seedToken = process.env.TORRENT_SEED_TOKEN
|
||||
if (!seedUrl || !seedToken) {
|
||||
|
|
@ -364,26 +369,30 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
break //service not available
|
||||
}
|
||||
console.log('SEED URL OK')
|
||||
const token = crypto.randomBytes(32).toString('hex')
|
||||
const reqData = {
|
||||
seed_token: seedToken,
|
||||
wallet_token: token
|
||||
const tokens = Array(numberOfTokens)
|
||||
for (let i = 0; i < numberOfTokens; i++) {
|
||||
tokens[i] = crypto.randomBytes(32).toString('hex')
|
||||
}
|
||||
console.log(seedUrl)
|
||||
console.log(seedToken)
|
||||
const res = await fetch(`${seedUrl}/api/enroll_token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(reqData)
|
||||
})
|
||||
if (res.status !== 200) {
|
||||
breakError = 'torrentSeed service currently not available'
|
||||
break //request didnt work, save coordinate anyway
|
||||
/**@param {string} token */
|
||||
const enrollToken = async token => {
|
||||
const reqData = {
|
||||
seed_token: seedToken,
|
||||
wallet_token: token
|
||||
}
|
||||
const res = await fetch(`${seedUrl}/api/enroll_token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(reqData)
|
||||
})
|
||||
if (res.status !== 200) {
|
||||
throw new Error('torrentSeed service currently not available')
|
||||
}
|
||||
}
|
||||
await Promise.all(tokens.map(enrollToken))
|
||||
console.log('RES SEED OK')
|
||||
const ackData = { seedUrl, token }
|
||||
const ackData = { seedUrl, tokens }
|
||||
const toSend = JSON.stringify(ackData)
|
||||
const encrypted = await SEA.encrypt(toSend, secret)
|
||||
const serviceResponse = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue