Download from the server if Hapi server is down
Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
parent
2487e6efcd
commit
33719b4f13
1 changed files with 10 additions and 4 deletions
|
@ -68,13 +68,15 @@ class DownloadCommand extends Command {
|
||||||
|
|
||||||
|
|
||||||
if (Hapi) {
|
if (Hapi) {
|
||||||
Embed.setFooter(`Using Hapi | ${Embed.footer.text}`);
|
let error = false;
|
||||||
compressEmbed.setFooter(`Using Hapi | ${compressEmbed.footer.text}`);
|
|
||||||
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append('url', args.link.href);
|
params.append('url', args.link.href);
|
||||||
fetch(`${Hapi}/download`, {method: 'POST', body: params})
|
fetch(`${Hapi}/download`, {method: 'POST', body: params})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
|
Embed.setFooter(`Using Hapi | ${Embed.footer.text}`);
|
||||||
|
compressEmbed.setFooter(`Using Hapi | ${compressEmbed.footer.text}`);
|
||||||
|
|
||||||
if (res.headers.get('content-type') == 'application/json; charset=utf-8') {
|
if (res.headers.get('content-type') == 'application/json; charset=utf-8') {
|
||||||
let json = await res.json();
|
let json = await res.json();
|
||||||
let compressmsg = await message.channel.send(compressEmbed);
|
let compressmsg = await message.channel.send(compressEmbed);
|
||||||
|
@ -134,15 +136,19 @@ class DownloadCommand extends Command {
|
||||||
message.channel.send({embed: Embed, files: [`${os.tmpdir()}/${message.id}.mp4`]});
|
message.channel.send({embed: Embed, files: [`${os.tmpdir()}/${message.id}.mp4`]});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
message.delete();
|
message.delete();
|
||||||
loadingmsg.delete();
|
loadingmsg.delete();
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return message.channel.send('Hapi server returned an error.');
|
error = true;
|
||||||
|
message.channel.send('Hapi server returned an error or is unreachable. Trying standalone download.');
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
if (!error)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.listproxy) {
|
if (args.listproxy) {
|
||||||
|
|
Loading…
Reference in a new issue