Remove absolute paths

This commit is contained in:
CrazyMax
2020-04-08 00:33:20 +02:00
parent ff47e64685
commit fce5f2e313
342 changed files with 6646 additions and 7223 deletions
+3 -23
View File
@@ -1,8 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const url = require('url');
const caw = require('caw');
const {URL} = require('url');
const contentDisposition = require('content-disposition');
const archiveType = require('archive-type');
const decompress = require('decompress');
@@ -16,7 +15,7 @@ const fileType = require('file-type');
const extName = require('ext-name');
const fsP = pify(fs);
const filenameFromPath = res => path.basename(url.parse(res.requestUrl).pathname);
const filenameFromPath = res => path.basename(new URL(res.requestUrl).pathname);
const getExtFromMime = res => {
const header = res.headers['content-type'];
@@ -58,37 +57,18 @@ const getFilename = (res, data) => {
return filename;
};
const getProtocolFromUri = uri => {
let {protocol} = url.parse(uri);
if (protocol) {
protocol = protocol.slice(0, -1);
}
return protocol;
};
module.exports = (uri, output, opts) => {
if (typeof output === 'object') {
opts = output;
output = null;
}
const protocol = getProtocolFromUri(uri);
opts = Object.assign({
encoding: null,
rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false'
}, opts);
const agent = caw(opts.proxy, {protocol});
const stream = got.stream(uri, Object.assign({agent}, opts))
.on('redirect', (response, nextOptions) => {
const redirectProtocol = getProtocolFromUri(nextOptions.href);
if (redirectProtocol && redirectProtocol !== protocol) {
nextOptions.agent = caw(opts.proxy, {protocol: redirectProtocol});
}
});
const stream = got.stream(uri, opts);
const promise = pEvent(stream, 'response').then(res => {
const encoding = opts.encoding === null ? 'buffer' : opts.encoding;