代码拉取完成,页面将自动刷新
const https = require('follow-redirects').https;
const fs = require("fs");
const URL = require("url");
const path = require("path");
console.log("Fetching ccurl dependencies...");;
var paths = ["ccurl", "ccurl/win64", "ccurl/lin64", "ccurl/mac"];
for (var i=0; i<paths.length; i++) {
if (!fs.existsSync(paths[i])) {
fs.mkdirSync(paths[i]);
}
}
var req = https.get({"host" : "api.github.com",
"path" : "/repos/iotaledger/ccurl/releases/latest",
"headers" : {"User-Agent": "IOTA Wallet"}}, function(res) {
if (res.statusCode !== 200) {
throw ("HTTP Error: " + response.statusCode);
}
var body = "";
res.on("data", function(chunk) {
body += chunk;
});
res.on("end", function() {
try {
var latestRelease = JSON.parse(body);
var downloads = [];
if (latestRelease.assets) {
for (var i=0; i<latestRelease.assets.length; i++) {
var asset = latestRelease.assets[i];
if (asset.name == "libccurl.so") {
downloads.push({"target": "lin64", "url": asset.browser_download_url, "filename": "libccurl.so"});
} else if (asset.name == "ccurl.dll") {
downloads.push({"target": "win64", "url": asset.browser_download_url, "filename": "libccurl.dll"});
} else if (asset.name == "libccurl.dylib") {
downloads.push({"target": "mac", "url": asset.browser_download_url, "filename": "libccurl.dylib"});
}
}
}
if (downloads.length != 3) {
throw("Could not find ccurl dependencies.");
}
var downloaded = 0;
for (var i=0; i<downloads.length; i++) {
download(downloads[i].url, path.join("ccurl", downloads[i].target, downloads[i].filename), function(err) {
if (err) {
throw(err);
} else {
downloaded++;
if (downloaded == 3) {
console.log("All ccurl dependencies have been downloaded.");
}
}
});
}
} catch (err) {
throw(err);
}
});
}).on("error", function(err) {
throw(err);
});
req.end();
var download = function(url, dest, cb) {
var parsed = URL.parse(url);
var file = fs.createWriteStream(dest);
var req = https.get({"host" : parsed.host,
"path" : parsed.path,
"headers": {"user-agent": "IOTA Wallet", "Accept": "application/octet-stream"}}, function(response) {
response.pipe(file);
file.on("finish", function() {
file.close(cb);
});
}).on("error", function(err) {
fs.unlink(dest);
if (cb) cb(err.message);
});
req.end();
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。