Skip to content

Commit

Permalink
Allow custom archives config on local node
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTaelin committed Jul 13, 2017
1 parent 3360c17 commit 9269757
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swarm-js",
"version": "0.1.19",
"version": "0.1.20",
"description": "Swarm tools for JavaScript.",
"main": "lib/swarm.js",
"scripts": {
Expand Down
15 changes: 10 additions & 5 deletions src/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const mimetype = require('mimetype');
const pick = require("./pick.js");
const request = require("xhr-request-promise");
const downloadUrl = "http://ethereum-mist.s3.amazonaws.com/swarm/";
const archives = require("./../archives/archives.json");
const defaultArchives = require("./../archives/archives.json");

// ∀ a . String -> JSON -> Map String a -o Map String a
// Inserts a key/val pair in an object impurely.
Expand Down Expand Up @@ -238,10 +238,10 @@ const download = swarmUrl => hash => path =>
// Downloads the Swarm binaries into a path. Returns a promise that only
// resolves when the exact Swarm file is there, and verified to be correct.
// If it was already there to begin with, skips the download.
const downloadBinary = path => {
const downloadBinary = (path, archives) => {
const os = require("o"+"s");
const system = os.platform().replace("win32","windows") + "-" + (os.arch() === "x64" ? "amd64" : "386");
const archive = archives[system];
const archive = (archives || defaultArchives)[system];
const archiveUrl = downloadUrl + archive.archive + ".tar.gz";
const archiveMD5 = archive.archiveMD5;
const binaryMD5 = archive.binaryMD5;
Expand All @@ -254,7 +254,12 @@ const downloadBinary = path => {
// dataDir : String,
// binPath : String,
// ethApi : String,
// onDownloadProgress : Number ~> ()
// onDownloadProgress : Number ~> (),
// archives : [{
// archive: String,
// binaryMD5: String,
// archiveMD5: String
// }]
// }

// SwarmSetup ~> Promise Process
Expand Down Expand Up @@ -335,7 +340,7 @@ const local = swarmSetup => useAPI =>
isAvailable("http://localhost:8500").then(isAvailable =>
isAvailable
? useAPI(at("http://localhost:8500")).then(() => {})
: downloadBinary(swarmSetup.binPath)
: downloadBinary(swarmSetup.binPath, swarmSetup.archives)
.onData(data => (swarmSetup.onProgress || (() => {}))(data.length))
.then(() => startProcess(swarmSetup))
.then(process => useAPI(at("http://localhost:8500")).then(() => process))
Expand Down

0 comments on commit 9269757

Please sign in to comment.