From 818560578346d33feb71806bf966c5c87f5be55e Mon Sep 17 00:00:00 2001 From: Mitra Ardron Date: Sun, 10 Jun 2018 18:16:35 -0700 Subject: [PATCH] Compile, update npm & deploy --- dist/dweb-transports-bundle.js | 6 +++--- package-lock.json | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/dweb-transports-bundle.js b/dist/dweb-transports-bundle.js index 931c619..1d32907 100644 --- a/dist/dweb-transports-bundle.js +++ b/dist/dweb-transports-bundle.js @@ -766,7 +766,7 @@ eval("const Url = __webpack_require__(/*! url */ \"../../../../usr/local/lib/nod /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("/* WEBPACK VAR INJECTION */(function(Buffer) {const nodefetch = __webpack_require__(/*! node-fetch */ 2); // Note, were using node-fetch-npm which had a warning in webpack see https://github.com/bitinn/node-fetch/issues/421 and is intended for clients\nconst errors = __webpack_require__(/*! ./Errors */ \"./Errors.js\"); // Standard Dweb Errors\n\n//var fetch,Headers,Request;\n//if (typeof(Window) === \"undefined\") {\nif (typeof(fetch) === \"undefined\") {\n //var fetch = require('whatwg-fetch').fetch; //Not as good as node-fetch-npm, but might be the polyfill needed for browser.safari\n //XMLHttpRequest = require(\"xmlhttprequest\").XMLHttpRequest; // Note this doesnt work if set to a var or const, needed by whatwg-fetch\n fetch = nodefetch;\n Headers = fetch.Headers; // A class\n Request = fetch.Request; // A class\n} /* else {\n // If on a browser, need to find fetch,Headers,Request in window\n console.log(\"Loading browser version of fetch,Headers,Request\");\n fetch = window.fetch;\n Headers = window.Headers;\n Request = window.Request;\n} */\n//TODO-HTTP to work on Safari or mobile will require a polyfill, see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch for comment\n\n\nhttptools = {};\n\nasync function loopfetch(req, ms, count, what) {\n let lasterr;\n while (count--) {\n try {\n return await fetch(req);\n } catch(err) {\n lasterr = err;\n console.log(\"Delaying\", what,\"by\", ms, \"because\", err.message);\n await new Promise(resolve => {setTimeout(() => { resolve(); },ms)})\n ms = ms*(1+Math.random()); // Spread out delays incase all requesting same time\n }\n }\n console.log(\"Looping\",what,\"failed\");\n throw(lasterr);\n}\n\nhttptools.p_httpfetch = async function(httpurl, init, verbose) { // Embrace and extend \"fetch\" to check result etc.\n /*\n Fetch a url\n\n url: optional (depends on command)\n resolves to: data as text or json depending on Content-Type header\n throws: TransportError if fails to fetch\n */\n try {\n if (verbose) console.log(\"httpurl=%s init=%o\", httpurl, init);\n //console.log('CTX=',init[\"headers\"].get('Content-Type'))\n // Using window.fetch, because it doesn't appear to be in scope otherwise in the browser.\n let req = new Request(httpurl, init);\n //let response = await fetch(new Request(httpurl, init)).catch(err => console.exception(err));\n let response = await loopfetch(req, 500, 10, \"fetching \"+httpurl);\n // fetch throws (on Chrome, untested on Firefox or Node) TypeError: Failed to fetch)\n // Note response.body gets a stream and response.blob gets a blob and response.arrayBuffer gets a buffer.\n if (response.ok) {\n let contenttype = response.headers.get('Content-Type');\n if (contenttype === \"application/json\") {\n return response.json(); // promise resolving to JSON\n } else if (contenttype.startsWith(\"text\")) { // Note in particular this is used for responses to store\n return response.text();\n } else { // Typically application/octetStream when don't know what fetching\n return new Buffer(await response.arrayBuffer()); // Convert arrayBuffer to Buffer which is much more usable currently\n }\n }\n // noinspection ExceptionCaughtLocallyJS\n throw new errors.TransportError(`Transport Error ${response.status}: ${response.statusText}`);\n } catch (err) {\n // Error here is particularly unhelpful - if rejected during the COrs process it throws a TypeError\n console.log(\"Note error from fetch might be misleading especially TypeError can be Cors issue:\",httpurl);\n if (err instanceof errors.TransportError) {\n throw err;\n } else {\n throw new errors.TransportError(`Transport error thrown by ${httpurl}: ${err.message}`);\n }\n }\n}\n\n\nhttptools.p_GET = async function(httpurl, opts={}) {\n /* Locate and return a block, based on its url\n Throws TransportError if fails\n opts {\n start, end, // Range of bytes wanted - inclusive i.e. 0,1023 is 1024 bytes\n verbose }\n resolves to: URL that can be used to fetch the resource, of form contenthash:/contenthash/Q123\n */\n let headers = new Headers();\n if (opts.start || opts.end) headers.append(\"range\", `bytes=${opts.start || 0}-${opts.end || \"\"}`);\n let init = { //https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch\n method: 'GET',\n headers: headers,\n mode: 'cors',\n cache: 'default',\n redirect: 'follow', // Chrome defaults to manual\n keepalive: true // Keep alive - mostly we'll be going back to same places a lot\n };\n return await httptools.p_httpfetch(httpurl, init, opts.verbose); // This s a real http url\n}\nhttptools.p_POST = async function(httpurl, type, data, verbose) {\n // Locate and return a block, based on its url\n // Throws TransportError if fails\n //let headers = new window.Headers();\n //headers.set('content-type',type); Doesn't work, it ignores it\n let init = {\n //https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch\n //https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name for headers tat cant be set\n method: 'POST',\n headers: {}, //headers,\n //body: new Buffer(data),\n body: data,\n mode: 'cors',\n cache: 'default',\n redirect: 'follow', // Chrome defaults to manual\n keepalive: true // Keep alive - mostly we'll be going back to same places a lot\n };\n return await httptools.p_httpfetch(httpurl, init, verbose);\n}\n\nexports = module.exports = httptools;\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../../usr/local/lib/node_modules/webpack/node_modules/buffer/index.js */ \"../../../../usr/local/lib/node_modules/webpack/node_modules/buffer/index.js\").Buffer))\n\n//# sourceURL=webpack:///./httptools.js?"); +eval("/* WEBPACK VAR INJECTION */(function(Buffer) {const nodefetch = __webpack_require__(/*! node-fetch */ 2); // Note, were using node-fetch-npm which had a warning in webpack see https://github.com/bitinn/node-fetch/issues/421 and is intended for clients\nconst errors = __webpack_require__(/*! ./Errors */ \"./Errors.js\"); // Standard Dweb Errors\n\n//var fetch,Headers,Request;\n//if (typeof(Window) === \"undefined\") {\nif (typeof(fetch) === \"undefined\") {\n //var fetch = require('whatwg-fetch').fetch; //Not as good as node-fetch-npm, but might be the polyfill needed for browser.safari\n //XMLHttpRequest = require(\"xmlhttprequest\").XMLHttpRequest; // Note this doesnt work if set to a var or const, needed by whatwg-fetch\n fetch = nodefetch;\n Headers = fetch.Headers; // A class\n Request = fetch.Request; // A class\n} /* else {\n // If on a browser, need to find fetch,Headers,Request in window\n console.log(\"Loading browser version of fetch,Headers,Request\");\n fetch = window.fetch;\n Headers = window.Headers;\n Request = window.Request;\n} */\n//TODO-HTTP to work on Safari or mobile will require a polyfill, see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch for comment\n\n\nhttptools = {};\n\nasync function loopfetch(req, ms, count, what) {\n let lasterr;\n while (count--) {\n try {\n return await fetch(req);\n } catch(err) {\n lasterr = err;\n console.log(\"Delaying\", what,\"by\", ms, \"because\", err.message);\n await new Promise(resolve => {setTimeout(() => { resolve(); },ms)})\n ms = ms*(1+Math.random()); // Spread out delays incase all requesting same time\n }\n }\n console.log(\"Looping\",what,\"failed\");\n throw(lasterr);\n}\n\nhttptools.p_httpfetch = async function(httpurl, init, verbose) { // Embrace and extend \"fetch\" to check result etc.\n /*\n Fetch a url\n\n url: optional (depends on command)\n resolves to: data as text or json depending on Content-Type header\n throws: TransportError if fails to fetch\n */\n try {\n if (verbose) console.log(\"httpurl=%s init=%o\", httpurl, init);\n //console.log('CTX=',init[\"headers\"].get('Content-Type'))\n // Using window.fetch, because it doesn't appear to be in scope otherwise in the browser.\n let req = new Request(httpurl, init);\n //let response = await fetch(new Request(httpurl, init)).catch(err => console.exception(err));\n let response = await loopfetch(req, 500, 20, \"fetching \"+httpurl);\n // fetch throws (on Chrome, untested on Firefox or Node) TypeError: Failed to fetch)\n // Note response.body gets a stream and response.blob gets a blob and response.arrayBuffer gets a buffer.\n if (response.ok) {\n let contenttype = response.headers.get('Content-Type');\n if (contenttype === \"application/json\") {\n return response.json(); // promise resolving to JSON\n } else if (contenttype.startsWith(\"text\")) { // Note in particular this is used for responses to store\n return response.text();\n } else { // Typically application/octetStream when don't know what fetching\n return new Buffer(await response.arrayBuffer()); // Convert arrayBuffer to Buffer which is much more usable currently\n }\n }\n // noinspection ExceptionCaughtLocallyJS\n throw new errors.TransportError(`Transport Error ${response.status}: ${response.statusText}`);\n } catch (err) {\n // Error here is particularly unhelpful - if rejected during the COrs process it throws a TypeError\n console.log(\"Note error from fetch might be misleading especially TypeError can be Cors issue:\",httpurl);\n if (err instanceof errors.TransportError) {\n throw err;\n } else {\n throw new errors.TransportError(`Transport error thrown by ${httpurl}: ${err.message}`);\n }\n }\n}\n\n\nhttptools.p_GET = async function(httpurl, opts={}) {\n /* Locate and return a block, based on its url\n Throws TransportError if fails\n opts {\n start, end, // Range of bytes wanted - inclusive i.e. 0,1023 is 1024 bytes\n verbose }\n resolves to: URL that can be used to fetch the resource, of form contenthash:/contenthash/Q123\n */\n let headers = new Headers();\n if (opts.start || opts.end) headers.append(\"range\", `bytes=${opts.start || 0}-${opts.end || \"\"}`);\n let init = { //https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch\n method: 'GET',\n headers: headers,\n mode: 'cors',\n cache: 'default',\n redirect: 'follow', // Chrome defaults to manual\n keepalive: true // Keep alive - mostly we'll be going back to same places a lot\n };\n return await httptools.p_httpfetch(httpurl, init, opts.verbose); // This s a real http url\n}\nhttptools.p_POST = async function(httpurl, type, data, verbose) {\n // Locate and return a block, based on its url\n // Throws TransportError if fails\n //let headers = new window.Headers();\n //headers.set('content-type',type); Doesn't work, it ignores it\n let init = {\n //https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch\n //https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name for headers tat cant be set\n method: 'POST',\n headers: {}, //headers,\n //body: new Buffer(data),\n body: data,\n mode: 'cors',\n cache: 'default',\n redirect: 'follow', // Chrome defaults to manual\n keepalive: true // Keep alive - mostly we'll be going back to same places a lot\n };\n return await httptools.p_httpfetch(httpurl, init, verbose);\n}\n\nexports = module.exports = httptools;\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../../usr/local/lib/node_modules/webpack/node_modules/buffer/index.js */ \"../../../../usr/local/lib/node_modules/webpack/node_modules/buffer/index.js\").Buffer))\n\n//# sourceURL=webpack:///./httptools.js?"); /***/ }), @@ -5041,7 +5041,7 @@ eval("\n\nexports.importer = exports.Importer = __webpack_require__(/*! ./import /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nconst protons = __webpack_require__(/*! protons */ \"./node_modules/protons/src/index.js\")\nconst pb = protons(__webpack_require__(/*! ./unixfs.proto */ \"./node_modules/ipfs-unixfs/src/unixfs.proto.js\"))\n// encode/decode\nconst unixfsData = pb.Data\n// const unixfsMetadata = pb.MetaData // encode/decode\n\nconst types = [\n 'raw',\n 'directory',\n 'file',\n 'metadata',\n 'symlink',\n 'hamt-sharded-directory'\n]\n\nconst dirTypes = [\n 'directory',\n 'hamt-sharded-directory'\n]\n\nfunction Data (type, data) {\n if (!(this instanceof Data)) {\n return new Data(type, data)\n }\n if (types.indexOf(type) === -1) {\n throw new Error('Type: ' + type + ' is not valid')\n }\n\n this.type = type\n this.data = data\n this.blockSizes = []\n\n this.addBlockSize = (size) => {\n this.blockSizes.push(size)\n }\n\n this.removeBlockSize = (index) => {\n this.blockSizes.splice(index, 1)\n }\n\n // data.length + blockSizes\n this.fileSize = () => {\n if (dirTypes.indexOf(this.type) >= 0) {\n // dirs don't have file size\n return undefined\n }\n\n let sum = 0\n this.blockSizes.forEach((size) => {\n sum += size\n })\n if (data) {\n sum += data.length\n }\n return sum\n }\n\n // encode to protobuf\n this.marshal = () => {\n let type\n\n switch (this.type) {\n case 'raw': type = unixfsData.DataType.Raw; break\n case 'directory': type = unixfsData.DataType.Directory; break\n case 'file': type = unixfsData.DataType.File; break\n case 'metadata': type = unixfsData.DataType.Metadata; break\n case 'symlink': type = unixfsData.DataType.Symlink; break\n case 'hamt-sharded-directory': type = unixfsData.DataType.HAMTShard; break\n default:\n throw new Error(`Unkown type: \"${this.type}\"`)\n }\n let fileSize = this.fileSize()\n\n if (!fileSize) {\n fileSize = undefined\n }\n\n return unixfsData.encode({\n Type: type,\n Data: this.data,\n filesize: fileSize,\n blocksizes: this.blockSizes.length > 0 ? this.blockSizes : undefined,\n hashType: this.hashType,\n fanout: this.fanout\n })\n }\n}\n\n// decode from protobuf https://github.com/ipfs/go-ipfs/blob/master/unixfs/format.go#L24\nData.unmarshal = (marsheled) => {\n const decoded = unixfsData.decode(marsheled)\n if (!decoded.Data) {\n decoded.Data = undefined\n }\n const obj = new Data(types[decoded.Type], decoded.Data)\n obj.blockSizes = decoded.blocksizes\n return obj\n}\n\nexports = module.exports = Data\n\n\n//# sourceURL=webpack:///./node_modules/ipfs-unixfs/src/index.js?"); +eval("\n\nconst protons = __webpack_require__(/*! protons */ \"./node_modules/protons/src/index.js\")\nconst pb = protons(__webpack_require__(/*! ./unixfs.proto */ \"./node_modules/ipfs-unixfs/src/unixfs.proto.js\"))\n// encode/decode\nconst unixfsData = pb.Data\n// const unixfsMetadata = pb.MetaData // encode/decode\n\nconst types = [\n 'raw',\n 'directory',\n 'file',\n 'metadata',\n 'symlink',\n 'hamt-sharded-directory'\n]\n\nconst dirTypes = [\n 'directory',\n 'hamt-sharded-directory'\n]\n\nfunction Data (type, data) {\n if (!(this instanceof Data)) {\n return new Data(type, data)\n }\n if (types.indexOf(type) === -1) {\n throw new Error('Type: ' + type + ' is not valid')\n }\n\n this.type = type\n this.data = data\n this.blockSizes = []\n\n this.addBlockSize = (size) => {\n this.blockSizes.push(size)\n }\n\n this.removeBlockSize = (index) => {\n this.blockSizes.splice(index, 1)\n }\n\n // data.length + blockSizes\n this.fileSize = () => {\n if (dirTypes.indexOf(this.type) >= 0) {\n // dirs don't have file size\n return undefined\n }\n\n let sum = 0\n this.blockSizes.forEach((size) => {\n sum += size\n })\n if (data) {\n sum += data.length\n }\n return sum\n }\n\n // encode to protobuf\n this.marshal = () => {\n let type\n\n switch (this.type) {\n case 'raw': type = unixfsData.DataType.Raw; break\n case 'directory': type = unixfsData.DataType.Directory; break\n case 'file': type = unixfsData.DataType.File; break\n case 'metadata': type = unixfsData.DataType.Metadata; break\n case 'symlink': type = unixfsData.DataType.Symlink; break\n case 'hamt-sharded-directory': type = unixfsData.DataType.HAMTShard; break\n default:\n throw new Error(`Unkown type: \"${this.type}\"`)\n }\n let fileSize = this.fileSize()\n\n let data = this.data\n\n if (!this.data || !this.data.length) {\n data = undefined\n }\n\n let blockSizes = this.blockSizes\n\n if (!this.blockSizes || !this.blockSizes.length) {\n blockSizes = undefined\n }\n\n return unixfsData.encode({\n Type: type,\n Data: data,\n filesize: fileSize,\n blocksizes: blockSizes,\n hashType: this.hashType,\n fanout: this.fanout\n })\n }\n}\n\n// decode from protobuf https://github.com/ipfs/go-ipfs/blob/master/unixfs/format.go#L24\nData.unmarshal = (marsheled) => {\n const decoded = unixfsData.decode(marsheled)\n if (!decoded.Data) {\n decoded.Data = undefined\n }\n const obj = new Data(types[decoded.Type], decoded.Data)\n obj.blockSizes = decoded.blocksizes\n return obj\n}\n\nexports = module.exports = Data\n\n\n//# sourceURL=webpack:///./node_modules/ipfs-unixfs/src/index.js?"); /***/ }), @@ -5053,7 +5053,7 @@ eval("\n\nconst protons = __webpack_require__(/*! protons */ \"./node_modules/pr /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = `message Data {\n enum DataType {\n Raw = 0;\n Directory = 1;\n File = 2;\n Metadata = 3;\n Symlink = 4;\n HAMTShard = 5;\n }\n\n required DataType Type = 1;\n optional bytes Data = 2;\n optional uint64 filesize = 3;\n repeated uint64 blocksizes = 4;\n\n optional uint64 hashType = 5;\n optional uint64 fanout = 6;\n}\n\nmessage Metadata {\n required string MimeType = 1;\n}`\n\n\n//# sourceURL=webpack:///./node_modules/ipfs-unixfs/src/unixfs.proto.js?"); +eval("\n\nmodule.exports = `message Data {\n enum DataType {\n Raw = 0;\n Directory = 1;\n File = 2;\n Metadata = 3;\n Symlink = 4;\n HAMTShard = 5;\n }\n\n required DataType Type = 1;\n optional bytes Data = 2;\n optional uint64 filesize = 3;\n repeated uint64 blocksizes = 4;\n\n optional uint64 hashType = 5;\n optional uint64 fanout = 6;\n}\n\nmessage Metadata {\n optional string MimeType = 1;\n}`\n\n\n//# sourceURL=webpack:///./node_modules/ipfs-unixfs/src/unixfs.proto.js?"); /***/ }), diff --git a/package-lock.json b/package-lock.json index 56d2621..76828f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4361,9 +4361,9 @@ } }, "ipfs-unixfs": { - "version": "0.1.14", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-0.1.14.tgz", - "integrity": "sha512-s1tEnwKhdd17MmyC/EUMNVMDYzKhCiHDI11TF8tSBeWkEQp+0WUxkYuqvz0R5TSi2lNDJ/oVnEmwWhki2spUiQ==", + "version": "0.1.15", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-0.1.15.tgz", + "integrity": "sha512-fjtwBDsIlNags4btHIdAJtE02K4KqEMOhV9GEFVv1M2JO2STS23v2LAtX5qb1EOU5VrjtKlm/JIBH3XDRdAyGQ==", "requires": { "protons": "^1.0.0" } diff --git a/package.json b/package.json index 893ce05..d123449 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dependencies": { "cids": "latest", "ipfs": "latest", - "ipfs-unixfs": "latest", + "ipfs-unixfs": "^0.1.15", "node-fetch": "latest", "readable-stream": "latest", "webtorrent": "^0.99.3",