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

Rename hashname -> hash

This commit is contained in:
sunnylqm 2020-09-24 22:44:37 +08:00
parent bcd61315e9
commit 17dffa1eb5
5 changed files with 51 additions and 52 deletions

View File

@ -90,50 +90,50 @@ public class UpdateContext {
void onDownloadFailed(Throwable error); void onDownloadFailed(Throwable error);
} }
public void downloadFile(String url, String hashName, DownloadFileListener listener) { public void downloadFile(String url, String hash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams(); DownloadTaskParams params = new DownloadTaskParams();
params.type = DownloadTaskParams.TASK_TYPE_FULL_DOWNLOAD; params.type = DownloadTaskParams.TASK_TYPE_FULL_DOWNLOAD;
params.url = url; params.url = url;
params.hash = hashName; params.hash = hash;
params.listener = listener; params.listener = listener;
params.zipFilePath = new File(rootDir, hashName + ".ppk"); params.zipFilePath = new File(rootDir, hash + ".ppk");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hash);
new DownloadTask(context).executeOnExecutor(this.executor, params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
public void downloadPatchFromApk(String url, String hashName, DownloadFileListener listener) { public void downloadPatchFromApk(String url, String hash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams(); DownloadTaskParams params = new DownloadTaskParams();
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK; params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK;
params.url = url; params.url = url;
params.hash = hashName; params.hash = hash;
params.listener = listener; params.listener = listener;
params.zipFilePath = new File(rootDir, hashName + ".apk.patch"); params.zipFilePath = new File(rootDir, hash + ".apk.patch");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hash);
new DownloadTask(context).executeOnExecutor(this.executor, params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
public void downloadPatchFromPpk(String url, String hashName, String originHashName, DownloadFileListener listener) { public void downloadPatchFromPpk(String url, String hash, String originHash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams(); DownloadTaskParams params = new DownloadTaskParams();
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK; params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
params.url = url; params.url = url;
params.hash = hashName; params.hash = hash;
params.originHash = originHashName; params.originHash = originHash;
params.listener = listener; params.listener = listener;
params.zipFilePath = new File(rootDir, originHashName + "-" + hashName + ".ppk.patch"); params.zipFilePath = new File(rootDir, originHash + "-" + hash + ".ppk.patch");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hash);
params.originDirectory = new File(rootDir, originHashName); params.originDirectory = new File(rootDir, originHash);
new DownloadTask(context).executeOnExecutor(this.executor, params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
private SharedPreferences sp; private SharedPreferences sp;
public void switchVersion(String hashName) { public void switchVersion(String hash) {
if (!new File(rootDir, hashName+"/index.bundlejs").exists()) { if (!new File(rootDir, hash+"/index.bundlejs").exists()) {
throw new Error("Bundle version " + hashName + " not found."); throw new Error("Bundle version " + hash + " not found.");
} }
String lastVersion = getCurrentVersion(); String lastVersion = getCurrentVersion();
SharedPreferences.Editor editor = sp.edit(); SharedPreferences.Editor editor = sp.edit();
editor.putString("currentVersion", hashName); editor.putString("currentVersion", hash);
if (lastVersion != null) { if (lastVersion != null) {
editor.putString("lastVersion", lastVersion); editor.putString("lastVersion", lastVersion);
} }

View File

@ -70,7 +70,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
@ReactMethod @ReactMethod
public void downloadUpdate(ReadableMap options, final Promise promise){ public void downloadUpdate(ReadableMap options, final Promise promise){
String url = options.getString("updateUrl"); String url = options.getString("updateUrl");
String hash = options.getString("hashName"); String hash = options.getString("hash");
updateContext.downloadFile(url, hash, new UpdateContext.DownloadFileListener() { updateContext.downloadFile(url, hash, new UpdateContext.DownloadFileListener() {
@Override @Override
public void onDownloadCompleted() { public void onDownloadCompleted() {
@ -87,7 +87,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
@ReactMethod @ReactMethod
public void downloadPatchFromPackage(ReadableMap options, final Promise promise){ public void downloadPatchFromPackage(ReadableMap options, final Promise promise){
String url = options.getString("updateUrl"); String url = options.getString("updateUrl");
String hash = options.getString("hashName"); String hash = options.getString("hash");
updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() { updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() {
@Override @Override
public void onDownloadCompleted() { public void onDownloadCompleted() {
@ -104,8 +104,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{
@ReactMethod @ReactMethod
public void downloadPatchFromPpk(ReadableMap options, final Promise promise){ public void downloadPatchFromPpk(ReadableMap options, final Promise promise){
String url = options.getString("updateUrl"); String url = options.getString("updateUrl");
String hash = options.getString("hashName"); String hash = options.getString("hash");
String originHash = options.getString("originHashName"); String originHash = options.getString("originHash");
updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() { updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() {
@Override @Override
public void onDownloadCompleted() { public void onDownloadCompleted() {
@ -121,7 +121,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
@ReactMethod @ReactMethod
public void reloadUpdate(ReadableMap options) { public void reloadUpdate(ReadableMap options) {
final String hash = options.getString("hashName"); final String hash = options.getString("hash");
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
@ -162,7 +162,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
@ReactMethod @ReactMethod
public void setNeedUpdate(ReadableMap options) { public void setNeedUpdate(ReadableMap options) {
final String hash = options.getString("hashName"); final String hash = options.getString("hash");
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override

View File

@ -44,7 +44,7 @@ static NSString * const ERROR_FILE_OPERATION = @"file operation error";
// event def // event def
static NSString * const EVENT_PROGRESS_DOWNLOAD = @"RCTPushyDownloadProgress"; static NSString * const EVENT_PROGRESS_DOWNLOAD = @"RCTPushyDownloadProgress";
// static NSString * const EVENT_PROGRESS_UNZIP = @"RCTPushyUnzipProgress"; // static NSString * const EVENT_PROGRESS_UNZIP = @"RCTPushyUnzipProgress";
static NSString * const PARAM_PROGRESS_HASHNAME = @"hash"; static NSString * const PARAM_PROGRESS_HASH = @"hash";
static NSString * const PARAM_PROGRESS_RECEIVED = @"received"; static NSString * const PARAM_PROGRESS_RECEIVED = @"received";
static NSString * const PARAM_PROGRESS_TOTAL = @"total"; static NSString * const PARAM_PROGRESS_TOTAL = @"total";
@ -248,8 +248,8 @@ RCT_EXPORT_METHOD(downloadPatchFromPpk:(NSDictionary *)options
RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options) RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options)
{ {
NSString *hashName = options[@"hashName"]; NSString *hash = options[@"hash"];
if (hashName.length) { if (hash.length) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = nil; NSString *lastVersion = nil;
if ([defaults objectForKey:keyPushyInfo]) { if ([defaults objectForKey:keyPushyInfo]) {
@ -258,7 +258,7 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options)
} }
NSMutableDictionary *newInfo = [[NSMutableDictionary alloc] init]; NSMutableDictionary *newInfo = [[NSMutableDictionary alloc] init];
newInfo[paramCurrentVersion] = hashName; newInfo[paramCurrentVersion] = hash;
newInfo[paramLastVersion] = lastVersion; newInfo[paramLastVersion] = lastVersion;
newInfo[paramIsFirstTime] = @(YES); newInfo[paramIsFirstTime] = @(YES);
newInfo[paramIsFirstLoadOk] = @(NO); newInfo[paramIsFirstLoadOk] = @(NO);
@ -271,8 +271,8 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options)
RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options) RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options)
{ {
NSString *hashName = options[@"hashName"]; NSString *hash = options[@"hash"];
if (hashName.length) { if (hash.length) {
[self setNeedUpdate:options]; [self setNeedUpdate:options];
// reload 0.62+ // reload 0.62+
@ -327,13 +327,13 @@ RCT_EXPORT_METHOD(markSuccess)
- (void)doPushy:(PushyType)type options:(NSDictionary *)options callback:(void (^)(NSError *error))callback - (void)doPushy:(PushyType)type options:(NSDictionary *)options callback:(void (^)(NSError *error))callback
{ {
NSString *updateUrl = [RCTConvert NSString:options[@"updateUrl"]]; NSString *updateUrl = [RCTConvert NSString:options[@"updateUrl"]];
NSString *hashName = [RCTConvert NSString:options[@"hashName"]]; NSString *hash = [RCTConvert NSString:options[@"hash"]];
if (updateUrl.length<=0 || hashName.length<=0) { if (updateUrl.length <= 0 || hash.length <= 0) {
callback([self errorWithMessage:ERROR_OPTIONS]); callback([self errorWithMessage:ERROR_OPTIONS]);
return; return;
} }
NSString *originHashName = [RCTConvert NSString:options[@"originHashName"]]; NSString *originHash = [RCTConvert NSString:options[@"originHash"]];
if (type == PushyTypePatchFromPpk && originHashName<=0) { if (type == PushyTypePatchFromPpk && originHash <= 0) {
callback([self errorWithMessage:ERROR_OPTIONS]); callback([self errorWithMessage:ERROR_OPTIONS]);
return; return;
} }
@ -345,14 +345,14 @@ RCT_EXPORT_METHOD(markSuccess)
return; return;
} }
NSString *zipFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@",hashName, [self zipExtension:type]]]; NSString *zipFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@",hash, [self zipExtension:type]]];
// NSString *unzipDir = [dir stringByAppendingPathComponent:hashName]; // NSString *unzipDir = [dir stringByAppendingPathComponent:hash];
RCTLogInfo(@"RCTPushy -- download file %@", updateUrl); RCTLogInfo(@"RCTPushy -- download file %@", updateUrl);
[RCTPushyDownloader download:updateUrl savePath:zipFilePath progressHandler:^(long long receivedBytes, long long totalBytes) { [RCTPushyDownloader download:updateUrl savePath:zipFilePath progressHandler:^(long long receivedBytes, long long totalBytes) {
if (self->hasListeners) { if (self->hasListeners) {
[self sendEventWithName:EVENT_PROGRESS_DOWNLOAD body:@{ [self sendEventWithName:EVENT_PROGRESS_DOWNLOAD body:@{
PARAM_PROGRESS_HASHNAME:hashName, PARAM_PROGRESS_HASH:hash,
PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLongLong:receivedBytes], PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLongLong:receivedBytes],
PARAM_PROGRESS_TOTAL:[NSNumber numberWithLongLong:totalBytes] PARAM_PROGRESS_TOTAL:[NSNumber numberWithLongLong:totalBytes]
}]; }];
@ -363,12 +363,12 @@ RCT_EXPORT_METHOD(markSuccess)
} }
else { else {
RCTLogInfo(@"RCTPushy -- unzip file %@", zipFilePath); RCTLogInfo(@"RCTPushy -- unzip file %@", zipFilePath);
NSString *unzipFilePath = [dir stringByAppendingPathComponent:hashName]; NSString *unzipFilePath = [dir stringByAppendingPathComponent:hash];
[self->_fileManager unzipFileAtPath:zipFilePath toDestination:unzipFilePath progressHandler:^(NSString *entry,long entryNumber, long total) { [self->_fileManager unzipFileAtPath:zipFilePath toDestination:unzipFilePath progressHandler:^(NSString *entry,long entryNumber, long total) {
// if (self->hasListeners) { // if (self->hasListeners) {
// [self sendEventWithName:EVENT_PROGRESS_UNZIP // [self sendEventWithName:EVENT_PROGRESS_UNZIP
// body:@{ // body:@{
// PARAM_PROGRESS_HASHNAME:hashName, // PARAM_PROGRESS_HASH:hash,
// PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLong:entryNumber], // PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLong:entryNumber],
// PARAM_PROGRESS_TOTAL:[NSNumber numberWithLong:total] // PARAM_PROGRESS_TOTAL:[NSNumber numberWithLong:total]
// }]; // }];
@ -385,16 +385,16 @@ RCT_EXPORT_METHOD(markSuccess)
{ {
NSString *sourceOrigin = [[NSBundle mainBundle] resourcePath]; NSString *sourceOrigin = [[NSBundle mainBundle] resourcePath];
NSString *bundleOrigin = [[RCTPushy binaryBundleURL] path]; NSString *bundleOrigin = [[RCTPushy binaryBundleURL] path];
[self patch:hashName fromBundle:bundleOrigin source:sourceOrigin callback:callback]; [self patch:hash fromBundle:bundleOrigin source:sourceOrigin callback:callback];
} }
break; break;
case PushyTypePatchFromPpk: case PushyTypePatchFromPpk:
{ {
NSString *lastVersionDir = [dir stringByAppendingPathComponent:originHashName]; NSString *lastVersionDir = [dir stringByAppendingPathComponent:originHash];
NSString *sourceOrigin = lastVersionDir; NSString *sourceOrigin = lastVersionDir;
NSString *bundleOrigin = [lastVersionDir stringByAppendingPathComponent:BUNDLE_FILE_NAME]; NSString *bundleOrigin = [lastVersionDir stringByAppendingPathComponent:BUNDLE_FILE_NAME];
[self patch:hashName fromBundle:bundleOrigin source:sourceOrigin callback:callback]; [self patch:hash fromBundle:bundleOrigin source:sourceOrigin callback:callback];
} }
break; break;
default: default:
@ -408,9 +408,9 @@ RCT_EXPORT_METHOD(markSuccess)
}]; }];
} }
- (void)patch:(NSString *)hashName fromBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback - (void)patch:(NSString *)hash fromBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback
{ {
NSString *unzipDir = [[RCTPushy downloadDir] stringByAppendingPathComponent:hashName]; NSString *unzipDir = [[RCTPushy downloadDir] stringByAppendingPathComponent:hash];
NSString *sourcePatch = [unzipDir stringByAppendingPathComponent:SOURCE_PATCH_NAME]; NSString *sourcePatch = [unzipDir stringByAppendingPathComponent:SOURCE_PATCH_NAME];
NSString *bundlePatch = [unzipDir stringByAppendingPathComponent:BUNDLE_PATCH_NAME]; NSString *bundlePatch = [unzipDir stringByAppendingPathComponent:BUNDLE_PATCH_NAME];

2
lib/index.d.ts vendored
View File

@ -60,7 +60,7 @@ export function setCustomEndpoints({
}): void; }): void;
interface ProgressData { interface ProgressData {
hashname: string; hash: string;
received: number; received: number;
total: number; total: number;
} }

View File

@ -9,7 +9,6 @@ const {
version: v, version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion'); } = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`; const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const uuidv4 = require('uuid/v4');
let Pushy = NativeModules.Pushy; let Pushy = NativeModules.Pushy;
@ -35,7 +34,7 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) {
const eventEmitter = new NativeEventEmitter(Pushy); const eventEmitter = new NativeEventEmitter(Pushy);
if (!uuid) { if (!uuid) {
uuid = uuidv4(); uuid = require('uuid/v4')();
Pushy.setUuid(uuid); Pushy.setUuid(uuid);
} }
@ -158,14 +157,14 @@ export async function downloadUpdate(options, eventListeners) {
logger('downloading diff'); logger('downloading diff');
await Pushy.downloadPatchFromPpk({ await Pushy.downloadPatchFromPpk({
updateUrl: options.diffUrl, updateUrl: options.diffUrl,
hashName: options.hash, hash: options.hash,
originHashName: currentVersion, originHash: currentVersion,
}); });
} else if (options.pdiffUrl) { } else if (options.pdiffUrl) {
logger('downloading pdiff'); logger('downloading pdiff');
await Pushy.downloadPatchFromPackage({ await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl, updateUrl: options.pdiffUrl,
hashName: options.hash, hash: options.hash,
}); });
} }
eventEmitter.removeAllListeners('RCTPushyDownloadProgress'); eventEmitter.removeAllListeners('RCTPushyDownloadProgress');
@ -175,13 +174,13 @@ export async function downloadUpdate(options, eventListeners) {
export function switchVersion(hash) { export function switchVersion(hash) {
assertRelease(); assertRelease();
logger('switchVersion'); logger('switchVersion');
Pushy.reloadUpdate({ hashName: hash }); Pushy.reloadUpdate({ hash });
} }
export function switchVersionLater(hash) { export function switchVersionLater(hash) {
assertRelease(); assertRelease();
logger('switchVersionLater'); logger('switchVersionLater');
Pushy.setNeedUpdate({ hashName: hash }); Pushy.setNeedUpdate({ hash });
} }
export function markSuccess() { export function markSuccess() {