From 5011c984ee153e931ce79d82fd5fc6f84ad59b3a Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Sat, 30 Aug 2025 11:18:18 +0800 Subject: [PATCH] v8.5.7 --- .gitignore | 1 + lib/endpoint.ts | 5 +---- lib/utils.ts | 37 +++++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index a3ea7b8..8637a00 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ Example/**/update.json yarn-error.log Example/testHotUpdate/.pushy dist/ +.cursor/mcp.json diff --git a/lib/endpoint.ts b/lib/endpoint.ts index 353368c..f84cf9d 100644 --- a/lib/endpoint.ts +++ b/lib/endpoint.ts @@ -1,10 +1,7 @@ import { logger, promiseAny } from './utils'; let currentEndpoint = 'https://update.react-native.cn/api'; -let backupEndpoints: string[] = [ - 'https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run', - 'https://update.reactnative.cn/api', -]; +let backupEndpoints: string[] = ['https://update.reactnative.cn/api']; let backupEndpointsQueryUrls = [ 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json', 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json', diff --git a/lib/utils.ts b/lib/utils.ts index 7272e36..123dca2 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -74,25 +74,30 @@ export const testUrls = async (urls?: string[]) => { return urls[0]; }; -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 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[1], + isRetry = false, ) => { - return fetch(url, params).catch((e) => { - logger('fetch error', url, e); - if (isAndroid70AndBelow()) { - logger( - `try fallback to http because android version: ${Platform.Version}`, - ); - return fetch(url.replace('https', 'http'), params); - } else { - throw e; - } - }); + return fetch(url, params) + .then((r) => { + if (r.ok) { + return r; + } + throw new Error(`${r.status} ${r.statusText}`); + }) + .catch((e) => { + logger('fetch error', url, e); + if (isRetry) { + throw e; + } + logger('trying fallback to http'); + return enhancedFetch(url.replace('https', 'http'), params, true); + }); };