mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 12:36:01 +00:00
fix
This commit is contained in:
21
node_modules/miniget/LICENSE
generated
vendored
Normal file
21
node_modules/miniget/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (C) 2017 by fent
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
80
node_modules/miniget/README.md
generated
vendored
Normal file
80
node_modules/miniget/README.md
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
# node-miniget
|
||||
|
||||
A small http(s) GET library with redirects, retries, reconnects, concatenating or streaming, and no dependencies. This keeps filesize small for potential browser use.
|
||||
|
||||
[](http://travis-ci.org/fent/node-miniget)
|
||||
[](https://david-dm.org/fent/node-miniget)
|
||||
[](https://codecov.io/gh/fent/node-miniget)
|
||||
|
||||
|
||||
# Usage
|
||||
|
||||
Concatenates a response
|
||||
|
||||
```js
|
||||
const miniget = require('miniget');
|
||||
|
||||
miniget('http://mywebsite.com', (err, body) => {
|
||||
console.log('webpage contents: ', body);
|
||||
}));
|
||||
```
|
||||
|
||||
Request can be streamed right away
|
||||
|
||||
```js
|
||||
miniget('http://api.mywebsite.com/v1/messages.json')
|
||||
.pipe(someWritableStream());
|
||||
```
|
||||
|
||||
|
||||
# API
|
||||
|
||||
### miniget(url, [options], [callback(err, body)])
|
||||
|
||||
Makes a GET request. `options` can have any properties from the [`http.request()` function](https://nodejs.org/api/http.html#http_http_request_options_callback), in addition to
|
||||
|
||||
* `maxRedirects` - Default is `2`.
|
||||
* `maxRetries` - Number of times to retry the request if there is a 500 or connection error. Default is `1`.
|
||||
* `maxReconnects` - During a big download, if there is a disconnect, miniget can try to reconnect and continue the download where it left off. Defaults to `0`.
|
||||
* `backoff` - An object with `inc` and `max` used to calculate how long to wait to retry a request. Defaults to `{ inc: 100, max: 10000 }`.
|
||||
* `highWaterMark` - Amount of data to buffer when in stream mode.
|
||||
* `transform` - Use this to add additional features. Called with the object that `http.get()` or `https.get()` would be called with. Must return a transformed object.
|
||||
* `acceptEncoding` - An object with encoding name as the key, and the value as a function that returns a decoding stream.
|
||||
```js
|
||||
acceptEncoding: { gzip: () => require('zlip').createGunzip(stream) }
|
||||
```
|
||||
Given encodings will be added to the `Accept-Encoding` header, and the response will be decoded if the server responds with encoded content.
|
||||
|
||||
If `callback` is given, will concatenate the response, and call `callback` with a possible error, and the response body.
|
||||
|
||||
Miniget returns a readable stream if `callback` is not given, errors will then be emitted on the stream. Returned stream also contains an `.abort()` method, and can emit the following events.
|
||||
|
||||
#### Event: redirect
|
||||
* `string` - URL redirected to.
|
||||
|
||||
Emitted when the request was redirected with a redirection status code.
|
||||
|
||||
#### Event: retry
|
||||
* `number` - Number of retry.
|
||||
* `Error` - Request or status code error.
|
||||
|
||||
Emitted when the request fails, or the response has a status code >= 500.
|
||||
|
||||
#### Event: reconnect
|
||||
* `number` - Number of reconnect.
|
||||
* `Error` - Request or response error.
|
||||
|
||||
Emitted when the request or response fails after download has started.
|
||||
|
||||
|
||||
# Install
|
||||
|
||||
npm install miniget
|
||||
|
||||
|
||||
# Tests
|
||||
Tests are written with [mocha](https://mochajs.org)
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
180
node_modules/miniget/lib/index.js
generated
vendored
Normal file
180
node_modules/miniget/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const urlParse = require('url').parse;
|
||||
const PassThrough = require('stream').PassThrough;
|
||||
|
||||
|
||||
const httpLibs = { 'http:': http, 'https:': https };
|
||||
const redirectCodes = { 301: true, 302: true, 303: true, 307: true };
|
||||
const defaults = {
|
||||
maxRedirects: 2,
|
||||
maxRetries: 2,
|
||||
maxReconnects: 0,
|
||||
backoff: { inc: 100, max: 10000 },
|
||||
highWaterMark: null,
|
||||
transform: null,
|
||||
acceptEncoding: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {!Object} options
|
||||
* @param {!Function(Error, http.IncomingMessage, string)} callback
|
||||
* @return {stream.Readable}
|
||||
*/
|
||||
module.exports = (url, options, callback) => {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
} else if (!options) {
|
||||
options = {};
|
||||
}
|
||||
options = Object.assign({}, defaults, options);
|
||||
const stream = new PassThrough({ highWaterMark: options.highWaterMark });
|
||||
let myreq, myres;
|
||||
let aborted = false;
|
||||
let redirects = 0;
|
||||
let retries = 0;
|
||||
let retryTimeout;
|
||||
let reconnects = 0;
|
||||
let contentLength;
|
||||
let acceptRanges = false;
|
||||
let rangeStart = 0, rangeEnd;
|
||||
let downloaded = 0;
|
||||
|
||||
// Check if this is a ranged request.
|
||||
if (options.headers && options.headers.Range) {
|
||||
let r = /bytes=(\d+)-(\d+)?/.exec(options.headers.Range);
|
||||
if (r) {
|
||||
rangeStart = parseInt(r[1], 10);
|
||||
rangeEnd = parseInt(r[2], 10);
|
||||
}
|
||||
}
|
||||
|
||||
// Add `Accept-Encoding` header.
|
||||
if (options.acceptEncoding) {
|
||||
options.headers = Object.assign({
|
||||
'Accept-Encoding': Object.keys(options.acceptEncoding).join(', ')
|
||||
}, options.headers);
|
||||
}
|
||||
|
||||
const onRequestError = (err, statusCode) => {
|
||||
if (!aborted) {
|
||||
// If there is an error when the download has already started,
|
||||
// but not finished, try reconnecting.
|
||||
if (myres && acceptRanges &&
|
||||
0 < downloaded && downloaded < contentLength) {
|
||||
if (reconnects++ < options.maxReconnects) {
|
||||
myres = null;
|
||||
retries = 0;
|
||||
let ms = Math.min(options.backoff.inc, options.backoff.max);
|
||||
retryTimeout = setTimeout(doDownload, ms);
|
||||
stream.emit('reconnect', reconnects, err);
|
||||
return;
|
||||
}
|
||||
} else if ((!statusCode || err.message === 'ENOTFOUND') &&
|
||||
retries++ < options.maxRetries) {
|
||||
let ms = Math.min(retries * options.backoff.inc, options.backoff.max);
|
||||
retryTimeout = setTimeout(doDownload, ms);
|
||||
stream.emit('retry', retries, err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream.emit('error', err);
|
||||
};
|
||||
|
||||
const doDownload = () => {
|
||||
if (aborted) { return; }
|
||||
let parsed = urlParse(url);
|
||||
let httpLib = httpLibs[parsed.protocol];
|
||||
if (!httpLib) {
|
||||
stream.emit('error', Error('Invalid URL: ' + url));
|
||||
return;
|
||||
}
|
||||
|
||||
Object.assign(parsed, options);
|
||||
for (let key in defaults) {
|
||||
delete parsed[key];
|
||||
}
|
||||
if (acceptRanges && downloaded > 0) {
|
||||
parsed.headers = Object.assign({}, parsed.headers, {
|
||||
Range: `bytes=${downloaded + rangeStart}-${rangeEnd || ''}`
|
||||
});
|
||||
}
|
||||
|
||||
if (options.transform) {
|
||||
parsed = options.transform(parsed);
|
||||
if (parsed.protocol) {
|
||||
httpLib = httpLibs[parsed.protocol];
|
||||
}
|
||||
}
|
||||
|
||||
myreq = httpLib.get(parsed, (res) => {
|
||||
if (redirectCodes[res.statusCode] === true) {
|
||||
if (redirects++ >= options.maxRedirects) {
|
||||
stream.emit('error', Error('Too many redirects'));
|
||||
} else {
|
||||
url = res.headers.location;
|
||||
stream.emit('redirect', url);
|
||||
doDownload();
|
||||
}
|
||||
return;
|
||||
} else if (res.statusCode < 200 || 400 <= res.statusCode) {
|
||||
let err = Error('Status code: ' + res.statusCode);
|
||||
if (res.statusCode >= 500) {
|
||||
onRequestError(err, res.statusCode);
|
||||
} else {
|
||||
stream.emit('error', err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let decoded = res;
|
||||
if (options.acceptEncoding && res.headers['content-encoding']) {
|
||||
for (let enc of res.headers['content-encoding'].split(', ').reverse()) {
|
||||
let fn = options.acceptEncoding[enc];
|
||||
if (fn != null) {
|
||||
decoded = decoded.pipe(fn(decoded));
|
||||
decoded.on('error', stream.emit.bind(stream, 'error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!contentLength) {
|
||||
contentLength = parseInt(res.headers['content-length'], 10);
|
||||
acceptRanges = res.headers['accept-ranges'] === 'bytes' &&
|
||||
contentLength > 0 && options.maxReconnects > 0;
|
||||
}
|
||||
if (acceptRanges) {
|
||||
res.on('data', (chunk) => { downloaded += chunk.length; });
|
||||
decoded.on('end', () => {
|
||||
if (downloaded === contentLength) {
|
||||
stream.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
decoded.pipe(stream, { end: !acceptRanges });
|
||||
myres = decoded;
|
||||
stream.emit('response', res);
|
||||
res.on('error', stream.emit.bind(stream, 'error'));
|
||||
});
|
||||
myreq.on('error', onRequestError);
|
||||
stream.emit('request', myreq);
|
||||
};
|
||||
|
||||
stream.abort = () => {
|
||||
aborted = true;
|
||||
stream.emit('abort');
|
||||
if (myreq) { myreq.abort(); }
|
||||
if (myres) { myres.unpipe(stream); }
|
||||
clearTimeout(retryTimeout);
|
||||
};
|
||||
|
||||
process.nextTick(doDownload);
|
||||
if (callback) {
|
||||
let body = '';
|
||||
stream.setEncoding('utf8');
|
||||
stream.on('data', (chunk) => { body += chunk; });
|
||||
stream.on('end', () => { callback(null, myres, body); });
|
||||
stream.on('error', callback);
|
||||
}
|
||||
return callback ? null : stream;
|
||||
};
|
69
node_modules/miniget/package.json
generated
vendored
Normal file
69
node_modules/miniget/package.json
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "miniget@^1.4.0",
|
||||
"_id": "miniget@1.5.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-KJ3AyIVZ76QuWAq43BWjkK+jLdhxhy3s4tsdg9Je91+cIFkeOSW2VEj2lSeKw50CPu1eCCkSbiQEBKL36mpA5w==",
|
||||
"_location": "/miniget",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "miniget@^1.4.0",
|
||||
"name": "miniget",
|
||||
"escapedName": "miniget",
|
||||
"rawSpec": "^1.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/m3u8stream",
|
||||
"/ytdl-core"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/miniget/-/miniget-1.5.1.tgz",
|
||||
"_shasum": "4f93840d5aaed21634cd12fd07d22f7d64e9d570",
|
||||
"_spec": "miniget@^1.4.0",
|
||||
"_where": "C:\\Users\\matia\\Bot Files\\node_modules\\ytdl-core",
|
||||
"author": {
|
||||
"name": "fent",
|
||||
"url": "https://github.com/fent"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fent/node-miniget/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "A small HTTP(S) GET request library, with redirects and streaming.",
|
||||
"devDependencies": {
|
||||
"istanbul": "^0.4.5",
|
||||
"lolex": "^3.0.0",
|
||||
"mocha": "^5.0.0",
|
||||
"nock": "^10.0.0",
|
||||
"stream-equal": "^1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/fent/node-miniget#readme",
|
||||
"keywords": [
|
||||
"request",
|
||||
"http",
|
||||
"https",
|
||||
"redirect",
|
||||
"stream"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"name": "miniget",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fent/node-miniget.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "istanbul cover node_modules/.bin/_mocha -- test/*-test.js"
|
||||
},
|
||||
"version": "1.5.1"
|
||||
}
|
Reference in New Issue
Block a user