@onekeyfe/hd-core 1.1.16-alpha.6 → 1.1.16-alpha.8
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/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
- package/dist/index.js +62 -13
- package/package.json +4 -4
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +28 -4
- package/src/api/firmware/uploadFirmware.ts +26 -4
- package/src/api/helpers/paramsValidator.ts +11 -2
|
@@ -4,6 +4,7 @@ import { RebootType } from '@onekeyfe/hd-transport';
|
|
|
4
4
|
import { IFirmwareUpdateTipMessage, IFirmwareUpdateProgressType } from '../../events/ui-request';
|
|
5
5
|
import { BaseMethod } from '../BaseMethod';
|
|
6
6
|
import { PROTO } from '../../constants';
|
|
7
|
+
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
7
8
|
export declare class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
8
9
|
checkPromise: Deferred<any> | null;
|
|
9
10
|
init(): void;
|
|
@@ -25,7 +26,7 @@ export declare class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params>
|
|
|
25
26
|
processedSize?: number;
|
|
26
27
|
totalSize?: number;
|
|
27
28
|
}): Promise<number>;
|
|
28
|
-
emmcFileWriteWithRetry(filePath: string, chunkLength: number, offset: number, chunk: ArrayBuffer | Buffer, overwrite: boolean, progress: number | null): Promise<
|
|
29
|
+
emmcFileWriteWithRetry(filePath: string, chunkLength: number, offset: number, chunk: ArrayBuffer | Buffer, overwrite: boolean, progress: number | null): Promise<TypedResponseMessage<"EmmcFile"> | undefined>;
|
|
29
30
|
reboot(rebootType: RebootType): Promise<import("@onekeyfe/hd-transport").Success>;
|
|
30
31
|
}
|
|
31
32
|
//# sourceMappingURL=FirmwareUpdateBaseMethod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateBaseMethod.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/FirmwareUpdateBaseMethod.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAIL,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"FirmwareUpdateBaseMethod.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/FirmwareUpdateBaseMethod.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAIL,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAexE,qBAAa,wBAAwB,CAAC,MAAM,CAAE,SAAQ,UAAU,CAAC,MAAM,CAAC;IACtE,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI,IAAI,IAAI;IAEZ,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAInB,cAAc,IAAI,OAAO;IASzB,cAAc,YAAa,yBAAyB,UASlD;IAMF,qBAAqB,SAAU,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,UAAU,UAM3E;IAMF,mBAAmB,aAAc,MAAM,gBAAgB,2BAA2B,UAQhF;YAEY,qCAAqC;IAkBnD,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;YAmFvC,4BAA4B;IAuBpC,mBAAmB;IA8CnB,uBAAuB,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IA6BlD,8BAA8B,CAAC,IAAI,EAAE,MAAM;IAW3C,uBAAuB,CAAC,EAC5B,OAAO,EACP,QAAQ,EACR,aAAa,EACb,SAAS,GACV,EAAE,KAAK,CAAC,cAAc,GAAG;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IA4CK,sBAAsB,CAC1B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,WAAW,GAAG,MAAM,EAC3B,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,GAAG,IAAI;IAwEnB,MAAM,CAAC,UAAU,EAAE,UAAU;CAsBpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAQjD,OAAO,EAEL,WAAW,EAIZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"uploadFirmware.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/uploadFirmware.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAQjD,OAAO,EAEL,WAAW,EAIZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,6BAA6B,CAAC;AAqEnF,eAAO,MAAM,cAAc,eAAsB,MAAM,kBAKtD,CAAC;AAEF,eAAO,MAAM,cAAc,eACb,UAAU,GAAG,KAAK,aACnB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM;;sBAsFf,CAAC;AA+NF,eAAO,MAAM,cAAc,cACd,SAAS,YACV,MAAM,QACV,WAAW,mBACA,MAAM,IAAI,qBAc5B,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAwBpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAChB,SAAS,yBACG,WAAW,KAAK,IAAI,UACnC,MAAM,UACN,WAAW,qBAUpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paramsValidator.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/paramsValidator.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EACD,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,WAAW,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAQF,eAAO,MAAM,cAAc,WAAY,GAAG,UAAU,MAAM,WAAW,CAAC,KAAG,
|
|
1
|
+
{"version":3,"file":"paramsValidator.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/paramsValidator.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EACD,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,WAAW,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAQF,eAAO,MAAM,cAAc,WAAY,GAAG,UAAU,MAAM,WAAW,CAAC,KAAG,IAyGxE,CAAC;AAEF,wBAAgB,cAAc,CAC5B,MAAM,EAAE,GAAG,EACX,iBAAiB,EAAE,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE;IACR,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CAC5C,QAwBF"}
|
package/dist/index.js
CHANGED
|
@@ -28064,14 +28064,20 @@ const validateParams = (values, fields) => {
|
|
|
28064
28064
|
}
|
|
28065
28065
|
break;
|
|
28066
28066
|
case 'buffer': {
|
|
28067
|
+
if (typeof value === 'undefined' || value === null) {
|
|
28068
|
+
throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [buffer].`);
|
|
28069
|
+
}
|
|
28067
28070
|
const isNodeBuffer = typeof Buffer !== 'undefined' &&
|
|
28068
28071
|
typeof Buffer.isBuffer === 'function' &&
|
|
28069
28072
|
Buffer.isBuffer(value);
|
|
28070
|
-
const isCustomBuffer = value &&
|
|
28071
|
-
value.constructor &&
|
|
28073
|
+
const isCustomBuffer = value.constructor &&
|
|
28072
28074
|
typeof value.constructor.isBuffer === 'function' &&
|
|
28073
28075
|
value.constructor.isBuffer(value);
|
|
28074
|
-
|
|
28076
|
+
const isArrayBuffer = typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;
|
|
28077
|
+
const isArrayBufferView = typeof ArrayBuffer !== 'undefined' &&
|
|
28078
|
+
typeof ArrayBuffer.isView === 'function' &&
|
|
28079
|
+
ArrayBuffer.isView(value);
|
|
28080
|
+
if (!isNodeBuffer && !isCustomBuffer && !isArrayBuffer && !isArrayBufferView) {
|
|
28075
28081
|
throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [buffer].`);
|
|
28076
28082
|
}
|
|
28077
28083
|
break;
|
|
@@ -28602,8 +28608,14 @@ const getInfo = ({ features, updateType, targetVersion }) => {
|
|
|
28602
28608
|
|
|
28603
28609
|
const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.5';
|
|
28604
28610
|
const SESSION_ERROR$1 = 'session not found';
|
|
28605
|
-
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
28611
|
+
const FIRMWARE_UPDATE_CONFIRM$1 = 'Firmware install confirmed';
|
|
28606
28612
|
const Log$8 = getLogger(exports.LoggerNames.Method);
|
|
28613
|
+
const isDeviceDisconnectedError$1 = (error) => {
|
|
28614
|
+
const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
|
|
28615
|
+
return (message.includes('device was disconnected') ||
|
|
28616
|
+
message.includes('transferIn') ||
|
|
28617
|
+
message.includes('USBDevice'));
|
|
28618
|
+
};
|
|
28607
28619
|
const postConfirmationMessage = (device) => {
|
|
28608
28620
|
var _a;
|
|
28609
28621
|
if ((_a = device.features) === null || _a === void 0 ? void 0 : _a.firmware_present) {
|
|
@@ -28717,12 +28729,27 @@ const newTouchUpdateProcess = (updateType, postMessage, device, { payload }, reb
|
|
|
28717
28729
|
postProgressTip(device, 'ConfirmOnDevice', postMessage);
|
|
28718
28730
|
postProgressTip(device, 'InstallingFirmware', postMessage);
|
|
28719
28731
|
typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
28720
|
-
|
|
28721
|
-
|
|
28722
|
-
|
|
28723
|
-
|
|
28732
|
+
let response;
|
|
28733
|
+
try {
|
|
28734
|
+
response = yield typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
28735
|
+
path: filePath,
|
|
28736
|
+
reboot_on_success: rebootOnSuccess,
|
|
28737
|
+
});
|
|
28738
|
+
}
|
|
28739
|
+
catch (error) {
|
|
28740
|
+
if (isDeviceDisconnectedError$1(error)) {
|
|
28741
|
+
Log$8.log('Rebooting device');
|
|
28742
|
+
response = {
|
|
28743
|
+
type: 'Success',
|
|
28744
|
+
message: { message: FIRMWARE_UPDATE_CONFIRM$1 },
|
|
28745
|
+
};
|
|
28746
|
+
}
|
|
28747
|
+
else {
|
|
28748
|
+
throw error;
|
|
28749
|
+
}
|
|
28750
|
+
}
|
|
28724
28751
|
if (response.type === 'Success' &&
|
|
28725
|
-
((_a = response === null || response === void 0 ? void 0 : response.message) === null || _a === void 0 ? void 0 : _a.message) === FIRMWARE_UPDATE_CONFIRM) {
|
|
28752
|
+
((_a = response === null || response === void 0 ? void 0 : response.message) === null || _a === void 0 ? void 0 : _a.message) === FIRMWARE_UPDATE_CONFIRM$1) {
|
|
28726
28753
|
const timeout = 2 * 60 * 1000;
|
|
28727
28754
|
const startTime = Date.now();
|
|
28728
28755
|
const isBleReconnect = DataManager.isBleConnect(env);
|
|
@@ -28943,6 +28970,13 @@ class DeviceFullyUploadResource extends BaseMethod {
|
|
|
28943
28970
|
|
|
28944
28971
|
const Log$7 = getLogger(exports.LoggerNames.Method);
|
|
28945
28972
|
const SESSION_ERROR = 'session not found';
|
|
28973
|
+
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
28974
|
+
const isDeviceDisconnectedError = (error) => {
|
|
28975
|
+
const message = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : '');
|
|
28976
|
+
return (message.includes('device was disconnected') ||
|
|
28977
|
+
message.includes('transferIn') ||
|
|
28978
|
+
message.includes('USBDevice'));
|
|
28979
|
+
};
|
|
28946
28980
|
class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
28947
28981
|
constructor() {
|
|
28948
28982
|
super(...arguments);
|
|
@@ -29112,10 +29146,25 @@ class FirmwareUpdateBaseMethod extends BaseMethod {
|
|
|
29112
29146
|
startEmmcFirmwareUpdate({ path }) {
|
|
29113
29147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29114
29148
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
29115
|
-
|
|
29116
|
-
|
|
29117
|
-
|
|
29118
|
-
|
|
29149
|
+
let updaeteResponse;
|
|
29150
|
+
try {
|
|
29151
|
+
updaeteResponse = yield typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
29152
|
+
path,
|
|
29153
|
+
reboot_on_success: true,
|
|
29154
|
+
});
|
|
29155
|
+
}
|
|
29156
|
+
catch (error) {
|
|
29157
|
+
if (isDeviceDisconnectedError(error)) {
|
|
29158
|
+
Log$7.log('Rebooting device');
|
|
29159
|
+
updaeteResponse = {
|
|
29160
|
+
type: 'Success',
|
|
29161
|
+
message: { message: FIRMWARE_UPDATE_CONFIRM },
|
|
29162
|
+
};
|
|
29163
|
+
}
|
|
29164
|
+
else {
|
|
29165
|
+
throw error;
|
|
29166
|
+
}
|
|
29167
|
+
}
|
|
29119
29168
|
if (updaeteResponse.type !== 'Success') {
|
|
29120
29169
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, 'firmware update error');
|
|
29121
29170
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.1.16-alpha.
|
|
3
|
+
"version": "1.1.16-alpha.8",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.1.16-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.1.16-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.1.16-alpha.8",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.1.16-alpha.8",
|
|
30
30
|
"axios": "1.12.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"bytebuffer": "^5.0.1",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/web-bluetooth": "^0.0.21",
|
|
47
47
|
"ripple-keypairs": "^1.3.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "2b168194312758f2444446bbe954df67815739b5"
|
|
50
50
|
}
|
|
@@ -24,9 +24,20 @@ import { DataManager } from '../../data-manager';
|
|
|
24
24
|
import { BaseMethod } from '../BaseMethod';
|
|
25
25
|
import { DEVICE } from '../../events';
|
|
26
26
|
import { PROTO } from '../../constants';
|
|
27
|
+
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
27
28
|
|
|
28
29
|
const Log = getLogger(LoggerNames.Method);
|
|
29
30
|
const SESSION_ERROR = 'session not found';
|
|
31
|
+
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
32
|
+
|
|
33
|
+
const isDeviceDisconnectedError = (error: unknown) => {
|
|
34
|
+
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
35
|
+
return (
|
|
36
|
+
message.includes('device was disconnected') ||
|
|
37
|
+
message.includes('transferIn') ||
|
|
38
|
+
message.includes('USBDevice')
|
|
39
|
+
);
|
|
40
|
+
};
|
|
30
41
|
|
|
31
42
|
export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
32
43
|
checkPromise: Deferred<any> | null = null;
|
|
@@ -255,10 +266,23 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
255
266
|
*/
|
|
256
267
|
async startEmmcFirmwareUpdate({ path }: { path: string }) {
|
|
257
268
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
269
|
+
let updaeteResponse: TypedResponseMessage<'Success'>;
|
|
270
|
+
try {
|
|
271
|
+
updaeteResponse = await typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
272
|
+
path,
|
|
273
|
+
reboot_on_success: true,
|
|
274
|
+
});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
if (isDeviceDisconnectedError(error)) {
|
|
277
|
+
Log.log('Rebooting device');
|
|
278
|
+
updaeteResponse = {
|
|
279
|
+
type: 'Success',
|
|
280
|
+
message: { message: FIRMWARE_UPDATE_CONFIRM },
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
262
286
|
if (updaeteResponse.type !== 'Success') {
|
|
263
287
|
throw ERRORS.TypedError(HardwareErrorCode.FirmwareError, 'firmware update error');
|
|
264
288
|
}
|
|
@@ -31,6 +31,15 @@ const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
|
31
31
|
|
|
32
32
|
const Log = getLogger(LoggerNames.Method);
|
|
33
33
|
|
|
34
|
+
const isDeviceDisconnectedError = (error: unknown) => {
|
|
35
|
+
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
36
|
+
return (
|
|
37
|
+
message.includes('device was disconnected') ||
|
|
38
|
+
message.includes('transferIn') ||
|
|
39
|
+
message.includes('USBDevice')
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
34
43
|
const postConfirmationMessage = (device: Device) => {
|
|
35
44
|
// only if firmware is already installed. fresh device does not require button confirmation
|
|
36
45
|
if (device.features?.firmware_present) {
|
|
@@ -220,10 +229,23 @@ const newTouchUpdateProcess = async (
|
|
|
220
229
|
postProgressTip(device, 'InstallingFirmware', postMessage);
|
|
221
230
|
typedCall = device.getCommands().typedCall.bind(device.getCommands());
|
|
222
231
|
// Firmware Update
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
232
|
+
let response: TypedResponseMessage<'Success'>;
|
|
233
|
+
try {
|
|
234
|
+
response = await typedCall('FirmwareUpdateEmmc', 'Success', {
|
|
235
|
+
path: filePath,
|
|
236
|
+
reboot_on_success: rebootOnSuccess,
|
|
237
|
+
});
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (isDeviceDisconnectedError(error)) {
|
|
240
|
+
Log.log('Rebooting device');
|
|
241
|
+
response = {
|
|
242
|
+
type: 'Success',
|
|
243
|
+
message: { message: FIRMWARE_UPDATE_CONFIRM },
|
|
244
|
+
} as TypedResponseMessage<'Success'>;
|
|
245
|
+
} else {
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
227
249
|
|
|
228
250
|
if (
|
|
229
251
|
response.type === 'Success' &&
|
|
@@ -84,17 +84,26 @@ export const validateParams = (values: any, fields: Array<SchemaParam>): void =>
|
|
|
84
84
|
break;
|
|
85
85
|
|
|
86
86
|
case 'buffer': {
|
|
87
|
+
if (typeof value === 'undefined' || value === null) {
|
|
88
|
+
throw invalidParameter(
|
|
89
|
+
`Parameter [${field.name}] is of type invalid and should be [buffer].`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
87
92
|
const isNodeBuffer =
|
|
88
93
|
typeof Buffer !== 'undefined' &&
|
|
89
94
|
typeof Buffer.isBuffer === 'function' &&
|
|
90
95
|
Buffer.isBuffer(value);
|
|
91
96
|
const isCustomBuffer =
|
|
92
|
-
value &&
|
|
93
97
|
value.constructor &&
|
|
94
98
|
typeof value.constructor.isBuffer === 'function' &&
|
|
95
99
|
value.constructor.isBuffer(value);
|
|
100
|
+
const isArrayBuffer = typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;
|
|
101
|
+
const isArrayBufferView =
|
|
102
|
+
typeof ArrayBuffer !== 'undefined' &&
|
|
103
|
+
typeof ArrayBuffer.isView === 'function' &&
|
|
104
|
+
ArrayBuffer.isView(value);
|
|
96
105
|
|
|
97
|
-
if (!isNodeBuffer && !isCustomBuffer) {
|
|
106
|
+
if (!isNodeBuffer && !isCustomBuffer && !isArrayBuffer && !isArrayBufferView) {
|
|
98
107
|
throw invalidParameter(
|
|
99
108
|
`Parameter [${field.name}] is of type invalid and should be [buffer].`
|
|
100
109
|
);
|