1- const fs = require ( 'graceful-fs' ) ;
2- const path = require ( 'path' ) ;
3- const querystring = require ( "querystring" ) ;
4- const fetch = require ( 'node-fetch' ) ;
5- const request = require ( 'postman-request' ) ;
6- const urlparse = require ( 'url' ) ;
7- const mkdirp = require ( 'mkdirp' ) ;
8- const log = require ( 'npmlog' ) ;
9-
10- const RateLimiter = require ( 'limiter' ) . RateLimiter ;
1+ import fs from 'graceful-fs' ;
2+ import path from 'path' ;
3+ import querystring from "querystring" ;
4+ import fetch from 'node-fetch' ;
5+ import request from 'postman-request' ;
6+ import urlparse from 'url' ;
7+ import mkdirp from 'mkdirp' ;
8+ import log from 'npmlog' ;
9+
10+ // import rl from 'limiter';
11+ // const RateLimiter = rl.RateLimiter;
1112
1213/* OPTIONS */
1314/*
@@ -26,7 +27,7 @@ post: POST request
2627let limiter , opts , queueDownload , download ;
2728
2829// create a filepath out of url, same as wget
29- const url_to_path = module . exports . url_to_path = function ( url , opts ) {
30+ const url_to_path = function ( url , opts ) {
3031 let parsedUrl = urlparse . parse ( url ) ;
3132 let p = path . join ( parsedUrl . hostname , parsedUrl . path ) ;
3233 // exorcise any trailing "/"
@@ -51,7 +52,7 @@ const url_to_path = module.exports.url_to_path = function(url, opts) {
5152// downcache("http://example.com", function(err, resp, body) {} )
5253
5354// we want to be flexible with the order of arguments since there are only three feasible types
54- module . exports = function ( ) {
55+ const Downcache = function ( ) {
5556 // this doesn't currently fire.
5657 let callback = function ( err , resp , body ) {
5758 log . info ( "This is the default downcache callback since you didn't provide one." ) ;
@@ -100,7 +101,7 @@ module.exports = function() {
100101
101102 log . level = opts . log ;
102103
103- limiter = new RateLimiter ( 1 , opts . limit ) ;
104+ // limiter = new RateLimiter(1, opts.limit);
104105
105106 if ( ! opts . useRequest ) {
106107 download = downloadWithFetch ;
@@ -109,13 +110,14 @@ module.exports = function() {
109110 }
110111
111112 queueDownload = function ( opts , callback ) {
112- limiter . removeTokens ( 1 , function ( err , remainingRequests ) {
113- if ( err ) {
114- log . info ( "rate limited " + opts . url ) ;
115- return callback ( "rate limited" ) ;
116- }
117- download ( opts , callback ) ;
118- } ) ;
113+ // limiter.removeTokens(1, function(err, remainingRequests) {
114+ // if (err) {
115+ // log.info("rate limited " + opts.url);
116+ // return callback("rate limited");
117+ // }
118+ // download(opts, callback);
119+ // });
120+ download ( opts , callback ) ;
119121 }
120122
121123 // copy `url` and `encoding` to the headers object
@@ -162,7 +164,7 @@ let fireCallback = function(opts, err, resp, body, callback) {
162164}
163165
164166// check if the file is in cache
165- let retrieve = module . exports . retrieve = function ( opts , callback ) {
167+ let retrieve = function ( opts , callback ) {
166168 if ( opts . force ) {
167169 queueDownload ( opts , callback ) ;
168170 return ;
@@ -301,13 +303,15 @@ function savePage(opts, resp, body) {
301303} // savePage
302304
303305// update the global settings that get used in absense of a specification in the individual call
304- module . exports . set = function ( property , value ) {
306+ function SetProperty ( property , value ) {
305307 if ( typeof property == "string" && typeof value == "string" ) {
306308 opts [ property ] = value ;
307309 } else if ( typeof property == "object" ) {
308310 opts = Object . assign ( property , opts ) ;
309311 }
310312 if ( property == "limit" || property . limit ) {
311- limiter = new RateLimiter ( 1 , opts . limit ) ;
313+ // limiter = new RateLimiter(1, opts.limit);
312314 }
313315}
316+
317+ export { Downcache , SetProperty } ;
0 commit comments