mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 23:50:39 +08:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
946a5db7e9 |
@@ -41,12 +41,12 @@ const ping =
|
|||||||
Promise.race([
|
Promise.race([
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
}).then(({ status }) => (status === 200 ? url : null)),
|
})
|
||||||
|
.then(({ status }) => (status === 200 ? url : null))
|
||||||
|
.catch(() => null),
|
||||||
new Promise(r => setTimeout(() => r(null), 2000)),
|
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const canUseGoogle = ping('https://www.google.com');
|
|
||||||
|
|
||||||
export function joinUrls(paths: string[], fileName?: string) {
|
export function joinUrls(paths: string[], fileName?: string) {
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
return paths.map(path => 'https://' + path + '/' + fileName);
|
return paths.map(path => 'https://' + path + '/' + fileName);
|
||||||
@@ -57,8 +57,5 @@ export const testUrls = async (urls?: string[]) => {
|
|||||||
if (!urls?.length) {
|
if (!urls?.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (await canUseGoogle) {
|
|
||||||
return urls[0];
|
|
||||||
}
|
|
||||||
return promiseAny(urls.map(ping)).catch(() => null);
|
return promiseAny(urls.map(ping)).catch(() => null);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user