Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Rename more
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed May 4, 2020
1 parent e0a18ab commit 46b2fb4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function toAxiosAuth (auth) {
return (axiosAuth.username && axiosAuth.password) ? axiosAuth : null;
}

async function uploadFileToHttp (localFileStream, parsedUrl, uploadOptions = {}) {
async function uploadFileToHttp (localFileStream, parsedUri, uploadOptions = {}) {
const {
method = 'POST',
timeout = 5000,
Expand All @@ -34,7 +34,7 @@ async function uploadFileToHttp (localFileStream, parsedUrl, uploadOptions = {})
const {
protocol,
href,
} = parsedUrl;
} = parsedUri;

const requestOpts = {
url: href,
Expand Down Expand Up @@ -67,7 +67,7 @@ async function uploadFileToHttp (localFileStream, parsedUrl, uploadOptions = {})
await axios(requestOpts);
}

async function uploadFileToFtp (localFileStream, parsedUrl, uploadOptions = {}) {
async function uploadFileToFtp (localFileStream, parsedUri, uploadOptions = {}) {
const {
auth,
} = uploadOptions;
Expand All @@ -76,7 +76,7 @@ async function uploadFileToFtp (localFileStream, parsedUrl, uploadOptions = {})
port,
protocol,
pathname,
} = parsedUrl;
} = parsedUri;

const ftpOpts = {
host: hostname,
Expand Down Expand Up @@ -140,20 +140,20 @@ async function uploadFile (localPath, remoteUri, uploadOptions = {}) {
isMetered = true,
} = uploadOptions;

const remoteUrl = url.parse(remoteUri);
const parsedUri = url.parse(remoteUri);
const {size} = await fs.stat(localPath);
if (isMetered) {
log.info(`Uploading '${localPath}' of ${toReadableSizeString(size)} size to '${remoteUri}'...`);
}
const timer = new Timer().start();
if (['http:', 'https:'].includes(remoteUrl.protocol)) {
await uploadFileToHttp(fs.createReadStream(localPath), remoteUrl, uploadOptions);
} else if (remoteUrl.protocol === 'ftp:') {
await uploadFileToFtp(fs.createReadStream(localPath), remoteUrl, uploadOptions);
if (['http:', 'https:'].includes(parsedUri.protocol)) {
await uploadFileToHttp(fs.createReadStream(localPath), parsedUri, uploadOptions);
} else if (parsedUri.protocol === 'ftp:') {
await uploadFileToFtp(fs.createReadStream(localPath), parsedUri, uploadOptions);
} else {
throw new Error(`Cannot upload the file at '${localPath}' to '${remoteUri}'. ` +
`Unsupported remote protocol '${remoteUrl.protocol}'. ` +
`Only http/https and ftp/ftps protocols are supported.`);
`Unsupported remote protocol '${parsedUri.protocol}'. ` +
`Only http/https and ftp/ftps protocols are supported.`);
}
if (isMetered) {
log.info(`Uploaded '${localPath}' of ${toReadableSizeString(size)} size in ${timer.getDuration().asSeconds.toFixed(3)}s`);
Expand Down

0 comments on commit 46b2fb4

Please sign in to comment.