Skip to content

Commit

Permalink
first changes for dpack in browser (#51)
Browse files Browse the repository at this point in the history
Co-authored-by: stobiewan <getsforwarded@gmail.com>
  • Loading branch information
stobiewan and stobiewan committed Apr 8, 2022
1 parent ba63b12 commit 16a68b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions dist/src/ipfs-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ exports.__esModule = true;
exports.isCid = exports.isV0CID = exports.pinIpfsCid = exports.putIpfsJson = exports.getIpfsJson = void 0;
var debug = require('debug')('dpack');
var IPFS = require('ipfs-http-client');
var nodeAddress = (_a = process.env["IPFS_RPC_URL"]) !== null && _a !== void 0 ? _a : '/ip4/127.0.0.1/tcp/5001';
var nodeAddress = '/ip4/127.0.0.1/tcp/5001';
try {
nodeAddress = (_a = process.env["IPFS_RPC_URL"]) !== null && _a !== void 0 ? _a : '/ip4/127.0.0.1/tcp/5001';
}
catch (_b) { }
debug("starting node ".concat(nodeAddress));
var node = IPFS.create(nodeAddress);
debug('started node');
function getIpfsJson(cid) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function () {
var blob, s, blob_1, blob_1_1, chunk, e_1_1;
var blob, s, utf8decoder, blob_1, blob_1_1, chunk, e_1_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
Expand All @@ -65,6 +69,7 @@ function getIpfsJson(cid) {
case 1:
blob = _b.sent();
s = '';
utf8decoder = new TextDecoder();
_b.label = 2;
case 2:
_b.trys.push([2, 7, 8, 13]);
Expand All @@ -74,7 +79,7 @@ function getIpfsJson(cid) {
case 4:
if (!(blob_1_1 = _b.sent(), !blob_1_1.done)) return [3 /*break*/, 6];
chunk = blob_1_1.value;
s += chunk;
s += utf8decoder.decode(chunk);
_b.label = 5;
case 5: return [3 /*break*/, 3];
case 6: return [3 /*break*/, 13];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherpacks/dpack",
"version": "0.0.28",
"version": "0.0.29",
"author": "nikolai mushegian <mail@nikolai.fyi>",
"license": "GPL-3.0",
"main": "./dist/index.js",
Expand Down
8 changes: 6 additions & 2 deletions src/ipfs-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const debug = require('debug')('dpack')

const IPFS = require('ipfs-http-client')

const nodeAddress = process.env["IPFS_RPC_URL"] ?? '/ip4/127.0.0.1/tcp/5001'
let nodeAddress = '/ip4/127.0.0.1/tcp/5001'
try {
nodeAddress = process.env["IPFS_RPC_URL"] ?? '/ip4/127.0.0.1/tcp/5001'
} catch {}
debug(`starting node ${nodeAddress}`)
const node = IPFS.create(nodeAddress)
debug('started node')
Expand All @@ -16,8 +19,9 @@ Please repack the pack containing ${cid}
}
const blob = await node.cat(cid)
let s = ''
let utf8decoder = new TextDecoder()
for await (const chunk of blob) {
s += chunk
s += utf8decoder.decode(chunk)
}
return JSON.parse(s)
}
Expand Down

0 comments on commit 16a68b5

Please sign in to comment.