Browse Source

Add event listener for 'download.started' with the filepath and length information

node16
Onja 12 months ago
parent
commit
93795e29d1
  1. 1
      src/models/file.js
  2. 5
      src/subscribers/consoleSubscriber.js

1
src/models/file.js

@ -78,6 +78,7 @@ class File {
// Get the content length and parse it to an integer
const contentLength = parseInt(response.headers['content-length'], 10);
emitter.emit('download.started', { url: this.url, filepath: this.filepath, length: contentLength });
const step = Math.floor(contentLength / 100);
let stepLimit = step;

5
src/subscribers/consoleSubscriber.js

@ -13,6 +13,11 @@ emitter.on('download.start', ({ url, filepath }) => {
log('download.start', `Downloading to ${filepath}`);
});
// Create a new listener for the download.start event
emitter.on('download.started', ({ url, filepath, length }) => {
log('download.started', `Downloading to ${filepath} and length is ${length}`);
});
// Create a new listener for the download.end event
emitter.on('download.end', ({ url, filepath }) => {
log('download.end', `Downloaded to ${filepath}`);

Loading…
Cancel
Save