ibrod83 / nodejs-file-downloader

130 stars 23 forks source link

Progress is not 100% even though the file is already downloaded #43

Closed Lott-Noob closed 2 years ago

Lott-Noob commented 2 years ago

I was implementing this package to my discord bot that downloads file on my server. But when I am trying to show the file download progress on discord embed. using the onProgress percentage. Though the file gets downloaded to my server but the progress still showing its downloading at very slow speed and then the bot gets timeout

My Code:

`run: async (client, interaction) => { await interaction.deferReply();

    // await interaction.reply({ content: interaction.options.get('link').value })

    const downloader = new Downloader({
        url: interaction.options.get('link').value, 
        directory: "././downloads"
        onProgress(percentage, chunk, remaningSize) {

            const fileDownloadingEmbed = new EmbedBuilder()
                .setColor(0xffdd1c)
                .setTitle('File Downloading')
                .setDescription(percentage+'%')
                .addFields(
                    { name: 'Filename: ', value: deduceFileNameFromUrl(interaction.options.get('link').value)  },
                    //
                    // { name: 'Download Info', value: 'Total Size: ' + byteHelper(stats.total)+'\n'+'Downloaded: ' + byteHelper(stats.downloaded)+'\n'+ 'Speed: '+ byteHelper(stats.speed)+'s'+'\n' + 'Progress: '+ Math.round(stats.progress)+'%'}
                ).setFooter({text: 'Upload requested by '+ interaction.user.username , iconURL: interaction.user.displayAvatarURL({size:1024}) } );

            interaction.editReply({embeds: [fileDownloadingEmbed]})
        }

    });

    try {
        await downloader.download();
    } catch (error) {
        console.log(error);
    }
}

}; `

image image

ibrod83 commented 2 years ago

Can you post a simplified code that reproduces the problem? There's too many details and unfamiliar code in your example. I do not know what interaction.deferReply() or EmbedBuilder are.

Lott-Noob commented 2 years ago

Can you post a simplified code that reproduces the problem? There's too many details and unfamiliar code in your example. I do not know what interaction.deferReply() or EmbedBuilder are.

Actually I am using the discord node js api wrapper. And I am showing the progress of downloaded file through a discord bot.😀

ibrod83 commented 2 years ago

Unfortunately I do not have a way to reproduce this, being that the code is being used in the context of Discord API, which i'm not familiar with.