Skip to content

Commit a663231

Browse files
committed
Improve code quality
1 parent 1579aa9 commit a663231

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

templates/node/src/client.ts.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ class Client {
201201
}
202202

203203
async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
204-
const fileIndex = Object.values(originalPayload).findIndex((value) => value instanceof File);
205-
const fileParam = Object.keys(originalPayload)[fileIndex];
206-
const file = originalPayload[fileParam];
204+
const [fileParam, file] = Object.entries(originalPayload).find(([, value]) => value instanceof File) ?? [];
207205

208206
if (!file) {
209207
throw new Error('File not found in payload');

templates/web/src/client.ts.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,7 @@ class Client {
629629
}
630630

631631
async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
632-
const fileIndex = Object.values(originalPayload).findIndex((value) => value instanceof File);
633-
const fileParam = Object.keys(originalPayload)[fileIndex];
634-
const file = originalPayload[fileParam];
632+
const [fileParam, file] = Object.entries(originalPayload).find(([, value]) => value instanceof File) ?? [];
635633

636634
if (!file) {
637635
throw new Error('File not found in payload');

0 commit comments

Comments
 (0)