Skip to content

Commit e964d00

Browse files
committed
feat: show gateway url for IPFS pinning service
To reduce the waiting time for the first view of the pinned site use the pinning service http gateway url. changes references to "public gateway" to "http gateway" to be consistent with how it works with this change in place.
1 parent 823b1dc commit e964d00

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

bin/ipfs-deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function main() {
9292

9393
const deployOptions = {
9494
publicDirPath: argv.path,
95-
copyPublicGatewayUrlToClipboard: !argv.noClipboard,
95+
copyHttpGatewayUrlToClipboard: !argv.noClipboard,
9696
open: !argv.O,
9797
port: argv.port,
9898
remotePinners: argv.p,

index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ const neatFrame = require('neat-frame')
2121
const { stripIndent } = require('common-tags')
2222

2323
// # Pure functions
24-
function publicGatewayUrl(hash) {
25-
return `https://ipfs.io/ipfs/${hash}`
24+
function httpGatewayUrl(hash, gatewayProvider = 'ipfs') {
25+
const gateways = {
26+
ipfs: 'https://ipfs.io',
27+
infura: 'https://ipfs.infura.io',
28+
pinata: 'https://gateway.pinata.cloud',
29+
}
30+
const origin = gateways[gatewayProvider] || gateways['ipfs']
31+
return `${origin}/ipfs/${hash}`
2632
}
2733

2834
function formatError(e) {
@@ -300,17 +306,17 @@ async function addToInfura(publicDirPath) {
300306
}
301307
}
302308

303-
function copyUrlToClipboard(hash) {
309+
function copyUrlToClipboard(url) {
304310
const spinner = ora()
305-
spinner.start('📋 Copying public gateway URL to clipboard…')
306-
clipboardy.writeSync(publicGatewayUrl(hash))
307-
spinner.succeed('📋 Copied public gateway URL to clipboard:')
308-
spinner.info(`🔗 ${chalk.green(publicGatewayUrl(hash))}`)
311+
spinner.start('📋 Copying HTTP gateway URL to clipboard…')
312+
clipboardy.writeSync(url)
313+
spinner.succeed('📋 Copied HTTP gateway URL to clipboard:')
314+
spinner.info(`🔗 ${chalk.green(url)}`)
309315
}
310316

311317
async function deploy({
312318
publicDirPath,
313-
copyPublicGatewayUrlToClipboard = false,
319+
copyHttpGatewayUrlToClipboard = false,
314320
open = false,
315321
port = '4002',
316322
remotePinners = ['infura'],
@@ -370,23 +376,24 @@ async function deploy({
370376

371377
if (successfulRemotePinners.length > 0) {
372378
const pinnedHash = Object.values(pinnedHashes)[0]
379+
const gatewayUrl = httpGatewayUrl(pinnedHash, successfulRemotePinners[0])
373380
const isEqual = hash => hash === pinnedHash
374381
if (!fp.every(isEqual)(Object.values(pinnedHashes))) {
375382
const spinner = ora()
376383
spinner.fail('≠ Found inconsistency in pinned hashes:')
377384
logError(pinnedHashes)
378385
}
379386

380-
if (copyPublicGatewayUrlToClipboard) {
381-
copyUrlToClipboard(pinnedHash)
387+
if (copyHttpGatewayUrlToClipboard) {
388+
copyUrlToClipboard(gatewayUrl)
382389
}
383390

384391
if (dnsProviders.includes('cloudflare')) {
385392
await updateCloudflareDns(siteDomain, credentials.cloudflare, pinnedHash)
386393
}
387394

388395
if (open && _.isEmpty(dnsProviders)) {
389-
await openUrl(publicGatewayUrl(pinnedHash))
396+
await openUrl(gatewayUrl)
390397
}
391398
if (open && !_.isEmpty(dnsProviders)) {
392399
await openUrl(`https://${siteDomain}`)

0 commit comments

Comments
 (0)