1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 08:41:37 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

add fallback for android <= 7.0

This commit is contained in:
sunnylqm
2025-05-21 10:44:44 +08:00
parent 7eac48ab5d
commit 2cf7336b6a
3 changed files with 28 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update", "name": "react-native-update",
"version": "10.28.11", "version": "10.29.0",
"description": "react-native hot update", "description": "react-native hot update",
"main": "src/index", "main": "src/index",
"scripts": { "scripts": {

View File

@@ -3,6 +3,7 @@ import {
assertDev, assertDev,
assertWeb, assertWeb,
emptyObj, emptyObj,
enhancedFetch,
joinUrls, joinUrls,
log, log,
noop, noop,
@@ -261,7 +262,7 @@ export class Pushy {
type: 'checking', type: 'checking',
message: this.options.appKey + ': ' + stringifyBody, message: this.options.appKey + ': ' + stringifyBody,
}); });
resp = await fetch(this.getCheckUrl(), fetchPayload); resp = await enhancedFetch(this.getCheckUrl(), fetchPayload);
} catch (e: any) { } catch (e: any) {
this.report({ this.report({
type: 'errorChecking', type: 'errorChecking',
@@ -272,7 +273,7 @@ export class Pushy {
try { try {
resp = await promiseAny( resp = await promiseAny(
backupEndpoints.map(endpoint => backupEndpoints.map(endpoint =>
fetch(this.getCheckUrl(endpoint), fetchPayload), enhancedFetch(this.getCheckUrl(endpoint), fetchPayload),
), ),
); );
} catch (err: any) { } catch (err: any) {

View File

@@ -40,13 +40,13 @@ const ping =
: async (url: string) => { : async (url: string) => {
let pingFinished = false; let pingFinished = false;
return Promise.race([ return Promise.race([
fetch(url, { enhancedFetch(url, {
method: 'HEAD', method: 'HEAD',
}) })
.then(({ status, statusText }) => { .then(({ status, statusText, url: finalUrl }) => {
pingFinished = true; pingFinished = true;
if (status === 200) { if (status === 200) {
return url; return finalUrl;
} }
log('ping failed', url, status, statusText); log('ping failed', url, status, statusText);
throw new Error('Ping failed'); throw new Error('Ping failed');
@@ -69,7 +69,7 @@ const ping =
export function joinUrls(paths: string[], fileName?: string) { export function joinUrls(paths: string[], fileName?: string) {
if (fileName) { 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; 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;
});
};