mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Made progress bar for github mod downloads
This commit is contained in:
1 parent
29bffa472b
commit
1fcd91342f
2 files changed
+13
-1
No files matched your search
@@ -10,6 +10,7 @@ const syncRequest = require("sync-request");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const https = require('follow-redirects').https;
|
const https = require('follow-redirects').https;
|
||||||
const factorioAPI = require("node-factorio-api");
|
const factorioAPI = require("node-factorio-api");
|
||||||
|
const sLog = require("single-line-log").stdout;
|
||||||
|
|
||||||
const fileOps = require("./../fileOps.js");
|
const fileOps = require("./../fileOps.js");
|
||||||
const config = require("./../../config");
|
const config = require("./../../config");
|
||||||
@@ -19,6 +20,8 @@ const instances = require("./../getInstances.js").sync();
|
|||||||
function ellipse(str, max){
|
function ellipse(str, max){
|
||||||
return str.length > (max - 3) ? str.substring(0,max-3) + '...' : str;
|
return str.length > (max - 3) ? str.substring(0,max-3) + '...' : str;
|
||||||
}
|
}
|
||||||
|
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
|
||||||
|
function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Lists mods for an instance as a table. Warning, handles printing internally.
|
Lists mods for an instance as a table. Warning, handles printing internally.
|
||||||
@@ -68,6 +71,7 @@ module.exports.listMods = function(instance){
|
|||||||
token: config.token,
|
token: config.token,
|
||||||
require_ownership: false
|
require_ownership: false
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
console.log("\r\n")
|
||||||
console.log("* Mods shared by all instances:")
|
console.log("* Mods shared by all instances:")
|
||||||
factorioAPI.getInstalledMods().then(mods => {
|
factorioAPI.getInstalledMods().then(mods => {
|
||||||
console.log(asTable(mods));
|
console.log(asTable(mods));
|
||||||
@@ -142,9 +146,16 @@ module.exports.addMod = function(term, instance){
|
|||||||
if(url) {
|
if(url) {
|
||||||
console.log("Downloading " + url);
|
console.log("Downloading " + url);
|
||||||
let file = fs.createWriteStream(modDirectory + name);
|
let file = fs.createWriteStream(modDirectory + name);
|
||||||
|
let bytesDownloaded = 0;
|
||||||
https.get(url, function(response) {
|
https.get(url, function(response) {
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
console.log("Downloaded "+name);
|
response.on("data", chunk => {
|
||||||
|
bytesDownloaded += chunk.length;
|
||||||
|
sLog("Downloading "+name+": "+formatBytes(bytesDownloaded));
|
||||||
|
}).on("end", x => {
|
||||||
|
sLog.clear();
|
||||||
|
console.log(""); // because sLog.clear() doesn't seem to do the job of ending the line properly
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
"right-pad": "^1.0.1",
|
"right-pad": "^1.0.1",
|
||||||
"rmdir-sync": "^1.0.1",
|
"rmdir-sync": "^1.0.1",
|
||||||
"simple-rcon": "^0.3.1",
|
"simple-rcon": "^0.3.1",
|
||||||
|
"single-line-log": "^1.1.2",
|
||||||
"socket.io": "^2.0.4",
|
"socket.io": "^2.0.4",
|
||||||
"socket.io-client": "^2.0.4",
|
"socket.io-client": "^2.0.4",
|
||||||
"sync-request": "^4.0.1",
|
"sync-request": "^4.0.1",
|
||||||
|
|||||||
Reference in new issue
Block a user