-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove redundant ipfs configing code
- Loading branch information
1 parent
e825a0b
commit 55978ab
Showing
6 changed files
with
91 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,43 @@ | ||
'use strict' | ||
|
||
const request = require('ipfs-registry-mirror-common/utils/retry-request') | ||
const config = require('../config') | ||
const startIpfs = require('./start-ipfs') | ||
const request = require('ipfs-registry-mirror-common/utils/retry-request') | ||
const timeout = require('ipfs-registry-mirror-common/utils/timeout-promise') | ||
|
||
const cleanUpOps = [] | ||
|
||
const cleanUp = () => { | ||
Promise.all( | ||
cleanUpOps.map(op => op()) | ||
) | ||
.then(() => { | ||
process.exit(0) | ||
}) | ||
} | ||
|
||
process.on('SIGTERM', cleanUp) | ||
process.on('SIGINT', cleanUp) | ||
|
||
module.exports = async (options) => { | ||
options = config(options) | ||
|
||
const ipfs = await startIpfs(options) | ||
|
||
cleanUpOps.push(() => { | ||
return new Promise((resolve) => { | ||
if (options.ipfs.node !== 'proc') { | ||
return resolve() | ||
} | ||
|
||
ipfs.stop(() => { | ||
console.info('👿 IPFS node stopped') // eslint-disable-line no-console | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
|
||
console.info('🗂️ Loading registry index from', options.registry) // eslint-disable-line no-console | ||
const ipfs = await startIpfs(options)() | ||
|
||
const mirror = await request(Object.assign({}, options.request, { | ||
uri: options.registry, | ||
json: true | ||
})) | ||
|
||
console.info('☎️ Dialling registry mirror', mirror.ipfs.addresses.join(',')) // eslint-disable-line no-console | ||
const tempPath = `${options.ipfs.prefix}-${Date.now()}` | ||
|
||
let connected | ||
console.info('📠 Copying registry index', mirror.root, 'to', tempPath) // eslint-disable-line no-console | ||
|
||
await timeout( | ||
Promise.race( | ||
mirror.ipfs.addresses.map(addr => { | ||
return ipfs.api.swarm.connect(mirror.ipfs.addresses[0]) | ||
}) | ||
), | ||
options.registryConnectTimeout | ||
) | ||
.then(() => { | ||
connected = true | ||
}) | ||
.catch(() => { | ||
connected = false | ||
try { | ||
await ipfs.api.files.rm(tempPath, { | ||
recursive: true | ||
}) | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
if (connected) { | ||
const tempPath = `${options.ipfs.prefix}-${Date.now()}` | ||
|
||
console.info('📠 Copying registry index', mirror.root, 'to', tempPath) // eslint-disable-line no-console | ||
|
||
try { | ||
await ipfs.api.files.rm(tempPath, { | ||
recursive: true | ||
}) | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
await ipfs.api.files.cp(mirror.root, tempPath) | ||
|
||
console.info('💌 Copied registry index', mirror.root, 'to', tempPath) // eslint-disable-line no-console | ||
|
||
console.info('🗑️ Replacing old registry index if it exists') // eslint-disable-line no-console | ||
await ipfs.api.files.cp(mirror.root, tempPath) | ||
|
||
try { | ||
await ipfs.api.files.rm(options.ipfs.prefix, { | ||
recursive: true | ||
}) | ||
} catch (e) { | ||
// ignore | ||
} | ||
console.info('💌 Copied registry index', mirror.root, 'to', tempPath) // eslint-disable-line no-console | ||
console.info('🗑️ Replacing old registry index if it exists') // eslint-disable-line no-console | ||
|
||
await ipfs.api.files.mv(tempPath, options.ipfs.prefix) | ||
try { | ||
await ipfs.api.files.rm(options.ipfs.prefix, { | ||
recursive: true | ||
}) | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
await cleanUp() | ||
await ipfs.api.files.mv(tempPath, options.ipfs.prefix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.