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

Add report

This commit is contained in:
sunnylqm
2021-10-21 09:29:37 +08:00
parent 2bf25f37f0
commit 8db8d2162e
5 changed files with 56 additions and 58 deletions

View File

@@ -76,6 +76,10 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
return `${endpoint}/checkUpdate/${APPKEY}`;
}
export function getReportUrl(endpoint = currentEndpoint) {
return `${endpoint}/report`;
}
export function setCustomEndpoints({ main, backups, backupQueryUrl }) {
currentEndpoint = main;
backupEndpointsQueryUrl = null;

View File

@@ -2,6 +2,7 @@ import {
tryBackupEndpoints,
getCheckUrl,
setCustomEndpoints,
getReportUrl,
} from './endpoint';
import {
NativeEventEmitter,
@@ -25,7 +26,9 @@ export const downloadRootDir = Pushy.downloadRootDir;
export const packageVersion = Pushy.packageVersion;
export const currentVersion = Pushy.currentVersion;
export const isFirstTime = Pushy.isFirstTime;
export const isRolledBack = Pushy.isRolledBack;
const rolledBackVersion = Pushy.rolledBackVersion;
export const isRolledBack = typeof rolledBackVersion === 'string';
export const buildTime = Pushy.buildTime;
let blockUpdate = Pushy.blockUpdate;
let uuid = Pushy.uuid;
@@ -45,7 +48,7 @@ async function getLocalHashInfo(hash) {
}
export async function getCurrentVersionInfo() {
return currentVersion ? await getLocalHashInfo(currentVersion) || {} : {};
return currentVersion ? (await getLocalHashInfo(currentVersion)) || {} : {};
}
const eventEmitter = new NativeEventEmitter(Pushy);
@@ -59,30 +62,29 @@ function logger(text) {
console.log(`Pushy: ${text}`);
}
function report(hash, type) {
logger(type);
fetch(getReportUrl(), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
hash,
type,
cInfo,
packageVersion,
buildTime,
}),
}).catch((_e) => {});
}
logger('uuid: ' + uuid);
/*
Return json:
Package expired:
{
expired: true,
downloadUrl: 'http://appstore/downloadUrl',
if (isRolledBack) {
report(rolledBackVersion, 'rollback');
}
Package is up to date:
{
upToDate: true,
}
There is available update:
{
update: true,
name: '1.0.3-rc',
hash: 'hash',
description: '添加聊天功能\n修复商城页面BUG',
metaInfo: '{"silent":true}',
pdiffUrl: 'http://update-packages.reactnative.cn/hash',
diffUrl: 'http://update-packages.reactnative.cn/hash',
}
*/
export const cInfo = {
pushy: require('../package.json').version,
@@ -173,6 +175,10 @@ export async function downloadUpdate(options, eventListeners) {
if (!options.update) {
return;
}
if (rolledbackVersion === options.hash) {
logger(`rolledback hash ${rolledbackVersion}, ignored`);
return;
}
if (downloadedHash === options.hash) {
logger(`duplicated downloaded hash ${downloadedHash}, ignored`);
return;
@@ -275,8 +281,8 @@ export function markSuccess() {
return;
}
marked = true;
logger('markSuccess');
Pushy.markSuccess();
report(currentVersion, 'success');
}
export async function downloadAndInstallApk({ url, onDownloadProgress }) {