react-native-update 10.38.0-beta.0 → 10.38.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -191,6 +191,39 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
191
191
|
return fout.toByteArray();
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
private void appendManifestEntries(
|
|
195
|
+
JSONObject manifest,
|
|
196
|
+
ArrayList<String> copyFroms,
|
|
197
|
+
ArrayList<String> copyTos,
|
|
198
|
+
ArrayList<String> deletes,
|
|
199
|
+
HashMap<String, String> copiesMap
|
|
200
|
+
) throws JSONException {
|
|
201
|
+
JSONObject copies = manifest.optJSONObject("copies");
|
|
202
|
+
if (copies != null) {
|
|
203
|
+
Iterator<?> keys = copies.keys();
|
|
204
|
+
while (keys.hasNext()) {
|
|
205
|
+
String to = (String) keys.next();
|
|
206
|
+
String from = copies.getString(to);
|
|
207
|
+
if (from.isEmpty()) {
|
|
208
|
+
from = to;
|
|
209
|
+
}
|
|
210
|
+
copyFroms.add(from);
|
|
211
|
+
copyTos.add(to);
|
|
212
|
+
if (copiesMap != null) {
|
|
213
|
+
copiesMap.put(to, from);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
JSONObject deleteMap = manifest.optJSONObject("deletes");
|
|
219
|
+
if (deleteMap != null) {
|
|
220
|
+
Iterator<?> deleteKeys = deleteMap.keys();
|
|
221
|
+
while (deleteKeys.hasNext()) {
|
|
222
|
+
deletes.add((String) deleteKeys.next());
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
194
227
|
private void copyBundledAssetToFile(String assetName, File destination) throws IOException {
|
|
195
228
|
InputStream in = context.getAssets().open(assetName);
|
|
196
229
|
FileOutputStream fout = new FileOutputStream(destination);
|
|
@@ -480,25 +513,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
480
513
|
byte[] bytes = readBytes(zipFile.getInputStream(ze));
|
|
481
514
|
String json = new String(bytes, "UTF-8");
|
|
482
515
|
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
|
483
|
-
|
|
484
|
-
JSONObject copies = obj.getJSONObject("copies");
|
|
485
|
-
Iterator<?> keys = copies.keys();
|
|
486
|
-
while( keys.hasNext() ) {
|
|
487
|
-
String to = (String)keys.next();
|
|
488
|
-
String from = copies.getString(to);
|
|
489
|
-
if (from.isEmpty()) {
|
|
490
|
-
from = to;
|
|
491
|
-
}
|
|
492
|
-
copyFroms.add(from);
|
|
493
|
-
copyTos.add(to);
|
|
494
|
-
// 保存 copies 映射关系(to -> from)
|
|
495
|
-
copiesMap.put(to, from);
|
|
496
|
-
}
|
|
497
|
-
JSONObject blackList = obj.getJSONObject("deletes");
|
|
498
|
-
Iterator<?> deleteKeys = blackList.keys();
|
|
499
|
-
while (deleteKeys.hasNext()) {
|
|
500
|
-
deletes.add((String)deleteKeys.next());
|
|
501
|
-
}
|
|
516
|
+
appendManifestEntries(obj, copyFroms, copyTos, deletes, copiesMap);
|
|
502
517
|
continue;
|
|
503
518
|
}
|
|
504
519
|
zipFile.unzipToPath(ze, param.unzipDirectory);
|
|
@@ -579,23 +594,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|
|
579
594
|
byte[] bytes = readBytes(zipFile.getInputStream(ze));
|
|
580
595
|
String json = new String(bytes, "UTF-8");
|
|
581
596
|
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
|
582
|
-
|
|
583
|
-
JSONObject copies = obj.getJSONObject("copies");
|
|
584
|
-
Iterator<?> keys = copies.keys();
|
|
585
|
-
while( keys.hasNext() ) {
|
|
586
|
-
String to = (String)keys.next();
|
|
587
|
-
String from = copies.getString(to);
|
|
588
|
-
if (from.isEmpty()) {
|
|
589
|
-
from = to;
|
|
590
|
-
}
|
|
591
|
-
copyFroms.add(from);
|
|
592
|
-
copyTos.add(to);
|
|
593
|
-
}
|
|
594
|
-
JSONObject blackList = obj.getJSONObject("deletes");
|
|
595
|
-
Iterator<?> deleteKeys = blackList.keys();
|
|
596
|
-
while (deleteKeys.hasNext()) {
|
|
597
|
-
deletes.add((String)deleteKeys.next());
|
|
598
|
-
}
|
|
597
|
+
appendManifestEntries(obj, copyFroms, copyTos, deletes, null);
|
|
599
598
|
continue;
|
|
600
599
|
}
|
|
601
600
|
zipFile.unzipToPath(ze, param.unzipDirectory);
|
|
@@ -4,8 +4,6 @@ import static androidx.core.content.FileProvider.getUriForFile;
|
|
|
4
4
|
import android.content.Intent;
|
|
5
5
|
import android.net.Uri;
|
|
6
6
|
import android.os.Build;
|
|
7
|
-
import android.os.Handler;
|
|
8
|
-
import android.os.Looper;
|
|
9
7
|
import com.facebook.react.bridge.Promise;
|
|
10
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
9
|
import com.facebook.react.bridge.ReactContext;
|
|
@@ -19,7 +17,6 @@ import java.util.Map;
|
|
|
19
17
|
public class UpdateModule extends NativePushySpec {
|
|
20
18
|
UpdateContext updateContext;
|
|
21
19
|
public static ReactApplicationContext mContext;
|
|
22
|
-
private final Handler handler = new Handler(Looper.getMainLooper());
|
|
23
20
|
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
|
|
24
21
|
super(reactContext);
|
|
25
22
|
this.updateContext = updateContext;
|
|
@@ -43,22 +40,12 @@ public class UpdateModule extends NativePushySpec {
|
|
|
43
40
|
boolean isFirstTime = updateContext.isFirstTime();
|
|
44
41
|
constants.put("isFirstTime", isFirstTime);
|
|
45
42
|
if (isFirstTime) {
|
|
46
|
-
|
|
47
|
-
@Override
|
|
48
|
-
public void run() {
|
|
49
|
-
updateContext.clearFirstTime();
|
|
50
|
-
}
|
|
51
|
-
}, 2000);
|
|
43
|
+
updateContext.clearFirstTime();
|
|
52
44
|
}
|
|
53
45
|
String rolledBackVersion = updateContext.rolledBackVersion();
|
|
54
46
|
constants.put("rolledBackVersion", rolledBackVersion);
|
|
55
47
|
if (rolledBackVersion != null) {
|
|
56
|
-
|
|
57
|
-
@Override
|
|
58
|
-
public void run() {
|
|
59
|
-
updateContext.clearRollbackMark();
|
|
60
|
-
}
|
|
61
|
-
}, 2000);
|
|
48
|
+
updateContext.clearRollbackMark();
|
|
62
49
|
}
|
|
63
50
|
constants.put("uuid", updateContext.getKv("uuid"));
|
|
64
51
|
return constants;
|
package/package.json
CHANGED
package/src/__tests__/setup.ts
CHANGED
package/src/client.ts
CHANGED
|
@@ -42,8 +42,7 @@ import { dedupeEndpoints, executeEndpointFallback } from './endpoint';
|
|
|
42
42
|
const SERVER_PRESETS = {
|
|
43
43
|
// cn
|
|
44
44
|
Pushy: {
|
|
45
|
-
main: 'https://update.react-native.cn/api',
|
|
46
|
-
backups: ['https://update.reactnative.cn/api'],
|
|
45
|
+
main: ['https://update.react-native.cn/api', 'https://update.reactnative.cn/api'],
|
|
47
46
|
queryUrls: [
|
|
48
47
|
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
|
|
49
48
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints.json',
|
|
@@ -51,14 +50,26 @@ const SERVER_PRESETS = {
|
|
|
51
50
|
},
|
|
52
51
|
// i18n
|
|
53
52
|
Cresc: {
|
|
54
|
-
main: 'https://api.cresc.dev',
|
|
55
|
-
backups: ['https://api.cresc.app'],
|
|
53
|
+
main: ['https://api.cresc.dev', 'https://api.cresc.app'],
|
|
56
54
|
queryUrls: [
|
|
57
55
|
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints_cresc.json',
|
|
58
56
|
],
|
|
59
57
|
},
|
|
60
58
|
};
|
|
61
59
|
|
|
60
|
+
const cloneServerConfig = (server: UpdateServerConfig): UpdateServerConfig => ({
|
|
61
|
+
main: dedupeEndpoints([...(server.main || [])]),
|
|
62
|
+
queryUrls: server.queryUrls ? [...server.queryUrls] : undefined,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const excludeConfiguredEndpoints = (
|
|
66
|
+
endpoints: string[],
|
|
67
|
+
configuredEndpoints: string[],
|
|
68
|
+
) => {
|
|
69
|
+
const configured = new Set(configuredEndpoints);
|
|
70
|
+
return endpoints.filter(endpoint => !configured.has(endpoint));
|
|
71
|
+
};
|
|
72
|
+
|
|
62
73
|
assertWeb();
|
|
63
74
|
|
|
64
75
|
const defaultClientOptions: ClientOptions = {
|
|
@@ -71,19 +82,6 @@ const defaultClientOptions: ClientOptions = {
|
|
|
71
82
|
throwError: false,
|
|
72
83
|
};
|
|
73
84
|
|
|
74
|
-
const cloneServerConfig = (
|
|
75
|
-
server?: UpdateServerConfig,
|
|
76
|
-
): UpdateServerConfig | undefined => {
|
|
77
|
-
if (!server) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
main: server.main,
|
|
82
|
-
backups: server.backups ? [...server.backups] : undefined,
|
|
83
|
-
queryUrls: server.queryUrls ? [...server.queryUrls] : undefined,
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
85
|
export const sharedState: {
|
|
88
86
|
progressHandlers: Record<string, EmitterSubscription>;
|
|
89
87
|
downloadedHash?: string;
|
|
@@ -209,7 +207,7 @@ export class Pushy {
|
|
|
209
207
|
throw e;
|
|
210
208
|
}
|
|
211
209
|
};
|
|
212
|
-
getCheckUrl = (endpoint: string
|
|
210
|
+
getCheckUrl = (endpoint: string) => {
|
|
213
211
|
return `${endpoint}/checkUpdate/${this.options.appKey}`;
|
|
214
212
|
};
|
|
215
213
|
getConfiguredCheckEndpoints = () => {
|
|
@@ -217,7 +215,7 @@ export class Pushy {
|
|
|
217
215
|
if (!server) {
|
|
218
216
|
return [];
|
|
219
217
|
}
|
|
220
|
-
return dedupeEndpoints(
|
|
218
|
+
return dedupeEndpoints(server.main);
|
|
221
219
|
};
|
|
222
220
|
getRemoteEndpoints = async () => {
|
|
223
221
|
const { server } = this.options;
|
|
@@ -233,16 +231,14 @@ export class Pushy {
|
|
|
233
231
|
const remoteEndpoints = await resp.json();
|
|
234
232
|
log('fetch endpoints:', remoteEndpoints);
|
|
235
233
|
if (Array.isArray(remoteEndpoints)) {
|
|
236
|
-
|
|
234
|
+
return excludeConfiguredEndpoints(
|
|
235
|
+
dedupeEndpoints(
|
|
237
236
|
remoteEndpoints.filter(
|
|
238
237
|
(endpoint): endpoint is string => typeof endpoint === 'string',
|
|
239
238
|
),
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
...normalizedRemoteEndpoints,
|
|
244
|
-
]).filter(endpoint => endpoint !== server.main);
|
|
245
|
-
return normalizedRemoteEndpoints;
|
|
239
|
+
),
|
|
240
|
+
this.getConfiguredCheckEndpoints(),
|
|
241
|
+
);
|
|
246
242
|
}
|
|
247
243
|
} catch (e) {
|
|
248
244
|
log('failed to fetch endpoints from: ', server.queryUrls, e);
|
|
@@ -410,8 +406,9 @@ export class Pushy {
|
|
|
410
406
|
return [];
|
|
411
407
|
}
|
|
412
408
|
const remoteEndpoints = await this.getRemoteEndpoints();
|
|
413
|
-
return
|
|
414
|
-
|
|
409
|
+
return excludeConfiguredEndpoints(
|
|
410
|
+
dedupeEndpoints(remoteEndpoints),
|
|
411
|
+
this.getConfiguredCheckEndpoints(),
|
|
415
412
|
);
|
|
416
413
|
};
|
|
417
414
|
downloadUpdate = async (
|