From 27e0567d1ff3c0bd9da4d1c69fa473618a4b664f Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 24 Apr 2024 14:35:37 -0600 Subject: [PATCH] fix(s3): fix downloads from s3 --- src/system.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system.ts b/src/system.ts index 3bcbad8..226afd6 100644 --- a/src/system.ts +++ b/src/system.ts @@ -167,12 +167,17 @@ export const fetchCacheFromS3 = async () => { const tmpFileDir = path.dirname(tempFilePath); const finalFilePath = path.join(process.cwd(), fileKey); + const warpCacheDir = path.dirname(finalFilePath); try { - if (fs.existsSync(fileKey)) { + if (!fs.existsSync(tmpFileDir)) { await fs.promises.mkdir(tmpFileDir, { recursive: true }); } + if (!fs.existsSync(warpCacheDir)) { + await fs.promises.mkdir(warpCacheDir, { recursive: true }); + } + const data = await s3.send( new GetObjectCommand({ ...params, Key: fileKey }), ); @@ -184,8 +189,6 @@ export const fetchCacheFromS3 = async () => { tempFilePath, }); await fs.promises.writeFile(tempFilePath, readableStream); - const warpCacheDir = path.dirname(finalFilePath); - await fs.promises.mkdir(warpCacheDir, { recursive: true }); if (fs.existsSync(finalFilePath)) { await fs.promises.unlink(finalFilePath); }