mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:11:39 +08:00
add fallback for android <= 7.0
This commit is contained in:
@@ -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": {
|
||||||
|
@@ -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) {
|
||||||
|
28
src/utils.ts
28
src/utils.ts
@@ -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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user