Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 11 additions & 42 deletions lib/streamer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node
const stream = require('stream');
const got = require('got');
const ProgressBar = require('progress');
const {promisify} = require('util');
import stream from 'stream';
import got from 'got';
import ProgressBar from 'progress';
import { promisify } from 'util';
const pipeline = promisify(stream.pipeline);

// colours
const chalk = require('chalk');
import chalk from 'chalk';

const red = chalk.bold.red;
const orange = chalk.keyword('orange');
const green = chalk.green;
const blue = chalk.blueBright;

module.exports = class vmwClient {
export default class vmwClient {
constructor(options) {
this.options = options;
// setup stuff
Expand All @@ -35,46 +35,15 @@ module.exports = class vmwClient {
.on('response', (response) => {
//console.log('FIRST RESPONSE');
})
.on('downloadProgress', (progress) => {
//let rate = Math.round(bar.curr / ((new Date - bar.start) / 1000) / 1000);
if(progress.total) { // handle no content-header
if(typeof(bar) == 'undefined') {
let totalBytes = progress.total;
let total = parseInt(totalBytes / 1024 * 100) / 100; // get KB
while(total > 99.99) { // scale up
label++;
total = parseInt(total / 1024 * 100) / 100;
}
bar = new ProgressBar(blue(fileName) + ' [' + green(':bar') + '] :percent | :etas | :curr/' + pad(total) + ' ' + labels[label], {
complete: '\u25A0',
head: '\u25A0',
incomplete: ' ',
width: 50,
renderThrottle: 500,
total: totalBytes
});
} else {
let chunk = progress.transferred - prevTrans;
prevTrans = progress.transferred;
current = progress.transferred;
for(let i = 0; i <= label; i++) {
current = parseInt(current / 1024 * 100) / 100;
}
bar.tick(chunk, {
'curr': pad(current)
});
}
}
.on('downloadProgress', (progress) => {console.log(progress);
}),
dstStream
.on('finish', () => {
if(!bar.complete) {
bar.update(1);
}
//console.log('FINISHS RESPONSE');
})
);
}
}
};

// pad/truncate zeros to left and right of number
function pad(num) {
Expand All @@ -86,4 +55,4 @@ function pad(num) {
}
return left + '.' + m[2];
}
};
}
29 changes: 16 additions & 13 deletions lib/vmw.api.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node
'use strict';
const vmwClient = require('vmw-sdk');
const streamer = require('./streamer');
const fs = require('fs');
const CookieFileStore = require('tough-cookie-file-store').FileCookieStore;
const {CookieJar} = require('tough-cookie');
import vmwClient from 'vmw-sdk';
import streamer from './streamer.js';
import fs from 'fs';
import { FileCookieStore as CookieFileStore } from 'tough-cookie-file-store';
import { CookieJar } from 'tough-cookie';

//import pMap from 'p-map'; // not set up yet for ESM
const pMap = require('p-map');
const storage = require('node-persist');
import pMap from 'p-map';

import storage from 'node-persist';

// provides a higher order interface on top of vmw.sdk.js
// handles auth/session persistence
Expand All @@ -19,13 +21,13 @@ const storage = require('node-persist');
// ignore self-signed certificate
//process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
// colours
const chalk = require('chalk');
import chalk from 'chalk';

const red = chalk.bold.red;
const orange = chalk.keyword('orange');
const green = chalk.green;
const blue = chalk.blueBright;

module.exports = class vmwApi {
export default class vmwApi {
constructor(options = {}) {
this.username = options.username;
this.password = options.password;
Expand Down Expand Up @@ -64,6 +66,7 @@ module.exports = class vmwApi {
});
}), {concurrency: 8})).flat(1);
fs.writeFileSync(this.statedir + '/fileList.json', JSON.stringify(data, null, "\t"), 'utf8');
console.log(data)
return data;
} catch(error) {
throw new Error(error.message);
Expand Down Expand Up @@ -91,7 +94,7 @@ module.exports = class vmwApi {
// attempt accountInfo
try {
if(fs.existsSync(this.statedir + '/headers.json')) {
let headers = require(this.statedir + '/headers.json');
let headers = JSON.parse(fs.readFileSync(this.statedir + '/headers.json', 'utf8'));
this.client.client = this.client.base.extend({
prefixUrl: 'https://customerconnect.vmware.com/',
headers
Expand Down Expand Up @@ -246,7 +249,7 @@ module.exports = class vmwApi {

// load fileList and retrieve file details
if(fs.existsSync(this.statedir + '/fileList.json')) {
let data = require(this.statedir + '/fileList.json');
let data = JSON.parse(fs.readFileSync(this.statedir + '/fileList.json', 'utf8'));
let details = data.filter((file) => {
return (file.fileName == fileName);
})[0];
Expand Down Expand Up @@ -281,4 +284,4 @@ module.exports = class vmwApi {
throw new Error('[' + red('ERROR') + ']: No files cached, please use ' + blue('ls <category>') + ' to view');
}
}
}
};
61 changes: 14 additions & 47 deletions lib/vmw.cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env node
'use strict';
const vmwClient = require('./vmw.api');
const streamer = require('./streamer');
const fs = require('fs');
const xtable = require('./xtable');
const md5File = require('md5-file');

import vmwClient from './vmw.api.js';
import streamer from './streamer.js';
import fs from 'fs';
import md5File from 'md5-file';
import path from 'path';

/* Module Purpose
To provide a cli interface for the vmw-api module.
Expand All @@ -21,7 +22,7 @@ Handle client IO unrelated to the VMW-API interface
var username = process.env.VMWUSER;
var password = process.env.VMWPASS;
var filesdir = process.cwd();
var statedir = __dirname;
var statedir = process.cwd();
if(process.env.VMWFILESDIR) {
filesdir = process.env.VMWFILESDIR;
}
Expand All @@ -30,9 +31,9 @@ if(process.env.VMWSTATEDIR) {
}

// colours
const chalk = require('chalk');
import chalk from 'chalk';

const red = chalk.bold.red;
const orange = chalk.keyword('orange');
const green = chalk.green;
const blue = chalk.blueBright;

Expand Down Expand Up @@ -84,21 +85,7 @@ if(process.argv[1].match(/vmw.cli/g)) {

// main
async function main(category, version, type) {
client.main(category, version, type).then((data) => {
let table = new xtable({data});
table.run();
table.out([
'fileName',
'fileType',
'version',
'releaseDate',
'fileSize',
'canDownload'
]);
}).catch((error) => {
//console.log('[CLI-ERROR]: ' + error.message);
console.log(error.message);
});
client.main(category, version, type)
}

// list
Expand Down Expand Up @@ -132,16 +119,7 @@ async function cmdPath(string) {
} else {
//console.log('Training Slash!! - call VERSIONS: ' + path[0]);
let result = await client.getProductVersions(path[0]);
let table = new xtable({
data: result.versions
});
table.run();
table.out([
'id',
'name',
'slugUrl',
'isSelected'
]);
console.log(result.versions)
}
} else if(path.length == 3) {
if(path[2].length > 0) {
Expand All @@ -156,9 +134,7 @@ async function cmdPath(string) {
{id: 'CUSTOM_ISO'},
{id: 'ADDONS'}
];
let table = new xtable({data});
table.run();
table.out(['id']);
console.log(data)
}
} else {
console.log('INVALID PATH');
Expand All @@ -183,17 +159,8 @@ async function cmdGet(fileName) { // broken, fix
async function cmdFile() {
// load fileList and retrieve file details
if(fs.existsSync(statedir + '/fileList.json')) {
let data = require(statedir + '/fileList.json');
let table = new xtable({data});
table.run();
table.out([
'fileName',
'fileType',
'version',
'releaseDate',
'fileSize',
'canDownload'
]);
let data = JSON.parse(fs.readFileSync(statedir + '/fileList.json', 'utf8'));
console.log(data)
}
}

48 changes: 0 additions & 48 deletions lib/xcell.js

This file was deleted.

Loading