1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-29 20:43:09 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

feat: test urls

This commit is contained in:
sunnylqm
2024-03-02 12:24:41 +08:00
parent c63e1501fe
commit 84ef668102
3 changed files with 34 additions and 3 deletions

View File

@@ -7,3 +7,18 @@ export function assertRelease() {
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
}
}
const ping = async (url: string) =>
fetch(url, {
method: 'HEAD',
redirect: 'follow',
}).then(({ status }) => status === 200);
const canUseGoogle = ping('https://www.google.com');
export const testUrls = async (urls?: string[]) => {
if (!urls?.length || (await canUseGoogle)) {
return null;
}
return Promise.race(urls.map((url) => ping(url).then(() => url)));
};