kopia lustrzana https://gitlab.com/rysiekpl/libresilient
merge-requests/9/merge
rodzic
40e2c9ddef
commit
90696da96e
|
@ -278,7 +278,7 @@ if (typeof window === 'undefined') {
|
|||
|
||||
self.log(config.name, "adding to IPFS...")
|
||||
self.log(config.name, "+-- number of resources:", resources.length)
|
||||
var ipfs_addresses = {};
|
||||
var ipfs_addresses = new Map();
|
||||
|
||||
resources.forEach(function(res){
|
||||
self.log(config.name, " +-- handling internal resource:", res)
|
||||
|
@ -290,10 +290,10 @@ if (typeof window === 'undefined') {
|
|||
// res holds the full URL
|
||||
// what we need in ipfs_addresses is in fact the absolute path (no domain, no scheme)
|
||||
var abs_path = res.replace(window.location.origin, '')
|
||||
ipfs_addresses[abs_path] = '/ipfs/' + result.cid.string
|
||||
self.log(config.name, "added to IPFS: " + abs_path + ' as ' + ipfs_addresses[abs_path])
|
||||
ipfs_addresses.set(abs_path, '/ipfs/' + result.cid.string)
|
||||
self.log(config.name, "added to IPFS: " + abs_path + ' as ' + ipfs_addresses.get(abs_path))
|
||||
// if we seem to have all we need, resolve!
|
||||
if (Object.keys(ipfs_addresses).length === resources.length) resolve(ipfs_addresses);
|
||||
if (ipfs_addresses.size === resources.length) resolve(ipfs_addresses);
|
||||
})
|
||||
|
||||
});
|
||||
|
@ -325,10 +325,10 @@ if (typeof window === 'undefined') {
|
|||
self.log(config.name, 'checking IPFS content against a gateway...')
|
||||
self.log(config.name, '+-- gateway in use: ' + config.ipfsGateway)
|
||||
// get the list of IPFS addresses
|
||||
var updatedPaths = Object.values(ipfs_addresses)
|
||||
for (path in ipfs_addresses) {
|
||||
var updatedPaths = Array.from(ipfs_addresses.values())
|
||||
for (const path of ipfs_addresses.keys()) {
|
||||
// start the fetch
|
||||
fetch(config.ipfsGateway + ipfs_addresses[path])
|
||||
fetch(config.ipfsGateway + ipfs_addresses.get(path))
|
||||
.then((response) => {
|
||||
ipfsaddr = response.url.replace(config.ipfsGateway, '')
|
||||
if (response.ok) {
|
||||
|
@ -392,6 +392,9 @@ if (typeof window === 'undefined') {
|
|||
return authGunAdmin(user, pass)
|
||||
.then((gunAPI) => {
|
||||
self.log(config.name, '+-- adding new IPFS addresses to Gun...')
|
||||
// TODO BUG: this will probably fail, or cause failures down the line
|
||||
// TODO BUG: we're setting a Map() object here; it's unclear how GunDB
|
||||
// TODO BUG: will handle this
|
||||
gunAPI.user.get(window.location.host).put(ipfs_addresses /*, function(ack) {...}*/);
|
||||
return gunAPI;
|
||||
})
|
||||
|
@ -407,8 +410,8 @@ if (typeof window === 'undefined') {
|
|||
.then((gunAPI) => {
|
||||
// get the paths
|
||||
self.log(config.name, '+-- starting verification of updated Gun data...')
|
||||
var updatedPaths = Object.keys(ipfs_addresses)
|
||||
for (path in ipfs_addresses) {
|
||||
var updatedPaths = Array.from(ipfs_addresses.values())
|
||||
for (const path of ipfs_addresses) {
|
||||
self.log(config.name, ' +-- watching: ' + path)
|
||||
//debuglog('watching path for updates:', path)
|
||||
// using the global gunUser to check if updates propagated
|
||||
|
@ -416,7 +419,7 @@ if (typeof window === 'undefined') {
|
|||
/*debuglog('+--', updpath)
|
||||
debuglog(' updated :', ipfs_addresses[updpath])
|
||||
debuglog(' received :', updaddr)*/
|
||||
if (ipfs_addresses[updpath] == updaddr) {
|
||||
if (ipfs_addresses.get(updpath) == updaddr) {
|
||||
// update worked!
|
||||
gunUser.get(window.location.host).get(updpath).off()
|
||||
self.log(config.name, '+-- update confirmed for:', updpath, '[' + updaddr + ']')
|
||||
|
|
Ładowanie…
Reference in New Issue