mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-03-15 18:30:49 +00:00
Updated, webpacked and deployed
This commit is contained in:
parent
ab90df7e40
commit
2c6bad9579
@ -55,11 +55,12 @@ class Transport {
|
||||
}
|
||||
/* Disconnect from the transport service - there is no guarrantee that a restart will be successfull so this is usually only for when exiting */
|
||||
p_stop(refreshstatus) {
|
||||
// refreshstatus(Transport instance) => optional callback to the UI to update the status on the display
|
||||
return new Promise((resolve, reject) => {
|
||||
this.status = Transport.STATUS_FAILED;
|
||||
if (refreshstatus) refreshstatus(this);
|
||||
//if (err) { reject(err) } else {
|
||||
resolve(res);
|
||||
resolve();
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class TransportHTTP extends Transport {
|
||||
*/
|
||||
//PY: res = self._sendGetPost(True, "rawstore", headers={"Content-Type": "application/octet-stream"}, urlargs=[], data=data)
|
||||
console.assert(data, "TransportHttp.p_rawstore: requires data");
|
||||
let res = await httptools.p_POST(this._cmdurl(servercommands.rawstore), "application/octet-stream", data); // resolves to URL
|
||||
const res = await httptools.p_POST(this._cmdurl(servercommands.rawstore), "application/octet-stream", data); // resolves to URL
|
||||
let parsedurl = Url.parse(res);
|
||||
let pathparts = parsedurl.pathname.split('/');
|
||||
return `contenthash:/contenthash/${pathparts.slice(-1)}`
|
||||
@ -271,7 +271,7 @@ class TransportHTTP extends Transport {
|
||||
async p_get(url, keys) {
|
||||
if (!url && keys) throw new errors.CodingError("TransportHTTP.p_get: requires url and at least one key");
|
||||
let parmstr =Array.isArray(keys) ? keys.map(k => this._keyparm(k)).join('&') : this._keyparm(keys);
|
||||
let res = await httptools.p_GET(this._url(url, servercommands.get, parmstr));
|
||||
const res = await httptools.p_GET(this._url(url, servercommands.get, parmstr));
|
||||
return Array.isArray(keys) ? res : res[keys]
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ This is a shim to the IPFS library, (Lists are handled in YJS or OrbitDB)
|
||||
See https://github.com/ipfs/js-ipfs but note its often out of date relative to the generic API doc.
|
||||
*/
|
||||
|
||||
//TODO-IPFS Note API changes in https://github.com/ipfs/js-ipfs/issues/1721 probably all ipfs.files -> ipfs.
|
||||
|
||||
const httptools = require('./httptools'); // Expose some of the httptools so that IPFS can use it as a backup
|
||||
const debug = require('debug')('dweb-transports:ipfs');
|
||||
|
||||
|
@ -101,7 +101,7 @@ class Transports {
|
||||
then resolve urls that might be names, returning a modified array.
|
||||
*/
|
||||
if (this.mirror) {
|
||||
return Array.isArray(urls) ? urls.map(url=>this.gatewayUrl(url)) : this.gatewayUrl(url);
|
||||
return Array.isArray(urls) ? this.gatewayUrls(urls) : this.gatewayUrl(url);
|
||||
} else if (this.namingcb) {
|
||||
return await this.namingcb(urls); // Array of resolved urls
|
||||
} else {
|
||||
@ -756,12 +756,23 @@ class Transports {
|
||||
let o = this.canonicalName(url, options);
|
||||
return o.protocol + ":/" + o.internal;
|
||||
}
|
||||
static _o2url(o) {
|
||||
return ["http","https"].includes(o.proto) ? [o.proto, o.internal].join('://') // Shouldnt be relative
|
||||
: o.proto ? [this.mirror, o.proto, o.internal].join('/')
|
||||
: o.internal; // Uncanonicalizable
|
||||
}
|
||||
static gatewayUrl(url) {
|
||||
// Convert url to gateway url, if not canonicalizable then just pass the url along
|
||||
let o = Transports.canonicalName(url);
|
||||
return !o ? url
|
||||
: ["http","https"].includes(o.proto) ? [o.proto, o.internal].join('://') // Shouldnt be relative
|
||||
: [this.mirror, o.proto, o.internal].join('/');
|
||||
return !o ? url : this._o2url(o)
|
||||
}
|
||||
static gatewayUrls(urls) { //TODO-API
|
||||
// Convert urls to gateway urls,
|
||||
// Easier to work on single form [ { proto, internal } ]
|
||||
const oo = urls.map(url => Transports.canonicalName(url) || { proto: undefined, internal: url }); //if not canonicalizable then just pass the url along
|
||||
const oArc = oo.filter(o => ["arc"].includes(o.proto)); // Prefered
|
||||
return (oArc.length ? oArc : oo) // Prefered if have them, else others
|
||||
.map(o=>this._o2url(o))
|
||||
}
|
||||
}
|
||||
Transports._transports = []; // Array of transport instances connected
|
||||
|
28
dist/dweb-transports-bundle.js
vendored
28
dist/dweb-transports-bundle.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user