File tree Expand file tree Collapse file tree 1 file changed +36
-6
lines changed
Expand file tree Collapse file tree 1 file changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,42 @@ export const checkImage = async (url: string) => {
2020 const token = getTokenParsed ( ) ;
2121
2222 if ( ! token ) {
23- resolve ( {
24- ok : false ,
25- status : 401 ,
26- statusText : 'Unauthorized' ,
27- error : 'No authentication token available' ,
28- } ) ;
23+ // Allow browser to load publicly-accessible URLs without authentication
24+ // Fall through to Image() approach with resolved URL
25+ const resolvedUrl = resolveImageUrl ( url ) ;
26+ const img = new Image ( ) ;
27+
28+ // Set a timeout to handle very slow loads
29+ const timeoutId = setTimeout ( ( ) => {
30+ resolve ( {
31+ ok : false ,
32+ status : 408 ,
33+ statusText : 'Request Timeout' ,
34+ error : 'Image loading timed out' ,
35+ } ) ;
36+ } , 10000 ) ; // 10 second timeout
37+
38+ img . onload = ( ) => {
39+ clearTimeout ( timeoutId ) ;
40+ resolve ( {
41+ ok : true ,
42+ status : 200 ,
43+ statusText : 'OK' ,
44+ validatedUrl : resolvedUrl ,
45+ } ) ;
46+ } ;
47+
48+ img . onerror = ( ) => {
49+ clearTimeout ( timeoutId ) ;
50+ resolve ( {
51+ ok : false ,
52+ status : 404 ,
53+ statusText : 'Image Not Found' ,
54+ error : 'Failed to load image' ,
55+ } ) ;
56+ } ;
57+
58+ img . src = resolvedUrl ;
2959 return ;
3060 }
3161
You can’t perform that action at this time.
0 commit comments