🎥 Make videos programmatically with React
don't delete sites with same prefix
Jonny Burger4b5649767a7f
diff --git a/packages/lambda/src/api/delete-site.ts b/packages/lambda/src/api/delete-site.tsindex 2b79d51f32..05dfae709a 100644--- a/packages/lambda/src/api/delete-site.ts+++ b/packages/lambda/src/api/delete-site.ts@@ -35,7 +35,8 @@ export const deleteSite = async ({let files = await lambdaLs({bucketName,- prefix: getSitesKey(siteName),+ // The `/` is important to not accidentially delete sites with the same name but containing a suffix.+ prefix: `${getSitesKey(siteName)}/`,region,expectedBucketOwner: accountId,});@@ -55,7 +56,8 @@ export const deleteSite = async ({});files = await lambdaLs({bucketName,- prefix: getSitesKey(siteName),+ // The `/` is important to not accidentially delete sites with the same name but containing a suffix.+ prefix: `${getSitesKey(siteName)}/`,region,expectedBucketOwner: accountId,});diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.tsindex cc31cbde84..288fbefa47 100644--- a/packages/lambda/src/api/deploy-site.ts+++ b/packages/lambda/src/api/deploy-site.ts@@ -89,7 +89,8 @@ export const deploySite = async ({bucketName,expectedBucketOwner: accountId,region,- prefix: subFolder,+ // The `/` is important to not accidentially delete sites with the same name but containing a suffix.+ prefix: `${subFolder}/`,}),bundleSite({publicPath: `/${subFolder}/`,diff --git a/packages/lambda/src/test/integration/deploy-site.test.ts b/packages/lambda/src/test/integration/deploy-site.test.tsindex 828c8df437..6fda83273d 100644--- a/packages/lambda/src/test/integration/deploy-site.test.ts+++ b/packages/lambda/src/test/integration/deploy-site.test.ts@@ -1,4 +1,5 @@import {expect, test} from 'vitest';+import {deleteSite} from '../../api/delete-site';import {deploySite} from '../../api/deploy-site';import {getOrCreateBucket} from '../../api/get-or-create-bucket';import {getDirFiles} from '../../api/upload-dir';@@ -146,6 +147,17 @@ test('Should keep the previous site if deploying the new one with different ID',region: 'ap-northeast-1',continuationToken: undefined,});++ await deleteSite({+ bucketName,+ region: 'ap-northeast-1',+ siteName: 'testing',+ });+ await deleteSite({+ bucketName,+ region: 'ap-northeast-1',+ siteName: 'testing-2',+ });expect(files.map((f) => {return f.Key;@@ -159,3 +171,49 @@ test('Should keep the previous site if deploying the new one with different ID',}),]);});++test('Should not delete site with same prefix', async () => {+ const {bucketName} = await getOrCreateBucket({+ region: 'ap-northeast-1',+ });++ await deploySite({+ bucketName,+ entryPoint: 'first',+ region: 'ap-northeast-1',+ siteName: 'my-site',+ });+ await deploySite({+ bucketName,+ entryPoint: 'second',+ region: 'ap-northeast-1',+ siteName: 'my-site-staging',+ });+ await deploySite({+ bucketName,+ entryPoint: 'first',+ region: 'ap-northeast-1',+ siteName: 'my-site',+ });++ const files = await lambdaLs({+ bucketName,+ expectedBucketOwner: null,+ prefix: 'sites/',+ region: 'ap-northeast-1',+ continuationToken: undefined,+ });+ expect(+ files.map((f) => {+ return f.Key;+ })+ ).toEqual([+ // Should not delete my-site-staging (same bucket name but with suffix)+ ...getDirFiles('/path/to/bundle-2').map((f) => {+ return 'sites/my-site-staging/' + f.name;+ }),+ ...getDirFiles('/path/to/bundle-1').map((f) => {+ return 'sites/my-site/' + f.name;+ }),+ ]);+});