mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	add fallback for android <= 7.0
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "react-native-update", | ||||
|   "version": "10.28.11", | ||||
|   "version": "10.29.0", | ||||
|   "description": "react-native hot update", | ||||
|   "main": "src/index", | ||||
|   "scripts": { | ||||
|   | ||||
| @@ -3,6 +3,7 @@ import { | ||||
|   assertDev, | ||||
|   assertWeb, | ||||
|   emptyObj, | ||||
|   enhancedFetch, | ||||
|   joinUrls, | ||||
|   log, | ||||
|   noop, | ||||
| @@ -261,7 +262,7 @@ export class Pushy { | ||||
|         type: 'checking', | ||||
|         message: this.options.appKey + ': ' + stringifyBody, | ||||
|       }); | ||||
|       resp = await fetch(this.getCheckUrl(), fetchPayload); | ||||
|       resp = await enhancedFetch(this.getCheckUrl(), fetchPayload); | ||||
|     } catch (e: any) { | ||||
|       this.report({ | ||||
|         type: 'errorChecking', | ||||
| @@ -272,7 +273,7 @@ export class Pushy { | ||||
|         try { | ||||
|           resp = await promiseAny( | ||||
|             backupEndpoints.map(endpoint => | ||||
|               fetch(this.getCheckUrl(endpoint), fetchPayload), | ||||
|               enhancedFetch(this.getCheckUrl(endpoint), fetchPayload), | ||||
|             ), | ||||
|           ); | ||||
|         } catch (err: any) { | ||||
|   | ||||
							
								
								
									
										28
									
								
								src/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/utils.ts
									
									
									
									
									
								
							| @@ -40,13 +40,13 @@ const ping = | ||||
|     : async (url: string) => { | ||||
|         let pingFinished = false; | ||||
|         return Promise.race([ | ||||
|           fetch(url, { | ||||
|           enhancedFetch(url, { | ||||
|             method: 'HEAD', | ||||
|           }) | ||||
|             .then(({ status, statusText }) => { | ||||
|             .then(({ status, statusText, url: finalUrl }) => { | ||||
|               pingFinished = true; | ||||
|               if (status === 200) { | ||||
|                 return url; | ||||
|                 return finalUrl; | ||||
|               } | ||||
|               log('ping failed', url, status, statusText); | ||||
|               throw new Error('Ping failed'); | ||||
| @@ -69,7 +69,7 @@ const ping = | ||||
|  | ||||
| export function joinUrls(paths: string[], fileName?: string) { | ||||
|   if (fileName) { | ||||
|     return paths.map(path => 'https://' + path + '/' + fileName); | ||||
|     return paths.map(path => `https://${path}/${fileName}`); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -108,3 +108,23 @@ export const assertDev = (matter: string) => { | ||||
|   } | ||||
|   return true; | ||||
| }; | ||||
|  | ||||
| export const isAndroid70AndBelow = () => { | ||||
|   // android 7.0 and below devices do not support letsencrypt cert | ||||
|   // https://letsencrypt.org/2023/07/10/cross-sign-expiration/ | ||||
|   return Platform.OS === 'android' && Platform.Version <= 24; | ||||
| }; | ||||
|  | ||||
| export const enhancedFetch = async ( | ||||
|   url: string, | ||||
|   params: Parameters<typeof fetch>[1], | ||||
| ) => { | ||||
|   return fetch(url, params).catch(e => { | ||||
|     log('fetch error', url, e); | ||||
|     if (isAndroid70AndBelow()) { | ||||
|       log(`try fallback to http because android version: ${Platform.Version}`); | ||||
|       return fetch(url.replace('https', 'http'), params); | ||||
|     } | ||||
|     throw e; | ||||
|   }); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm