1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

update queryurls

This commit is contained in:
sunnylqm 2024-07-27 17:37:54 +08:00
parent 88bacdfb15
commit 2357a0b78d
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View File

@ -17,8 +17,10 @@ import {
const defaultServer = { const defaultServer = {
main: 'https://update.react-native.cn/api', main: 'https://update.react-native.cn/api',
backups: ['https://update.reactnative.cn/api'], backups: ['https://update.reactnative.cn/api'],
queryUrl: queryUrls: [
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json', 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
],
}; };
const empty = {}; const empty = {};
@ -233,9 +235,11 @@ export class Pushy {
if (!server) { if (!server) {
return []; return [];
} }
if (server.queryUrl) { if (server.queryUrls) {
try { try {
const resp = await fetch(server.queryUrl); const resp = await Promise.race(
server.queryUrls.map(queryUrl => fetch(queryUrl)),
);
const remoteEndpoints = await resp.json(); const remoteEndpoints = await resp.json();
log('fetch endpoints:', remoteEndpoints); log('fetch endpoints:', remoteEndpoints);
if (Array.isArray(remoteEndpoints)) { if (Array.isArray(remoteEndpoints)) {
@ -244,7 +248,7 @@ export class Pushy {
); );
} }
} catch (e: any) { } catch (e: any) {
log('failed to fetch endpoints from: ', server.queryUrl); log('failed to fetch endpoints from: ', server.queryUrls);
} }
} }
return server.backups; return server.backups;

View File

@ -62,7 +62,7 @@ export type UpdateEventsLogger = ({
export interface PushyServerConfig { export interface PushyServerConfig {
main: string; main: string;
backups?: string[]; backups?: string[];
queryUrl?: string; queryUrls?: string[];
} }
export interface PushyOptions { export interface PushyOptions {