Skip to content

Commit 32e06c1

Browse files
authored
Merge pull request #592 from psteinroe/fix/ensure-existence
fix: use new .info() for ensureExistence
2 parents ce69156 + f4952e4 commit 32e06c1

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

.changeset/silver-rice-travel.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@supabase-cache-helpers/storage-core": patch
3+
---
4+
5+
fix: use new .info() for ensureExistence

packages/storage-core/src/url-fetcher.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,13 @@ export const createUrlFetcher = (
2323
fileApi: StorageFileApi,
2424
path: string,
2525
): Promise<string | undefined> => {
26-
let params: Record<string, string> | undefined;
26+
let params: Record<string, string> = {};
27+
2728
if (config?.ensureExistence) {
28-
const pathElements = path.split('/');
29-
const fileName = pathElements.pop();
30-
const { data: files } = await fileApi.list(pathElements.join('/'), {
31-
limit: 1,
32-
search: fileName,
33-
});
34-
if (!files || files.length === 0) return;
35-
params = {
36-
updated_at: files[0].updated_at,
37-
};
38-
} else {
29+
const { data: fileInfo } = await fileApi.info(path);
30+
if (!fileInfo) return;
3931
params = {
40-
updated_at: Date.now().toString(),
32+
updated_at: fileInfo.updatedAt,
4133
};
4234
}
4335

packages/storage-core/tests/url-fetcher.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('urlFetcher', () => {
6565
),
6666
).resolves.toEqual(
6767
expect.stringContaining(
68-
`http://localhost:54321/storage/v1/object/public/public_contact_files/${dirName}/${publicFiles[0]}?updated_at=`,
68+
`http://localhost:54321/storage/v1/object/public/public_contact_files/${dirName}/${publicFiles[0]}`,
6969
),
7070
);
7171
});

0 commit comments

Comments
 (0)