Skip to content

Commit 8e33e77

Browse files
authored
use createSignedUrl() for downloading pst files (#2590)
1 parent f3f628e commit 8e33e77

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

micro-services/emails-fetcher/src/services/pst/PSTEmailsFetcher.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,23 @@ export default class PSTEmailsFetcher {
433433
async downloadPSTFromSupabase(storagePath: string) {
434434
const { data, error } = await supabaseClient.storage
435435
.from(PST_FOLDER)
436-
.download(storagePath);
436+
.createSignedUrl(storagePath, 3600); // 1 hour timeout
437437

438438
if (error) throw error;
439439

440+
const res = await fetch(data.signedUrl);
441+
442+
if (!res.ok || !res.body) {
443+
throw new Error(`Failed to download PST: ${res.status}`);
444+
}
445+
440446
this.localPstFilePath = path.join(
441447
'/tmp',
442448
`${Date.now()}-${path.basename(storagePath)}`
443449
);
444450

445451
const writeStream = fs.createWriteStream(this.localPstFilePath);
446-
await pipeline(data.stream(), writeStream);
452+
await pipeline(res.body, writeStream);
447453
this.pstFile = new PSTFile(this.localPstFilePath);
448454
}
449455

0 commit comments

Comments
 (0)