Skip to content

Commit 7a15812

Browse files
authored
feat: private and public gateways (#300)
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
1 parent d6179cc commit 7a15812

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

public/locales/en/explore.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"hashDigest": "Hash digest"
3131
},
3232
"ObjectInfo": {
33-
"gatewayLink": "View on IPFS Gateway"
33+
"publicGateway": "View on Public Gateway",
34+
"privateGateway": "View on Local Gateway"
3435
},
3536
"base": "base",
3637
"version": "version",

src/components/ExplorePage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { explorerTour } from '../lib/tours'
1313

1414
export class ExplorePage extends React.Component {
1515
render () {
16-
let { t, explore, exploreIsLoading, explorePathFromHash, doExploreLink, runTour = false, joyrideCallback, gatewayUrl = 'https://ipfs.io' } = this.props
16+
let { t, explore, exploreIsLoading, explorePathFromHash, doExploreLink, runTour = false, joyrideCallback, gatewayUrl, publicGatewayUrl = 'https://dweb.link' } = this.props
1717

1818
if (!explorePathFromHash) {
1919
// No IPLD path to explore so show the intro page
@@ -70,6 +70,7 @@ export class ExplorePage extends React.Component {
7070
format={targetNode.format}
7171
onLinkClick={doExploreLink}
7272
gatewayUrl={gatewayUrl}
73+
publicGatewayUrl={publicGatewayUrl}
7374
/>
7475
)
7576
: null}

src/components/object-info/ObjectInfo.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const DagNodeIcon = ({ type, ...props }) => (
6262
</svg>
6363
)
6464

65-
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, ...props }) => {
65+
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
6666
return (
6767
<section className={`pa4 sans-serif ${className}`} {...props}>
6868
<h2 className='ma0 lh-title f4 fw4 montserrat pb2' title={type}>
@@ -74,9 +74,16 @@ const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, li
7474
<a className='dn di-ns no-underline charcoal ml2' href='https://docs.ipfs.io/concepts/glossary/#unixfs' rel='external' target='_external'>UnixFS</a>
7575
) : null}
7676
{format === 'unixfs' && data.type && ['directory', 'file'].some(x => x === data.type) ? (
77-
<a className='no-underline avenir ml2 pa2 fw5 f6 blue' href={`${gatewayUrl}/ipfs/${cid}`} rel='external nofollow' target='_external'>
78-
{t('ObjectInfo.gatewayLink')}
79-
</a>
77+
<>
78+
{gatewayUrl && gatewayUrl !== publicGatewayUrl && (
79+
<a className='no-underline avenir ml2 pa2 fw5 f6 blue' href={`${gatewayUrl}/ipfs/${cid}`} rel='external nofollow' target='_external'>
80+
{t('ObjectInfo.privateGateway')}
81+
</a>)}
82+
{publicGatewayUrl && (
83+
<a className='no-underline avenir ml2 pa2 fw5 f6 blue' href={`${publicGatewayUrl}/ipfs/${cid}`} rel='external nofollow' target='_external'>
84+
{t('ObjectInfo.publicGateway')}
85+
</a>)}
86+
</>
8087
) : null}
8188
</h2>
8289
<div className='f6'>

src/components/object-info/ObjectInfo.stories.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ storiesOf('IPLD Node Info', module)
2424
data={dagNodeA.data}
2525
type='dag-pb'
2626
gatewayUrl='https://ipfs.io'
27+
publicGatewayUrl='https://dweb.link'
2728
onLinkClick={action('link clicked')}
2829
/>
2930
))
@@ -36,6 +37,7 @@ storiesOf('IPLD Node Info', module)
3637
data={dagNodeB.data}
3738
type='dag-pb'
3839
gatewayUrl='https://ipfs.io'
40+
publicGatewayUrl='https://dweb.link'
3941
onLinkClick={action('link clicked')}
4042
/>
4143
))
@@ -48,6 +50,7 @@ storiesOf('IPLD Node Info', module)
4850
data={dagNodeC.data}
4951
type='dag-pb'
5052
gatewayUrl='https://ipfs.io'
53+
publicGatewayUrl='https://dweb.link'
5154
onLinkClick={action('link clicked')}
5255
/>
5356
))

0 commit comments

Comments
 (0)