1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-12-18 03:35:08 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Fix custom endpoints

This commit is contained in:
sunnylqm
2020-07-28 23:34:06 +08:00
parent f110df1206
commit dbd0880295
3 changed files with 36 additions and 11 deletions

View File

@@ -29,6 +29,9 @@ let backupEndpointsQueryUrl =
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json';
export async function tryBackupEndpoints() {
if (!backupEndpoints.length && !backupEndpointsQueryUrl) {
return;
}
try {
await ping(getStatusUrl(), true);
logger('current endpoint ok');
@@ -73,10 +76,14 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
return `${endpoint}/checkUpdate/${APPKEY}`;
}
export function setCustomEndpoints(mainEndpoint, backups) {
currentEndpoint = mainEndpoint;
export function setCustomEndpoints({ main, backups, backupQueryUrl }) {
currentEndpoint = main;
backupEndpointsQueryUrl = null;
if (Array.isArray(backups) && backups.length > 0) {
backupEndpoints = backups;
pickFatestAvailableEndpoint();
}
if (typeof backupQueryUrl === 'string') {
backupEndpointsQueryUrl = backupQueryUrl;
}
}

21
lib/index.d.ts vendored
View File

@@ -21,7 +21,7 @@ export interface UpdateAvailableResult {
metaInfo: string;
pdiffUrl: string;
diffUrl?: string;
};
}
export type CheckResult =
| ExpiredResult
@@ -40,7 +40,18 @@ export function switchVersionLater(hash: string): void;
export function markSuccess(): void;
export function setCustomEndpoints(
mainEndpoint: string,
backupEndpoints?: string[],
): void;
/**
* @param {string} main - The main api endpoint
* @param {string[]} [backups] - The back up endpoints.
* @param {string} [backupQueryUrl] - An url that return a json file containing an array of endpoint.
* like: ["https://backup.api/1", "https://backup.api/2"]
*/
export function setCustomEndpoints({
main,
backups,
backupQueryUrl,
}: {
main: string;
backUps?: string[];
backupQueryUrl?: string;
}): void;