1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 07:01:38 +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",
"version": "10.28.11",
"version": "10.29.0",
"description": "react-native hot update",
"main": "src/index",
"scripts": {

View File

@@ -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) {

View File

@@ -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;
});
};