mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	add back full update
This commit is contained in:
		| @@ -70,7 +70,7 @@ public class UpdateModule extends ReactContextBaseJavaModule { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void downloadUpdate(ReadableMap options, final Promise promise) { |     public void downloadFullUpdate(ReadableMap options, final Promise promise) { | ||||||
|         String url = options.getString("updateUrl"); |         String url = options.getString("updateUrl"); | ||||||
|         String hash = options.getString("hash"); |         String hash = options.getString("hash"); | ||||||
|         updateContext.downloadFullUpdate(url, hash, new UpdateContext.DownloadFileListener() { |         updateContext.downloadFullUpdate(url, hash, new UpdateContext.DownloadFileListener() { | ||||||
|   | |||||||
| @@ -224,7 +224,7 @@ RCT_EXPORT_METHOD(getLocalHashInfo:(NSString *)hash | |||||||
|     resolve([defaults stringForKey:[keyHashInfo stringByAppendingString:hash]]); |     resolve([defaults stringForKey:[keyHashInfo stringByAppendingString:hash]]); | ||||||
| } | } | ||||||
|  |  | ||||||
| RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options | RCT_EXPORT_METHOD(downloadFullUpdate:(NSDictionary *)options | ||||||
|                   resolver:(RCTPromiseResolveBlock)resolve |                   resolver:(RCTPromiseResolveBlock)resolve | ||||||
|                   rejecter:(RCTPromiseRejectBlock)reject) |                   rejecter:(RCTPromiseRejectBlock)reject) | ||||||
| { | { | ||||||
|   | |||||||
							
								
								
									
										40
									
								
								lib/main.js
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								lib/main.js
									
									
									
									
									
								
							| @@ -95,7 +95,7 @@ export const cInfo = { | |||||||
|  |  | ||||||
| function assertRelease() { | function assertRelease() { | ||||||
|   if (__DEV__) { |   if (__DEV__) { | ||||||
|     throw new Error('react-native-update can only run on RELEASE version.'); |     throw new Error('react-native-update 只能在 RELEASE 版本中运行.'); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -138,7 +138,7 @@ export async function checkUpdate(APPKEY, isRetry) { | |||||||
|     }); |     }); | ||||||
|   } catch (e) { |   } catch (e) { | ||||||
|     if (isRetry) { |     if (isRetry) { | ||||||
|       throw new Error('Could not connect to pushy server'); |       throw new Error('无法连接更新服务器,请检查网络连接后重试'); | ||||||
|     } |     } | ||||||
|     await tryBackupEndpoints(APPKEY); |     await tryBackupEndpoints(APPKEY); | ||||||
|     return checkUpdate(APPKEY, true); |     return checkUpdate(APPKEY, true); | ||||||
| @@ -209,6 +209,7 @@ export async function downloadUpdate(options, eventListeners) { | |||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |   let succeeded = false; | ||||||
|   if (options.diffUrl) { |   if (options.diffUrl) { | ||||||
|     logger('downloading diff'); |     logger('downloading diff'); | ||||||
|     try { |     try { | ||||||
| @@ -217,38 +218,45 @@ export async function downloadUpdate(options, eventListeners) { | |||||||
|         hash: options.hash, |         hash: options.hash, | ||||||
|         originHash: currentVersion, |         originHash: currentVersion, | ||||||
|       }); |       }); | ||||||
|  |       succeeded = true; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       logger(`diff error: ${e.message}, try pdiff`); |       logger(`diff error: ${e.message}, try pdiff`); | ||||||
|       try { |  | ||||||
|         await Pushy.downloadPatchFromPackage({ |  | ||||||
|           updateUrl: options.pdiffUrl, |  | ||||||
|           hash: options.hash, |  | ||||||
|         }); |  | ||||||
|       } catch (e) { |  | ||||||
|         progressHandler && progressHandler.remove(); |  | ||||||
|         report(options.hash, 'error'); |  | ||||||
|         throw e; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   } else if (options.pdiffUrl) { |   if (!succeeded && options.pdiffUrl) { | ||||||
|     logger('downloading pdiff'); |     logger('downloading pdiff'); | ||||||
|     try { |     try { | ||||||
|       await Pushy.downloadPatchFromPackage({ |       await Pushy.downloadPatchFromPackage({ | ||||||
|         updateUrl: options.pdiffUrl, |         updateUrl: options.pdiffUrl, | ||||||
|         hash: options.hash, |         hash: options.hash, | ||||||
|       }); |       }); | ||||||
|  |       succeeded = true; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       progressHandler && progressHandler.remove(); |       logger(`pdiff error: ${e.message}, try full patch`); | ||||||
|       report(options.hash, 'error'); |  | ||||||
|       throw e; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |   if (!succeeded && options.updateUrl) { | ||||||
|  |     logger('downloading full patch'); | ||||||
|  |     try { | ||||||
|  |       await Pushy.downloadFullUpdate({ | ||||||
|  |         updateUrl: options.updateUrl, | ||||||
|  |         hash: options.hash, | ||||||
|  |       }); | ||||||
|  |       succeeded = true; | ||||||
|  |     } catch (e) { | ||||||
|  |       logger(`full patch error: ${e.message}`); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   progressHandler && progressHandler.remove(); | ||||||
|  |   if (!succeeded) { | ||||||
|  |     report(options.hash, 'error'); | ||||||
|  |     throw new Error('all update attempts failed'); | ||||||
|  |   } | ||||||
|   setLocalHashInfo(options.hash, { |   setLocalHashInfo(options.hash, { | ||||||
|     name: options.name, |     name: options.name, | ||||||
|     description: options.description, |     description: options.description, | ||||||
|     metaInfo: options.metaInfo, |     metaInfo: options.metaInfo, | ||||||
|   }); |   }); | ||||||
|   progressHandler && progressHandler.remove(); |  | ||||||
|   downloadedHash = options.hash; |   downloadedHash = options.hash; | ||||||
|   return options.hash; |   return options.hash; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -28,6 +28,6 @@ | |||||||
|   }, |   }, | ||||||
|   "homepage": "https://github.com/reactnativecn/react-native-pushy#readme", |   "homepage": "https://github.com/reactnativecn/react-native-pushy#readme", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "nanoid": "^3.1.30" |     "nanoid": "^3.3.3" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| # yarn lockfile v1 | # yarn lockfile v1 | ||||||
|  |  | ||||||
|  |  | ||||||
| nanoid@^3.1.30: | nanoid@^3.3.3: | ||||||
|   version "3.1.30" |   version "3.3.3" | ||||||
|   resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.30.tgz#63f93cc548d2a113dc5dfbc63bfa09e2b9b64362" |   resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" | ||||||
|   integrity sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ== |   integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm