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

setBlockUpdate

This commit is contained in:
sunnylqm
2020-08-31 01:17:28 +08:00
parent f461c8ddd2
commit 9e6c7ea769
2 changed files with 39 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ export const currentVersion = Pushy.currentVersion;
export const isFirstTime = Pushy.isFirstTime;
export const isRolledBack = Pushy.isRolledBack;
export const buildTime = Pushy.buildTime;
let blockUpdate = Pushy.blockUpdate;
if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) {
throw new Error(
@@ -27,7 +28,7 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) {
/*
Return json:
Package was expired:
Package expired:
{
expired: true,
downloadUrl: 'http://appstore/downloadUrl',
@@ -56,6 +57,14 @@ function assertRelease() {
export async function checkUpdate(APPKEY, isRetry) {
assertRelease();
if (blockUpdate && blockUpdate.until > Date.now()) {
console.warn(
`Pushy update is blocked until ${new Date(
blockUpdate.until,
).toLocaleString()}. Reason: ${blockUpdate.reason}`,
);
return;
}
let resp;
try {
resp = await fetch(getCheckUrl(APPKEY), {
@@ -78,6 +87,8 @@ export async function checkUpdate(APPKEY, isRetry) {
return checkUpdate(APPKEY, true);
}
checkOperation(resp);
if (resp.status !== 200) {
throw new Error((await resp.json()).message);
}
@@ -85,12 +96,26 @@ export async function checkUpdate(APPKEY, isRetry) {
return resp.json();
}
function checkOperation(resp) {
if (!Array.isArray(resp.op)) {
return;
}
resp.op.forEach((action) => {
if (action.type === 'block') {
blockUpdate = {
reason: action.reason,
until: Date.now() + action.duration,
};
Pushy.setBlockUpdate(blockUpdate);
}
});
}
export async function downloadUpdate(options) {
assertRelease();
if (!options.update) {
return;
}
if (options.diffUrl) {
await Pushy.downloadPatchFromPpk({
updateUrl: options.diffUrl,