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

Compare commits

..

22 Commits

Author SHA1 Message Date
sunnylqm
3ea6b1d08d v7.4.0 2022-04-27 22:29:55 +08:00
sunnylqm
ea1a8dfad2 add back full update 2022-04-27 21:52:38 +08:00
Sunny Luo
ead8f8cac5 Merge pull request #392 from npmmirror/master
Update https://registry.npm.taobao.org to https://registry.npmmirror.com
2022-02-15 21:36:46 +08:00
NPM Mirror Bot
b424fc6041 update https://registry.npm.taobao.org to https://registry.npmmirror.com 2022-02-12 07:35:22 +00:00
sunnylqm
d76e8052f5 v7.4.0-beta.0 2022-01-19 21:30:56 +08:00
sunnylqm
3ebf6e95c9 Try fix safezip for google play 2022-01-19 21:29:35 +08:00
sunnylqm
2ae4180840 v7.3.8 2021-11-22 18:12:02 +08:00
sunnylqm
ec0a9e0a3e Revert "Update pod script path"
This reverts commit fddae3d79a.
2021-11-11 18:46:48 +08:00
sunnylqm
b34b70ed01 v7.3.6 2021-11-11 18:09:21 +08:00
sunnylqm
fddae3d79a Update pod script path 2021-11-11 18:08:49 +08:00
sunnylqm
7fc0d717d5 v7.3.5 2021-11-10 22:31:56 +08:00
sunnylqm
686209d50e Check stateListener 2021-11-10 22:31:23 +08:00
sunnylqm
80b0401b02 v7.3.4 2021-11-04 17:53:05 +08:00
sunnylqm
786d32d92f Fix simpleUpdate 2021-11-04 17:52:30 +08:00
sunnylqm
27327dbe12 v7.3.3 2021-11-04 16:40:35 +08:00
sunnylqm
96a81cc36d Improve download exception handling 2021-11-04 16:39:50 +08:00
sunnylqm
0aa063c584 v7.3.2 2021-11-04 16:36:06 +08:00
sunnylqm
4d72d49fe4 Chech downloaded hash 2021-11-04 16:35:34 +08:00
sunnylqm
53d07406ef v7.3.1 2021-10-30 14:56:58 +08:00
sunnylqm
d0804cfe15 Fix rolledBackVersion 2021-10-30 14:56:23 +08:00
sunnylqm
35939286d0 v7.3.0 2021-10-29 13:03:34 +08:00
sunnylqm
f49ce30cef Fix assertHash 2021-10-29 13:02:49 +08:00
10 changed files with 62 additions and 73 deletions

View File

@@ -1 +1 @@
registry=https://registry.npm.taobao.org/
registry=https://registry.npmmirror.com/

View File

@@ -68,6 +68,9 @@ export default class App extends Component {
});
},
});
if (!hash) {
return;
}
Alert.alert('提示', '下载完毕,是否重启应用?', [
{
text: '是',

View File

@@ -16,40 +16,6 @@ public class SafeZipFile extends ZipFile {
super(file);
}
@Override
public Enumeration<? extends ZipEntry> entries() {
return new SafeZipEntryIterator(super.entries());
}
private static class SafeZipEntryIterator implements Enumeration<ZipEntry> {
final private Enumeration<? extends ZipEntry> delegate;
private SafeZipEntryIterator(Enumeration<? extends ZipEntry> delegate) {
this.delegate = delegate;
}
@Override
public boolean hasMoreElements() {
return delegate.hasMoreElements();
}
@Override
public ZipEntry nextElement() {
ZipEntry entry = delegate.nextElement();
if (null != entry) {
String name = entry.getName();
/**
* avoid ZipperDown
*/
if (null != name && (name.contains("../") || name.contains("..\\"))) {
throw new SecurityException("illegal entry: " + entry.getName());
}
}
return entry;
}
}
public void unzipToFile(ZipEntry entry, File output) throws IOException {
InputStream inputStream = null;
try {
@@ -63,6 +29,11 @@ public class SafeZipFile extends ZipFile {
}
private void writeOutInputStream(File file, InputStream inputStream) throws IOException {
// https://support.google.com/faqs/answer/9294009
String canonicalPath = file.getCanonicalPath();
if (!canonicalPath.startsWith(UpdateContext.getRootDir())) {
throw new SecurityException("illegal entry: " + file.getName());
}
BufferedOutputStream output = null;
try {
output = new BufferedOutputStream(

View File

@@ -19,13 +19,14 @@ import java.io.File;
public class UpdateContext {
private Context context;
private File rootDir;
private static File rootDir;
private Executor executor;
public static boolean DEBUG = false;
private static ReactInstanceManager mReactInstanceManager;
private static boolean isUsingBundleUrl = false;
public UpdateContext(Context context) {
this.context = context;
this.executor = Executors.newSingleThreadExecutor();
@@ -49,7 +50,7 @@ public class UpdateContext {
}
}
public String getRootDir() {
public static String getRootDir() {
return rootDir.toString();
}

View File

@@ -70,7 +70,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
}
@ReactMethod
public void downloadUpdate(ReadableMap options, final Promise promise) {
public void downloadFullUpdate(ReadableMap options, final Promise promise) {
String url = options.getString("updateUrl");
String hash = options.getString("hash");
updateContext.downloadFullUpdate(url, hash, new UpdateContext.DownloadFileListener() {

View File

@@ -224,7 +224,7 @@ RCT_EXPORT_METHOD(getLocalHashInfo:(NSString *)hash
resolve([defaults stringForKey:[keyHashInfo stringByAppendingString:hash]]);
}
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options
RCT_EXPORT_METHOD(downloadFullUpdate:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{

View File

@@ -95,7 +95,7 @@ export const cInfo = {
function assertRelease() {
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) {
if (isRetry) {
throw new Error('Could not connect to pushy server');
throw new Error('无法连接更新服务器,请检查网络连接后重试');
}
await tryBackupEndpoints(APPKEY);
return checkUpdate(APPKEY, true);
@@ -175,8 +175,8 @@ export async function downloadUpdate(options, eventListeners) {
if (!options.update) {
return;
}
if (rolledbackVersion === options.hash) {
logger(`rolledback hash ${rolledbackVersion}, ignored`);
if (rolledBackVersion === options.hash) {
logger(`rolledback hash ${rolledBackVersion}, ignored`);
return;
}
if (downloadedHash === options.hash) {
@@ -209,6 +209,7 @@ export async function downloadUpdate(options, eventListeners) {
);
}
}
let succeeded = false;
if (options.diffUrl) {
logger('downloading diff');
try {
@@ -217,38 +218,45 @@ export async function downloadUpdate(options, eventListeners) {
hash: options.hash,
originHash: currentVersion,
});
succeeded = true;
} catch (e) {
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');
return;
}
}
} else if (options.pdiffUrl) {
}
if (!succeeded && options.pdiffUrl) {
logger('downloading pdiff');
try {
await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
succeeded = true;
} catch (e) {
progressHandler && progressHandler.remove();
report(options.hash, 'error');
return;
logger(`pdiff error: ${e.message}, try full patch`);
}
}
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, {
name: options.name,
description: options.description,
metaInfo: options.metaInfo,
});
progressHandler && progressHandler.remove();
downloadedHash = options.hash;
return options.hash;
}
@@ -268,20 +276,23 @@ function assertHash(hash) {
return;
}
readyHash = hash;
return true;
}
export function switchVersion(hash) {
assertRelease();
assertHash(hash);
logger('switchVersion: ' + hash);
Pushy.reloadUpdate({ hash });
if (assertHash(hash)) {
logger('switchVersion: ' + hash);
Pushy.reloadUpdate({ hash });
}
}
export function switchVersionLater(hash) {
assertRelease();
assertHash(hash);
logger('switchVersionLater: ' + hash);
Pushy.setNeedUpdate({ hash });
if (assertHash(hash)) {
logger('switchVersionLater: ' + hash);
Pushy.setNeedUpdate({ hash });
}
}
let marked = false;

View File

@@ -36,12 +36,15 @@ export function simpleUpdate(WrappedComponent) {
this.checkUpdate();
}
componentWillUnmount() {
this.stateListener.remove();
this.stateListener && this.stateListener.remove();
}
doUpdate = async (info) => {
try {
const hash = await downloadUpdate(info);
this.stateListener.remove();
if (!hash) {
return;
}
this.stateListener && this.stateListener.remove();
Alert.alert('提示', '下载完毕,是否立即更新?', [
{
text: '以后再说',
@@ -91,7 +94,7 @@ export function simpleUpdate(WrappedComponent) {
},
},
]);
} else {
} else if (info.update) {
Alert.alert(
'提示',
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "7.2.0",
"version": "7.4.0",
"description": "react-native hot update",
"main": "lib/index.js",
"scripts": {
@@ -28,6 +28,6 @@
},
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
"dependencies": {
"nanoid": "^3.1.28"
"nanoid": "^3.3.3"
}
}

View File

@@ -2,7 +2,7 @@
# yarn lockfile v1
nanoid@^3.1.28:
version "3.1.28"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.28.tgz#3c01bac14cb6c5680569014cc65a2f26424c6bd4"
integrity sha512-gSu9VZ2HtmoKYe/lmyPFES5nknFrHa+/DT9muUFWFMi6Jh9E1I7bkvlQ8xxf1Kos9pi9o8lBnIOkatMhKX/YUw==
nanoid@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25"
integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==