Skip to content

Commit 59785a9

Browse files
committed
fix: implement work around for folders without index file
1 parent 6911e70 commit 59785a9

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/StorageClient.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ describe(`Given an instance of the '${StorageClient.name}'`, () => {
7171
describe('When testing folder uploads', () => {
7272
const files = [file1, file2];
7373

74-
it.only('Then it should create the expected resources', async () => {
74+
it('Then it should create the expected resources', async () => {
7575
const result = await client.uploadFolder(files, {
7676
acl: immutable(37111),
7777
});
7878

79-
console.log(result);
80-
8179
await assertFileExist(client.resolve(result.files[0]?.uri ?? never()));
8280
});
8381

src/StorageClient.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class StorageClient {
7878
? await this.uploadImmutableFile(file, acl)
7979
: await this.uploadMutableFile(file, acl);
8080

81+
await this.waitUntilStatus(
82+
resource.storageKey,
83+
['done', 'available'],
84+
this.env.cachingTimeout,
85+
);
86+
8187
return new FileUploadResponse(resource, this);
8288
}
8389

@@ -140,9 +146,9 @@ export class StorageClient {
140146
files: FileList | File[],
141147
options: UploadFolderOptions = { acl: immutable(this.env.defaultChainId) },
142148
): Promise<UploadFolderResponse> {
143-
const needsIndex = 'index' in options && !!options.index;
149+
const withIndexFile = 'index' in options && !!options.index;
144150
const [folderResource, ...fileResources] = await this.allocateStorage(
145-
files.length + (needsIndex ? 2 : 1),
151+
files.length + (withIndexFile ? 2 : 1),
146152
);
147153

148154
const builder = MultipartEntriesBuilder.from(fileResources).withFiles(
@@ -162,6 +168,13 @@ export class StorageClient {
162168
throw await StorageClientError.fromResponse(response);
163169
}
164170

171+
await this.waitUntilStatus(
172+
// biome-ignore lint/style/noNonNullAssertion: we know the folder has at least one file
173+
withIndexFile ? folderResource.storageKey : fileResources[0]!.storageKey,
174+
['done', 'available'],
175+
this.env.cachingTimeout,
176+
);
177+
165178
return {
166179
folder: folderResource,
167180
files: fileResources,
@@ -317,8 +330,6 @@ export class StorageClient {
317330
while (Date.now() - startedAt < timeout) {
318331
const { status } = await this.status(storageKeyOrUri);
319332

320-
console.log(storageKeyOrUri, status);
321-
322333
// Handle common error states
323334
switch (status) {
324335
case 'error_upload':
@@ -401,21 +412,11 @@ export class StorageClient {
401412
storageKey: string,
402413
entries: readonly MultipartEntry[],
403414
): Promise<Response> {
404-
const response = await this.multipartRequest(
415+
return this.multipartRequest(
405416
'POST',
406417
`${this.env.backend}/${storageKey}`,
407418
entries,
408419
);
409-
410-
console.log('upload', `${this.env.backend}/${storageKey}`);
411-
412-
await this.waitUntilStatus(
413-
storageKey,
414-
['done', 'available'],
415-
this.env.cachingTimeout,
416-
);
417-
418-
return response;
419420
}
420421

421422
private async update(

0 commit comments

Comments
 (0)