From 2357a0b78d0a03faef753e0595c2222a2e93ea86 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Sat, 27 Jul 2024 17:37:54 +0800 Subject: [PATCH] update queryurls --- src/client.ts | 12 ++++++++---- src/type.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index 00eaf052..e5f607ab 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,8 +17,10 @@ import { const defaultServer = { main: 'https://update.react-native.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', + ], }; const empty = {}; @@ -233,9 +235,11 @@ export class Pushy { if (!server) { return []; } - if (server.queryUrl) { + if (server.queryUrls) { try { - const resp = await fetch(server.queryUrl); + const resp = await Promise.race( + server.queryUrls.map(queryUrl => fetch(queryUrl)), + ); const remoteEndpoints = await resp.json(); log('fetch endpoints:', remoteEndpoints); if (Array.isArray(remoteEndpoints)) { @@ -244,7 +248,7 @@ export class Pushy { ); } } catch (e: any) { - log('failed to fetch endpoints from: ', server.queryUrl); + log('failed to fetch endpoints from: ', server.queryUrls); } } return server.backups; diff --git a/src/type.ts b/src/type.ts index acb82fec..e6ed64d6 100644 --- a/src/type.ts +++ b/src/type.ts @@ -62,7 +62,7 @@ export type UpdateEventsLogger = ({ export interface PushyServerConfig { main: string; backups?: string[]; - queryUrl?: string; + queryUrls?: string[]; } export interface PushyOptions {