@@ -60,14 +60,14 @@ const Preview = (props) => {
60
60
< Drag { ...props } >
61
61
{ /* eslint-disable-next-line jsx-a11y/media-has-caption */ }
62
62
< audio width = '100%' controls >
63
- < source src = { src } />
63
+ < source src = { safeSubresourceGwUrl ( src ) } />
64
64
</ audio >
65
65
</ Drag >
66
66
)
67
67
case 'pdf' :
68
68
return (
69
69
< Drag { ...props } >
70
- < object className = "FilePreviewPDF w-100" data = { src } type = 'application/pdf' >
70
+ < object className = "FilePreviewPDF w-100" data = { safeSubresourceGwUrl ( src ) } type = 'application/pdf' >
71
71
{ t ( 'noPDFSupport' ) }
72
72
< a href = { src } download target = '_blank' rel = 'noopener noreferrer' className = 'underline-hover navy-muted' > { t ( 'downloadPDF' ) } </ a >
73
73
</ object >
@@ -78,14 +78,14 @@ const Preview = (props) => {
78
78
< Drag { ...props } >
79
79
{ /* eslint-disable-next-line jsx-a11y/media-has-caption */ }
80
80
< video controls className = { className } >
81
- < source src = { src } />
81
+ < source src = { safeSubresourceGwUrl ( src ) } />
82
82
</ video >
83
83
</ Drag >
84
84
)
85
85
case 'image' :
86
86
return (
87
87
< Drag { ...props } >
88
- < img className = { className } alt = { name } src = { src } />
88
+ < img className = { className } alt = { name } src = { safeSubresourceGwUrl ( src ) } />
89
89
</ Drag >
90
90
)
91
91
default : {
@@ -154,3 +154,19 @@ export default connect(
154
154
'selectPublicGateway' ,
155
155
withTranslation ( 'files' ) ( Preview )
156
156
)
157
+
158
+ // Potential fix for mixed-content error when redirecting to localhost subdomain
159
+ // from https://github.com/ipfs/ipfs-webui/issues/2246#issuecomment-2322192398
160
+ // We do it here and not in src/bundles/config.js because we dont want IPLD
161
+ // explorer to open links in path gateway, localhost is desired there.
162
+ //
163
+ // Context: localhost in Kubo is a subdomain gateway, so http://locahost:8080/ipfs/cid will
164
+ // redirect to http://cid.ipfs.localhost:8080 – perhaps subdomains are not
165
+ // interpreted as secure context correctly and that triggers forced upgrade to
166
+ // https. switching to IP should help.
167
+ function safeSubresourceGwUrl ( url ) {
168
+ if ( url . startsWith ( 'http://localhost:' ) ) {
169
+ return url . replace ( 'http://localhost:' , 'http://127.0.0.1:' )
170
+ }
171
+ return url
172
+ }
0 commit comments