1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-11-01 22:03:10 +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, UpdateAvailableResult,
UpdateEventsListener, UpdateEventsListener,
} from './type'; } from './type';
import { assertRelease, logger } from './utils'; import { assertRelease, logger, testUrls } from './utils';
export { setCustomEndpoints }; export { setCustomEndpoints };
const { const {
version: v, version: v,
@@ -255,11 +255,12 @@ export async function downloadUpdate(
} }
let succeeded = false; let succeeded = false;
report({ type: 'downloading' }); report({ type: 'downloading' });
if (options.diffUrl) { const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
if (diffUrl) {
logger('downloading diff'); logger('downloading diff');
try { try {
await PushyModule.downloadPatchFromPpk({ await PushyModule.downloadPatchFromPpk({
updateUrl: options.diffUrl, updateUrl: diffUrl,
hash: options.hash, hash: options.hash,
originHash: currentVersion, originHash: currentVersion,
}); });
@@ -268,28 +269,34 @@ export async function downloadUpdate(
logger(`diff error: ${e.message}, try pdiff`); logger(`diff error: ${e.message}, try pdiff`);
} }
} }
if (!succeeded && options.pdiffUrl) { if (!succeeded) {
logger('downloading pdiff'); const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
try { if (pdiffUrl) {
await PushyModule.downloadPatchFromPackage({ logger('downloading pdiff');
updateUrl: options.pdiffUrl, try {
hash: options.hash, await PushyModule.downloadPatchFromPackage({
}); updateUrl: pdiffUrl,
succeeded = true; hash: options.hash,
} catch (e) { });
logger(`pdiff error: ${e.message}, try full patch`); succeeded = true;
} catch (e) {
logger(`pdiff error: ${e.message}, try full patch`);
}
} }
} }
if (!succeeded && options.updateUrl) { if (!succeeded) {
logger('downloading full patch'); const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
try { if (updateUrl) {
await PushyModule.downloadFullUpdate({ logger('downloading full patch');
updateUrl: options.updateUrl, try {
hash: options.hash, await PushyModule.downloadFullUpdate({
}); updateUrl: updateUrl,
succeeded = true; hash: options.hash,
} catch (e) { });
logger(`full patch error: ${e.message}`); succeeded = true;
} catch (e) {
logger(`full patch error: ${e.message}`);
}
} }
} }
progressHandler && progressHandler.remove(); progressHandler && progressHandler.remove();

View File

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

View File

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