Feature: Start the download if there is no response after 5 min.

master
masterhc 8 months ago
parent d24e6e4190
commit ab9392e530

@ -479,35 +479,14 @@ exports.torrent = (bot)=>
const filter = i => i.customId === 'Redirect'+random || i.customId === 'Remove'+random;
let message = await user.send({embeds: [embed], components: [row] });
const collector = message.createMessageComponentCollector({ filter, time: 60000 });
const collector = message.createMessageComponentCollector({ filter, time: 5*60000 });
collector.on('collect', async m =>
{
collector.stop();
m.deferUpdate();
let cookie = await fetch('https://utorrent.wordfights.com/api/v2/auth/login',
{
"headers":
{
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
"body":`username=${process.env.qbittorrentusername}&password=${process.env.qbittorrentpassword}`,
"method": "POST"
}
)
.then(handleResponse)
async function handleResponse(response)
{
try {
let headers = [...response.headers.entries()];
headers = headers.filter(i=>i[0]=='set-cookie')[0][1]
return headers
} catch (error) {
console.log(error)
return
}
let cookie = await getCookie();
}
if(!cookie) return
if(m.customId === 'Remove'+random)
@ -538,7 +517,43 @@ exports.torrent = (bot)=>
collector.on('end', async ()=>
{
message.edit({ components: [] });
await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", {
"headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie": cookie,
},
"body": `value=true&hashes=${req.params.id}`,
"method": "POST"
});
})
res.json({ok:'OK'})
}
}
async function getCookie()
{
return await fetch('https://utorrent.wordfights.com/api/v2/auth/login',
{
"headers":
{
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
"body":`username=${process.env.qbittorrentusername}&password=${process.env.qbittorrentpassword}`,
"method": "POST"
}
)
.then(handleResponse)
async function handleResponse(response)
{
try {
let headers = [...response.headers.entries()];
headers = headers.filter(i=>i[0]=='set-cookie')[0][1]
return headers
} catch (error) {
console.log(error)
return
}
}
}
Loading…
Cancel
Save