mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-01 13:53:11 +08:00
Add report
This commit is contained in:
@@ -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;
|
||||
|
||||
54
lib/main.js
54
lib/main.js
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user