alexandria-core
Advanced tools
Comparing version 1.0.1 to 1.0.2
82
index.js
import axios from 'axios'; | ||
import IPFS_MAIN from 'ipfs' | ||
const ipfs = new IPFS_MAIN() | ||
try { | ||
var IPFS_MAIN = require('ipfs'); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
let AlexandriaCore = (function(){ | ||
@@ -9,7 +13,12 @@ let Core = {}; | ||
// Initiate all instances | ||
Core.ipfs = new IPFS_MAIN(); | ||
try { | ||
Core.ipfs = new IPFS_MAIN(); | ||
} catch (e) { | ||
Core.ipfs = "not-supported" | ||
} | ||
// Define all of the application URLS | ||
Core.OIPdURL = "https://api.alexandria.io/alexandria/v2"; | ||
Core.IPFSGatewayURL = "https://gateway.ipfs.io/ipfs/"; | ||
Core.IPFSGatewayURL = "http://gateway.ipfs.io/ipfs/"; | ||
@@ -119,2 +128,6 @@ // Define URLS for things we don't control, these likely will change often | ||
if (!type){ | ||
type = Core.Artifact.getType(oip); | ||
} | ||
for (let i = 0; i < files.length; i++){ | ||
@@ -126,3 +139,9 @@ if (files[i].type === type && !mainFile){ | ||
return mainFile; | ||
let fileURL = ""; | ||
if (mainFile){ | ||
fileURL = location + "/" + mainFile.fname; | ||
} | ||
return fileURL; | ||
} | ||
@@ -392,26 +411,30 @@ | ||
Core.ipfs.files.cat(hash, function (err, file) { | ||
if (err){ | ||
console.log(err); | ||
return; | ||
} | ||
onData(Core.util.buildIPFSURL(hash)); | ||
let stream = file; | ||
let chunks = []; | ||
if (stream){ | ||
stream.on('data', function(chunk) { | ||
chunks.push(chunk); | ||
try { | ||
Core.ipfs.files.cat(hash, function (err, file) { | ||
if (err){ | ||
console.log(err); | ||
return; | ||
} | ||
// Note, this might cause tons of lag depending on how many ongoing IPFS requests we have. | ||
Core.util.chunksToFileURL(chunks, function(data){ | ||
onData(data); | ||
let stream = file; | ||
let chunks = []; | ||
if (stream){ | ||
stream.on('data', function(chunk) { | ||
chunks.push(chunk); | ||
// Note, this might cause tons of lag depending on how many ongoing IPFS requests we have. | ||
Core.util.chunksToFileURL(chunks, function(data){ | ||
onData(data); | ||
}) | ||
}); | ||
stream.on('end', function(){ | ||
// Core.util.chunksToFileURL(chunks, function(data){ | ||
// onData(data); | ||
// }) | ||
}) | ||
}); | ||
stream.on('end', function(){ | ||
// Core.util.chunksToFileURL(chunks, function(data){ | ||
// onData(data); | ||
// }) | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
} catch (e){ } | ||
} | ||
@@ -464,3 +487,8 @@ | ||
if (!fname){ | ||
trailURL = hash; | ||
let parts = hash.split('/'); | ||
if (parts.length == 2){ | ||
trailURL = parts[0] + "/" + encodeURIComponent(parts[1]); | ||
} else { | ||
trailURL = hash; | ||
} | ||
} else { | ||
@@ -467,0 +495,0 @@ trailURL = hash + "/" + encodeURIComponent(fname); |
{ | ||
"name": "alexandria-core", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "The core module of Alexandria!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19360
410