mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-28 12:03:11 +08:00
add enhancedfetch for android <=7
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
UpdateAvailableResult,
|
||||
UpdateEventsListener,
|
||||
} from './type';
|
||||
import { assertRelease, logger, promiseAny, testUrls } from './utils';
|
||||
import { assertRelease, enhancedFetch, logger, promiseAny, testUrls } from './utils';
|
||||
export { setCustomEndpoints };
|
||||
const {
|
||||
version: v,
|
||||
@@ -153,7 +153,7 @@ export async function checkUpdate(APPKEY: string) {
|
||||
};
|
||||
let resp;
|
||||
try {
|
||||
resp = await fetch(getCheckUrl(APPKEY), fetchPayload);
|
||||
resp = await enhancedFetch(getCheckUrl(APPKEY), fetchPayload);
|
||||
} catch (e: any) {
|
||||
report({
|
||||
type: 'errorChecking',
|
||||
@@ -164,7 +164,7 @@ export async function checkUpdate(APPKEY: string) {
|
||||
try {
|
||||
resp = await promiseAny(
|
||||
backupEndpoints.map((endpoint) =>
|
||||
fetch(getCheckUrl(APPKEY, endpoint), fetchPayload),
|
||||
enhancedFetch(getCheckUrl(APPKEY, endpoint), fetchPayload),
|
||||
),
|
||||
);
|
||||
} catch {}
|
||||
|
||||
31
lib/utils.ts
31
lib/utils.ts
@@ -33,15 +33,15 @@ 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;
|
||||
}
|
||||
logger('ping failed', url, status, statusText);
|
||||
logger('ping failed', finalUrl, status, statusText);
|
||||
throw new Error('Ping failed');
|
||||
})
|
||||
.catch((e) => {
|
||||
@@ -73,3 +73,26 @@ export const testUrls = async (urls?: string[]) => {
|
||||
logger('all ping failed, use first url:', urls[0]);
|
||||
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 enhancedFetch = async (
|
||||
url: string,
|
||||
params: Parameters<typeof fetch>[1],
|
||||
) => {
|
||||
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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "8.5.6",
|
||||
"version": "8.5.7",
|
||||
"description": "react-native hot update",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user