3
3
4
4
const browser = require ( 'webextension-polyfill' )
5
5
const html = require ( 'choo/html' )
6
- const { normalizeGatewayURL } = require ( '../../lib/options' )
6
+ const { normalizeGatewayURL, hostTextToArray , hostArrayToText } = require ( '../../lib/options' )
7
7
8
8
// Warn about mixed content issues when changing the gateway
9
9
// https://github.com/ipfs-shipyard/ipfs-companion/issues/648
@@ -13,19 +13,40 @@ function gatewaysForm ({
13
13
ipfsNodeType,
14
14
customGatewayUrl,
15
15
useCustomGateway,
16
+ noRedirectHostnames,
16
17
publicGatewayUrl,
17
18
onOptionChange
18
19
} ) {
19
20
const onCustomGatewayUrlChange = onOptionChange ( 'customGatewayUrl' , normalizeGatewayURL )
20
21
const onUseCustomGatewayChange = onOptionChange ( 'useCustomGateway' )
21
22
const onPublicGatewayUrlChange = onOptionChange ( 'publicGatewayUrl' , normalizeGatewayURL )
23
+ const onNoRedirectHostnamesChange = onOptionChange ( 'noRedirectHostnames' , hostTextToArray )
22
24
const mixedContentWarning = ! secureContextUrl . test ( customGatewayUrl )
25
+ const supportRedirectToCustomGateway = ipfsNodeType === 'external'
23
26
24
27
return html `
25
28
< form >
26
29
< fieldset >
27
30
< legend > ${ browser . i18n . getMessage ( 'option_header_gateways' ) } </ legend >
28
- ${ ipfsNodeType === 'external' ? html `
31
+ < div >
32
+ < label for ="publicGatewayUrl ">
33
+ < dl >
34
+ < dt > ${ browser . i18n . getMessage ( 'option_publicGatewayUrl_title' ) } </ dt >
35
+ < dd > ${ browser . i18n . getMessage ( 'option_publicGatewayUrl_description' ) } </ dd >
36
+ </ dl >
37
+ </ label >
38
+ < input
39
+ id ="publicGatewayUrl "
40
+ type ="url "
41
+ inputmode ="url "
42
+ required
43
+ pattern ="^https?://[^/]+/?$ "
44
+ spellcheck ="false "
45
+ title ="Enter URL without any sub-path "
46
+ onchange =${ onPublicGatewayUrlChange }
47
+ value =${ publicGatewayUrl } />
48
+ </ div >
49
+ ${ supportRedirectToCustomGateway ? html `
29
50
< div >
30
51
< label for ="customGatewayUrl ">
31
52
< dl >
@@ -48,7 +69,7 @@ function gatewaysForm ({
48
69
49
70
</ div >
50
71
` : null }
51
- ${ ipfsNodeType === 'external' ? html `
72
+ ${ supportRedirectToCustomGateway ? html `
52
73
< div >
53
74
< label for ="useCustomGateway ">
54
75
< dl >
@@ -63,24 +84,22 @@ function gatewaysForm ({
63
84
checked =${ useCustomGateway } />
64
85
</ div >
65
86
` : null }
66
- < div >
67
- < label for ="publicGatewayUrl ">
68
- < dl >
69
- < dt > ${ browser . i18n . getMessage ( 'option_publicGatewayUrl_title' ) } </ dt >
70
- < dd > ${ browser . i18n . getMessage ( 'option_publicGatewayUrl_description' ) } </ dd >
71
- </ dl >
72
- </ label >
73
- < input
74
- id ="publicGatewayUrl "
75
- type ="url "
76
- inputmode ="url "
77
- required
78
- pattern ="^https?://[^/]+/?$ "
79
- spellcheck ="false "
80
- title ="Enter URL without any sub-path "
81
- onchange =${ onPublicGatewayUrlChange }
82
- value =${ publicGatewayUrl } />
83
- </ div >
87
+ ${ supportRedirectToCustomGateway ? html `
88
+ < div >
89
+ < label for ="noRedirectHostnames ">
90
+ < dl >
91
+ < dt > ${ browser . i18n . getMessage ( 'option_noRedirectHostnames_title' ) } </ dt >
92
+ < dd > ${ browser . i18n . getMessage ( 'option_noRedirectHostnames_description' ) } </ dd >
93
+ </ dl >
94
+ </ label >
95
+ < textarea
96
+ id ="noRedirectHostnames "
97
+ spellcheck ="false "
98
+ onchange =${ onNoRedirectHostnamesChange }
99
+ rows ="4"
100
+ > ${ hostArrayToText ( noRedirectHostnames ) } </ textarea >
101
+ </ div >
102
+ ` : null }
84
103
</ fieldset >
85
104
</ form >
86
105
`
0 commit comments