mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 12:51:44 +08:00
test cdn urls
This commit is contained in:
53
lib/main.ts
53
lib/main.ts
@@ -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();
|
||||
|
@@ -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 =
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user