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

improve cleanup and rollout

This commit is contained in:
sunnylqm
2024-10-03 21:41:47 +08:00
parent 2467b0c119
commit 94431ee6f7
6 changed files with 36 additions and 10 deletions

6
Example/update.json Normal file
View File

@@ -0,0 +1,6 @@
{
"android": {
"appId": 28605,
"appKey": "5gbQes9blswLW_jv8dnp8QBz"
}
}

View File

@@ -430,6 +430,9 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
if (sub.getName().charAt(0) == '.') {
continue;
}
if (isFileUpdatedWithinDays(sub, 7)) {
continue;
}
if (sub.isFile()) {
sub.delete();
} else {
@@ -441,6 +444,13 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
}
}
private boolean isFileUpdatedWithinDays(File file, int days) {
long currentTime = System.currentTimeMillis();
long lastModified = file.lastModified();
long daysInMillis = days * 24 * 60 * 60 * 1000L;
return (currentTime - lastModified) < daysInMillis;
}
@Override
protected Void doInBackground(DownloadTaskParams... params) {
int taskType = params[0].type;

View File

@@ -536,7 +536,15 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
for(NSString *fileName in list) {
if (![fileName isEqualToString:curVersion]) {
[_fileManager removeFile:[downloadDir stringByAppendingPathComponent:fileName] completionHandler:nil];
NSString *filePath = [downloadDir stringByAppendingPathComponent:fileName];
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
if (error) {
continue;
}
NSDate *modificationDate = [attributes fileModificationDate];
if ([[NSDate date] timeIntervalSinceDate:modificationDate] > 7 * 24 * 60 * 60) {
[_fileManager removeFile:filePath completionHandler:nil];
}
}
}
}

View File

@@ -21,14 +21,14 @@ const PushyConstants = isTurboModuleEnabled
? PushyModule.getConstants()
: PushyModule;
export const downloadRootDir = PushyConstants.downloadRootDir;
export const packageVersion = PushyConstants.packageVersion;
export const currentVersion = PushyConstants.currentVersion;
export const isFirstTime = PushyConstants.isFirstTime;
export const rolledBackVersion = PushyConstants.rolledBackVersion;
export const isRolledBack = typeof rolledBackVersion === 'string';
export const downloadRootDir: string = PushyConstants.downloadRootDir;
export const packageVersion: string = PushyConstants.packageVersion;
export const currentVersion: string = PushyConstants.currentVersion;
export const isFirstTime: boolean = PushyConstants.isFirstTime;
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
export const buildTime = PushyConstants.buildTime;
export const buildTime: string = PushyConstants.buildTime;
let uuid = PushyConstants.uuid;
if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {

View File

@@ -166,7 +166,7 @@ export const PushyProvider = ({
if (!info) {
return;
}
const rollout = info.config?.rollout;
const rollout = info.config?.rollout?.[packageVersion];
if (rollout) {
if (!isInRollout(rollout)) {
log(`not in ${rollout}% rollout, ignored`);

View File

@@ -8,7 +8,9 @@ export interface CheckResult {
description?: string;
metaInfo?: string;
config?: {
rollout?: number;
rollout?: {
[packageVersion: string]: number;
};
[key: string]: any;
};
pdiff?: string;