1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

fix: type

This commit is contained in:
sunnylqm 2023-09-05 22:47:47 +08:00
parent 8bed6ef979
commit 15af7802ad
No known key found for this signature in database

View File

@ -10,6 +10,7 @@ import {
PermissionsAndroid, PermissionsAndroid,
} from 'react-native'; } from 'react-native';
import { import {
CheckResult,
EventType, EventType,
ProgressData, ProgressData,
UpdateAvailableResult, UpdateAvailableResult,
@ -130,24 +131,23 @@ function assertRelease() {
} }
} }
let checkingThrottling = false; let lastChecking = Date.now();
export async function checkUpdate(APPKEY: string, isRetry?: boolean) { export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
assertRelease(); assertRelease();
if (checkingThrottling) { const now = Date.now();
if (now - lastChecking < 1000 * 5) {
logger('repeated checking, ignored'); logger('repeated checking, ignored');
return; return;
} }
checkingThrottling = true; lastChecking = now;
setTimeout(() => {
checkingThrottling = false;
}, 3000);
if (blockUpdate && blockUpdate.until > Date.now() / 1000) { if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
return report({ report({
type: 'errorChecking', type: 'errorChecking',
message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date( message: `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
blockUpdate.until * 1000, blockUpdate.until * 1000,
).toLocaleString()}"`, ).toLocaleString()}"`,
}); });
return;
} }
report({ type: 'checking' }); report({ type: 'checking' });
let resp; let resp;
@ -167,19 +167,26 @@ export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
}); });
} catch (e) { } catch (e) {
if (isRetry) { if (isRetry) {
return report({ report({
type: 'errorChecking', type: 'errorChecking',
message: '无法连接更新服务器,请检查网络连接后重试', message: '无法连接更新服务器,请检查网络连接后重试',
}); });
return;
} }
await tryBackupEndpoints(); await tryBackupEndpoints();
return checkUpdate(APPKEY, true); return checkUpdate(APPKEY, true);
} }
const result = await resp.json(); const result: CheckResult = await resp.json();
// @ts-ignore
checkOperation(result.op); checkOperation(result.op);
if (resp.status !== 200) { if (resp.status !== 200) {
return report({ type: 'errorChecking', message: result.message }); report({
type: 'errorChecking',
//@ts-ignore
message: result.message,
});
return;
} }
return result; return result;