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

test cdn urls

This commit is contained in:
sunnylqm
2024-07-26 15:37:32 +08:00
parent fcfc8c3dbb
commit ab1e62dba5
3 changed files with 34 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ import {
UpdateAvailableResult,
UpdateEventsListener,
} from './type';
import { assertRelease, logger } from './utils';
import { assertRelease, logger, testUrls } from './utils';
export { setCustomEndpoints };
const {
version: v,
@@ -255,11 +255,12 @@ export async function downloadUpdate(
}
let succeeded = false;
report({ type: 'downloading' });
if (options.diffUrl) {
const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
if (diffUrl) {
logger('downloading diff');
try {
await PushyModule.downloadPatchFromPpk({
updateUrl: options.diffUrl,
updateUrl: diffUrl,
hash: options.hash,
originHash: currentVersion,
});
@@ -268,28 +269,34 @@ export async function downloadUpdate(
logger(`diff error: ${e.message}, try pdiff`);
}
}
if (!succeeded && options.pdiffUrl) {
logger('downloading pdiff');
try {
await PushyModule.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
succeeded = true;
} catch (e) {
logger(`pdiff error: ${e.message}, try full patch`);
if (!succeeded) {
const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
if (pdiffUrl) {
logger('downloading pdiff');
try {
await PushyModule.downloadPatchFromPackage({
updateUrl: pdiffUrl,
hash: options.hash,
});
succeeded = true;
} catch (e) {
logger(`pdiff error: ${e.message}, try full patch`);
}
}
}
if (!succeeded && options.updateUrl) {
logger('downloading full patch');
try {
await PushyModule.downloadFullUpdate({
updateUrl: options.updateUrl,
hash: options.hash,
});
succeeded = true;
} catch (e) {
logger(`full patch error: ${e.message}`);
if (!succeeded) {
const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
if (updateUrl) {
logger('downloading full patch');
try {
await PushyModule.downloadFullUpdate({
updateUrl: updateUrl,
hash: options.hash,
});
succeeded = true;
} catch (e) {
logger(`full patch error: ${e.message}`);
}
}
}
progressHandler && progressHandler.remove();

View File

@@ -19,8 +19,11 @@ export interface UpdateAvailableResult {
description: string;
metaInfo: string;
pdiffUrl: string;
pdiffUrls?: string[];
diffUrl?: string;
diffUrls?: string[];
updateUrl?: string;
updateUrls?: string[];
}
export type CheckResult =

View File

@@ -23,10 +23,9 @@ const ping =
new Promise(r => setTimeout(() => r(null), 2000)),
]);
const canUseGoogle = ping('https://www.google.com');
export const testUrls = async (urls?: string[]) => {
if (!urls?.length || (await canUseGoogle)) {
if (!urls?.length) {
return null;
}
return Promise.race(urls.map(ping)).catch(() => null);