Skip to content

Commit b4597b0

Browse files
committed
Fix API dependency injection, RX handling, fs.list()
1 parent fd4fd4b commit b4597b0

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/api/filesystem.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ export class BadgeFileSystemApi {
2020
textEncoder = new TextEncoder();
2121
textDecoder = new TextDecoder();
2222

23-
/** Lists entries in the folder given by `path` */
24-
async list(path: string): Promise<FileListing[]> {
23+
/**
24+
* Lists entries in the folder given by `path`
25+
* @param path default: `/internal`
26+
*/
27+
async list(path: string = '/internal'): Promise<FileListing[]> {
28+
if (path == '') {
29+
throw Error('Path must not be empty');
30+
}
2531
let pathEncoded = this.textEncoder.encode(path);
2632
let data: ArrayBuffer = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_FILESYSTEM_LIST, pathEncoded, 4000);
2733

src/badge-api.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* @author Reinier van der Leer
44
*/
55

6+
import { BadgeUSB, TransactionArgs } from "./badge-usb";
67
import { BadgeFileSystemApi } from "./api/filesystem";
78
import { BadgeAppFSApi } from "./api/appfs";
89
import { BadgeNVSApi } from "./api/nvs";
9-
import { BadgeUSB } from "./badge-usb";
1010

1111
export type ProgressCallback = (status: string, progressPercent: number) => void;
1212

@@ -54,15 +54,19 @@ export class BadgeAPI {
5454

5555

5656
/*** Filesystem API ***/
57-
public fileSystem = new BadgeFileSystemApi(this.transaction);
57+
public fileSystem = new BadgeFileSystemApi(
58+
(...args: TransactionArgs) => this.transaction(...args),
59+
);
5860

5961
/*** AppFS API ***/
6062
public appFS = new BadgeAppFSApi(
6163
this.fileSystem,
6264
this.disconnect,
63-
this.transaction,
65+
(...args: TransactionArgs) => this.transaction(...args),
6466
);
6567

6668
/*** NVS API */
67-
public nvs = new BadgeNVSApi(this.transaction);
69+
public nvs = new BadgeNVSApi(
70+
(...args: TransactionArgs) => this.transaction(...args),
71+
);
6872
}

src/badge-usb.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ export class BadgeUSB {
471471
dataView, identifier, magic,
472472
type: responseType,
473473
payload: {
474-
buffer,
474+
buffer: payload,
475475
crc: payloadCRC,
476476
declaredLength: payloadLength,
477477
},
@@ -485,6 +485,8 @@ export class BadgeUSB {
485485
}
486486
}
487487

488+
export type TransactionArgs = Parameters<BadgeUSB['transaction']>;
489+
488490
class TransactionPromise extends Promise<TransactionResponse> {
489491
resolve: (value: TransactionResponse | PromiseLike<TransactionResponse>) => void;
490492
reject: (reason: TransactionResponse | Error) => void;

0 commit comments

Comments
 (0)