@@ -128,14 +128,33 @@ const Url = ({ url }: { url: IUrl }) => {
128
128
const { colors, theme } = useTheme ( ) ;
129
129
const { baseUrl, user } = useContext ( MessageContext ) ;
130
130
const API_Embed = useAppSelector ( state => state . settings . API_Embed ) ;
131
+ const [ imageUrl , setImageUrl ] = useState ( '' ) ;
132
+
133
+ useEffect ( ( ) => {
134
+ const verifyUrlIsImage = async ( ) => {
135
+ try {
136
+ const imageUrl = getImageUrl ( ) ;
137
+ if ( ! imageUrl ) return ;
138
+
139
+ const response = await fetch ( imageUrl , { method : 'HEAD' } ) ;
140
+ const contentType = response . headers . get ( 'content-type' ) ;
141
+ if ( contentType ?. startsWith ?.( 'image/' ) ) {
142
+ setImageUrl ( imageUrl ) ;
143
+ }
144
+ } catch {
145
+ // do nothing
146
+ }
147
+ } ;
148
+ verifyUrlIsImage ( ) ;
149
+ } , [ url . image , url . url ] ) ;
150
+
131
151
const getImageUrl = ( ) => {
132
- const imageUrl = url . image || url . url ;
152
+ const _imageUrl = url . image || url . url ;
133
153
134
- if ( ! imageUrl ) return null ;
135
- if ( imageUrl . includes ( 'http' ) ) return imageUrl ;
136
- return `${ baseUrl } /${ imageUrl } ?rc_uid=${ user . id } &rc_token=${ user . token } ` ;
154
+ if ( ! _imageUrl ) return null ;
155
+ if ( _imageUrl . includes ( 'http' ) ) return _imageUrl ;
156
+ return `${ baseUrl } /${ _imageUrl } ?rc_uid=${ user . id } &rc_token=${ user . token } ` ;
137
157
} ;
138
- const image = getImageUrl ( ) ;
139
158
140
159
const onPress = ( ) => openLink ( url . url , theme ) ;
141
160
@@ -166,9 +185,9 @@ const Url = ({ url }: { url: IUrl }) => {
166
185
] }
167
186
background = { Touchable . Ripple ( colors . surfaceNeutral ) } >
168
187
< >
169
- { image ? (
188
+ { imageUrl ? (
170
189
< WidthAwareView >
171
- < UrlImage image = { image } hasContent = { hasContent } />
190
+ < UrlImage image = { imageUrl } hasContent = { hasContent } />
172
191
</ WidthAwareView >
173
192
) : null }
174
193
{ hasContent ? < UrlContent title = { url . title } description = { url . description } /> : null }
0 commit comments