react-native-update 9.1.6 → 9.2.0
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.
- package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +1 -1
- package/lib/endpoint.ts +16 -9
- package/lib/main.ts +31 -26
- package/lib/type.ts +3 -0
- package/lib/utils.ts +23 -0
- package/package.json +1 -1
|
@@ -57,7 +57,7 @@ public class UpdateModule extends NativeUpdateSpec {
|
|
|
57
57
|
|
|
58
58
|
@Override
|
|
59
59
|
public void downloadFullUpdate(ReadableMap options, final Promise promise) {
|
|
60
|
-
|
|
60
|
+
UpdateModuleImpl.downloadFullUpdate(this.updateContext,options,promise);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
@Override
|
package/lib/endpoint.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { logger } from './utils';
|
|
2
2
|
|
|
3
3
|
let currentEndpoint = 'https://update.react-native.cn/api';
|
|
4
|
-
let backupEndpoints: string[] = [
|
|
5
|
-
|
|
4
|
+
let backupEndpoints: string[] = [
|
|
5
|
+
'https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run',
|
|
6
|
+
'https://update.reactnative.cn/api',
|
|
7
|
+
];
|
|
8
|
+
let backupEndpointsQueryUrls = [
|
|
9
|
+
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
|
|
10
|
+
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json',
|
|
11
|
+
];
|
|
6
12
|
|
|
7
13
|
export async function updateBackupEndpoints() {
|
|
8
|
-
if (
|
|
14
|
+
if (backupEndpointsQueryUrls) {
|
|
9
15
|
try {
|
|
10
|
-
const resp = await
|
|
16
|
+
const resp = await Promise.race(
|
|
17
|
+
backupEndpointsQueryUrls.map((queryUrl) => fetch(queryUrl)),
|
|
18
|
+
);
|
|
11
19
|
const remoteEndpoints = await resp.json();
|
|
12
20
|
if (Array.isArray(remoteEndpoints)) {
|
|
13
21
|
backupEndpoints = Array.from(
|
|
@@ -36,18 +44,17 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) {
|
|
|
36
44
|
export function setCustomEndpoints({
|
|
37
45
|
main,
|
|
38
46
|
backups,
|
|
39
|
-
|
|
47
|
+
backupQueryUrls,
|
|
40
48
|
}: {
|
|
41
49
|
main: string;
|
|
42
50
|
backups?: string[];
|
|
43
|
-
|
|
51
|
+
backupQueryUrls?: string[];
|
|
44
52
|
}) {
|
|
45
53
|
currentEndpoint = main;
|
|
46
|
-
backupEndpointsQueryUrl = null;
|
|
47
54
|
if (Array.isArray(backups) && backups.length > 0) {
|
|
48
55
|
backupEndpoints = backups;
|
|
49
56
|
}
|
|
50
|
-
if (
|
|
51
|
-
|
|
57
|
+
if (Array.isArray(backupQueryUrls) && backupQueryUrls.length > 0) {
|
|
58
|
+
backupEndpointsQueryUrls = backupQueryUrls;
|
|
52
59
|
}
|
|
53
60
|
}
|
package/lib/main.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
UpdateAvailableResult,
|
|
17
17
|
UpdateEventsListener,
|
|
18
18
|
} from './type';
|
|
19
|
-
import { assertRelease, logger } from './utils';
|
|
19
|
+
import { assertRelease, logger, testUrls } from './utils';
|
|
20
20
|
export { setCustomEndpoints };
|
|
21
21
|
const {
|
|
22
22
|
version: v,
|
|
@@ -260,11 +260,12 @@ export async function downloadUpdate(
|
|
|
260
260
|
}
|
|
261
261
|
let succeeded = false;
|
|
262
262
|
report({ type: 'downloading' });
|
|
263
|
-
|
|
263
|
+
const diffUrl = (await testUrls(options.diffUrls)) || options.diffUrl;
|
|
264
|
+
if (diffUrl) {
|
|
264
265
|
logger('downloading diff');
|
|
265
266
|
try {
|
|
266
267
|
await PushyModule.downloadPatchFromPpk({
|
|
267
|
-
updateUrl:
|
|
268
|
+
updateUrl: diffUrl,
|
|
268
269
|
hash: options.hash,
|
|
269
270
|
originHash: currentVersion,
|
|
270
271
|
});
|
|
@@ -273,28 +274,34 @@ export async function downloadUpdate(
|
|
|
273
274
|
logger(`diff error: ${e.message}, try pdiff`);
|
|
274
275
|
}
|
|
275
276
|
}
|
|
276
|
-
if (!succeeded
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
277
|
+
if (!succeeded) {
|
|
278
|
+
const pdiffUrl = (await testUrls(options.pdiffUrls)) || options.pdiffUrl;
|
|
279
|
+
if (pdiffUrl) {
|
|
280
|
+
logger('downloading pdiff');
|
|
281
|
+
try {
|
|
282
|
+
await PushyModule.downloadPatchFromPackage({
|
|
283
|
+
updateUrl: pdiffUrl,
|
|
284
|
+
hash: options.hash,
|
|
285
|
+
});
|
|
286
|
+
succeeded = true;
|
|
287
|
+
} catch (e) {
|
|
288
|
+
logger(`pdiff error: ${e.message}, try full patch`);
|
|
289
|
+
}
|
|
286
290
|
}
|
|
287
291
|
}
|
|
288
|
-
if (!succeeded
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
292
|
+
if (!succeeded) {
|
|
293
|
+
const updateUrl = (await testUrls(options.updateUrls)) || options.updateUrl;
|
|
294
|
+
if (updateUrl) {
|
|
295
|
+
logger('downloading full patch');
|
|
296
|
+
try {
|
|
297
|
+
await PushyModule.downloadFullUpdate({
|
|
298
|
+
updateUrl: updateUrl,
|
|
299
|
+
hash: options.hash,
|
|
300
|
+
});
|
|
301
|
+
succeeded = true;
|
|
302
|
+
} catch (e) {
|
|
303
|
+
logger(`full patch error: ${e.message}`);
|
|
304
|
+
}
|
|
298
305
|
}
|
|
299
306
|
}
|
|
300
307
|
progressHandler && progressHandler.remove();
|
|
@@ -322,12 +329,10 @@ function assertHash(hash: string) {
|
|
|
322
329
|
return true;
|
|
323
330
|
}
|
|
324
331
|
|
|
325
|
-
let applyingUpdate = false;
|
|
326
332
|
export function switchVersion(hash: string) {
|
|
327
333
|
assertRelease();
|
|
328
|
-
if (assertHash(hash)
|
|
334
|
+
if (assertHash(hash)) {
|
|
329
335
|
logger('switchVersion: ' + hash);
|
|
330
|
-
applyingUpdate = true;
|
|
331
336
|
PushyModule.reloadUpdate({ hash });
|
|
332
337
|
}
|
|
333
338
|
}
|
package/lib/type.ts
CHANGED
|
@@ -19,8 +19,11 @@ export interface UpdateAvailableResult {
|
|
|
19
19
|
description: string;
|
|
20
20
|
metaInfo: string;
|
|
21
21
|
pdiffUrl: string;
|
|
22
|
+
pdiffUrls?: string[];
|
|
22
23
|
diffUrl?: string;
|
|
24
|
+
diffUrls?: string[];
|
|
23
25
|
updateUrl?: string;
|
|
26
|
+
updateUrls?: string[];
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export type CheckResult =
|
package/lib/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
1
3
|
export function logger(...args: any[]) {
|
|
2
4
|
console.log('Pushy: ', ...args);
|
|
3
5
|
}
|
|
@@ -7,3 +9,24 @@ export function assertRelease() {
|
|
|
7
9
|
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
|
8
10
|
}
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
const ping =
|
|
14
|
+
Platform.OS === 'web'
|
|
15
|
+
? Promise.resolve
|
|
16
|
+
: async (url: string) =>
|
|
17
|
+
Promise.race([
|
|
18
|
+
fetch(url, {
|
|
19
|
+
method: 'HEAD',
|
|
20
|
+
})
|
|
21
|
+
.then(({ status }) => (status === 200 ? url : null))
|
|
22
|
+
.catch(() => null),
|
|
23
|
+
new Promise(r => setTimeout(() => r(null), 2000)),
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const testUrls = async (urls?: string[]) => {
|
|
28
|
+
if (!urls?.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return Promise.race(urls.map(ping)).catch(() => null);
|
|
32
|
+
};
|