Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bambu-cli

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bambu-cli - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

lib/ftp.js

5

bin/cli.js

@@ -15,2 +15,3 @@ #!/usr/bin/env node

.describe('download', 'Download a file, optional set output path [--download=/foo]')
.describe('delete', 'Delete a file, optional use --filter to limit to a single file')
.describe('file', 'The file to work with')

@@ -20,7 +21,9 @@ .describe('filter', 'Filter files by name')

.describe('parse', 'Parse a 3mf file after download')
.describe('yes', 'Auto select YES when prompted')
.command('config', 'Show config (for bambu-farm)')
.command('files', 'Show files on machine [--id] [--filter] [--download] [--parse]')
.command('files', 'Show gcode files on machine [--id] [--filter] [--download] [--parse] [--delete] [--yes]')
.command('login', 'Login and fetch machine information')
.command('ls', 'Alias for machines')
.command('machines', 'List current known machines')
.command('timelapse', 'Show video files on machine [--id] [--filter] [--download] [--delete] [--yes]')
.command('parse', 'Parse details from a .3mf file [--file]')

@@ -27,0 +30,0 @@ .command('status', 'Check machine connectivity [--id to get detailed info]')

1

lib/commands.js

@@ -33,3 +33,4 @@ const cfg = require('./config.js');

module.exports.files = require('./files.js');
module.exports.timelapse = require('./timelapse.js');
module.exports.parse = require('./parse.js');

@@ -58,1 +58,15 @@ const fs = require('fs');

module.exports.remove = removeConfig;
const getMachine = (id) => {
const machines = config.machines;
let machine = null;
if (machines && Array.isArray(machines)) {
machines.forEach(_m => {
if (_m.id === id) {
machine = _m;
}
});
}
return machine;
};
module.exports.getMachine = getMachine;

@@ -1,155 +0,52 @@

const Table = require('easy-table');
const ftp = require('basic-ftp');
const pretty = require('prettysize');
const fs = require('fs');
const path = require('path');
const ProgressBar = require('progress');
const os = require('os');
const fs = require('fs');
const ftp = require('./ftp.js');
const parse = require('./parse.js');
const cfg = require('./config.js');
module.exports = async(args) => {
//console.log(args);
let filter = args.filter;
if (filter === true) {
filter = null;
const machine = cfg.getMachine(args.id);
const typeCheck = (name) => {
return (name.indexOf('.gcode') > -1 && !name.startsWith('.'));
};
if (args.parse) {
args.download = os.tmpdir();
}
const machines = cfg.get('machines');
let machine;
machines.forEach(_m => {
if (_m.id === args.id) {
machine = _m;
await ftp.tableView(machine, '/', typeCheck, args, (opts) => {
if (opts.table) {
if (opts.count) {
console.log(opts.table);
} else {
console.log(`No files found!`);
}
}
});
if (!machine) {
console.error(`Failed to find machine: ${args.id}`);
process.exit(2);
}
//console.log(`Fetching files for ${args.id}`);
const files = await listFTP(machine, '/');
const table = new Table();
files.sort((a, b) => {
const file1 = a.name.toLowerCase();
const file2 = b.name.toLowerCase();
if (file1 > file2) {
return 1;
}
return -1;
});
const list = [];
let count = 0;
files.forEach((f) => {
if (f.name.indexOf('.gcode') > -1 && !f.name.startsWith('.')) {
if (filter) {
if (f.name.toLowerCase().indexOf(filter.toLowerCase()) === -1) {
if (opts.downloaded && args.parse) {
const parseFile = () => {
let file;
if (files.length) {
file = files.pop();
} else {
return;
}
}
count++;
list.push({ file: f.name, size: f.size });
table.cell('Name', f.name);
table.cell('Date', f.rawModifiedAt);
table.cell('Size', f.size, (s) => { return pretty(s); });
table.newRow();
}
});
table.total('Name', {
printer: Table.aggr.printer('# of Files: ', () => { return count; }),
init: 0
});
table.total('Size', {
printer: Table.aggr.printer('Total: ', pretty),
init: 0
});
if (count === 1 && (args.download || args.parse)) {
if (args.download === true) {
args.download = './';
}
if (args.parse) {
args.download = os.tmpdir();
}
const remote = `/${list[0].file}`;
const local = path.resolve(args.download, list[0].file);
console.log(`Downloading `, list[0].file, 'to', args.download);
//console.log('remote:', remote);
//console.log('local:', local);
await downloadFile(machine, remote, local, list[0].size);
if (args.parse) {
parse({
file: file
}, () => {
console.log(`Cleaning up tmpfile:`, file);
fs.rmSync(file);
parseFile();
});
};
console.log();
parse({
file: local
}, () => {
console.log(`Cleaing up tmpfile:`, local);
fs.rmSync(local);
const files = [];
opts.remote.forEach(f => {
const p = path.join(args.download, f.file);
files.push(p);
});
parseFile();
}
} else {
console.log(table.toString());
}
});
};
const downloadFile = async(machine, remote, local, size) => {
const client = new ftp.Client();
let trans = 0;
const bar = new ProgressBar(' downloading [:bar] :pcurrent of :ptotal :percent :etas', {
complete: '=',
incomplete: ' ',
width: 100,
total: size
});
client.trackProgress(info => {
let bytes = info.bytes;
if (bytes === 0) {
return;
}
bar.tick(bytes - trans, {
pcurrent: pretty(bytes).replace(' ', ''),
ptotal: pretty(size).replace(' ', '')
});
trans = bytes;
});
const secureOptions = {
checkServerIdentity: () => { return null; },
rejectUnauthorized: false //Needed for the Self Signed Cert
};
try {
await client.access({
host: machine.ip,
user: 'bblp',
password: machine.token,
port: 990,
secure: 'implicit',
secureOptions: secureOptions
});
await client.downloadTo(local, remote);
await client.close();
} catch (e) {
return false;
}
};
const listFTP = async(machine, dir) => {
const client = new ftp.Client();
const secureOptions = {
checkServerIdentity: () => { return null; },
rejectUnauthorized: false //Needed for the Self Signed Cert
};
try {
await client.access({
host: machine.ip,
user: 'bblp',
password: machine.token,
port: 990,
secure: 'implicit',
secureOptions: secureOptions
});
const list = await client.list(dir);
await client.close();
return list;
} catch (e) {
return [];
}
};
const cfg = require('./config.js');
const Table = require('easy-table');
const ftp = require('basic-ftp');
const mqtt = require('mqtt');

@@ -9,2 +8,4 @@ const chalk = require('chalk');

const ftp = require('./ftp.js');
const CONSTS = require('./const.js');

@@ -15,3 +16,3 @@

const status = (value) => {
return chalk.bold((value) ? chalk.green(`✔`) : chalk.red(`✘`));
return ' ' + chalk.bold((value) ? chalk.green(`✔`) : chalk.red(`✘`));
};

@@ -84,4 +85,4 @@

const len = str.length;
if (len > 25) {
str = `${str.substr(0, 25)} ...`;
if (len > 20) {
str = `${str.substr(0, 20)} ...`;
}

@@ -286,3 +287,3 @@ return str;

.replace(', 0 seconds', '')
.replace('s', '')
.replace('econds', '')
.replace('ours', '')

@@ -309,16 +310,4 @@ .replace('our', '')

const checkFTP = async(machine) => {
const client = new ftp.Client();
const secureOptions = {
checkServerIdentity: () => { return null; },
rejectUnauthorized: false //Needed for the Self Signed Cert
};
const client = await ftp.makeClient(machine);
try {
await client.access({
host: machine.ip,
user: 'bblp',
password: machine.token,
port: 990,
secure: 'implicit',
secureOptions: secureOptions
});
const list = await client.list('/');

@@ -325,0 +314,0 @@ await client.close();

{
"name": "bambu-cli",
"version": "1.0.9",
"version": "1.0.10",
"description": "Bambulabs CLI for printers",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc