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

Backup domains

This commit is contained in:
sunnylqm
2020-01-18 23:55:10 +08:00
parent bdd97ac6ac
commit 1d0fb7d260
4 changed files with 81 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
import getHost, { tryBackupDomains } from './getHost';
import { NativeAppEventEmitter, NativeModules } from 'react-native';
const Pushy = NativeModules.Pushy || {};
const host = 'https://update.reactnative.cn/api';
const Pushy = NativeModules.Pushy || {};
export const downloadRootDir = Pushy.downloadRootDir;
export const packageVersion = Pushy.packageVersion;
@@ -28,7 +28,6 @@ There is available update:
hash: 'hash',
description: '添加聊天功能\n修复商城页面BUG',
metaInfo: '{"silent":true}',
updateUrl: 'http://update-packages.reactnative.cn/hash',
pdiffUrl: 'http://update-packages.reactnative.cn/hash',
diffUrl: 'http://update-packages.reactnative.cn/hash',
}
@@ -40,20 +39,29 @@ function assertRelease() {
}
}
export async function checkUpdate(APPKEY) {
export async function checkUpdate(APPKEY, isRetry) {
assertRelease();
const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
packageVersion,
hash: currentVersion,
buildTime,
}),
});
let resp;
try {
resp = await fetch(`${getHost()}/checkUpdate/${APPKEY}`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
packageVersion,
hash: currentVersion,
buildTime,
}),
});
} catch (e) {
if (isRetry) {
throw new Error('Could not connect to pushy server');
}
await tryBackupDomains();
return checkUpdate(APPKEY, true);
}
if (resp.status !== 200) {
throw new Error((await resp.json()).message);