🎥 Make videos programmatically with React
fix s3 lambda key
Jonny Burger88b88f36a6fe
diff --git a/packages/lambda/src/api/upload-dir.ts b/packages/lambda/src/api/upload-dir.tsindex 858a7c2540..a5964d475c 100644--- a/packages/lambda/src/api/upload-dir.ts+++ b/packages/lambda/src/api/upload-dir.ts@@ -6,6 +6,7 @@ import path from 'path';import {Privacy} from '../defaults';import {AwsRegion} from '../pricing/aws-regions';import {getS3Client} from '../shared/aws-clients';+import {makeS3Key} from '../shared/make-s3-key';type FileInfo = {name: string;@@ -73,7 +74,7 @@ export const uploadDir = async ({const client = getS3Client(region);const uploads = files.map(async (filePath) => {- const Key = `${folder}/${path.relative(dir, filePath.name)}`;+ const Key = makeS3Key(folder, dir, filePath.name);const Body = createReadStream(filePath.name);const ContentType = mimeTypes.lookup(Key) || 'application/octet-stream';const ACL = privacy === 'private' ? 'private' : 'public-read';diff --git a/packages/lambda/src/shared/make-s3-key.ts b/packages/lambda/src/shared/make-s3-key.tsnew file mode 100644index 0000000000..89a10888cc--- /dev/null+++ b/packages/lambda/src/shared/make-s3-key.ts@@ -0,0 +1,5 @@+import path from 'path';++export const makeS3Key = (folder: string, dir: string, filePath: string) => {+ return `${folder}/${path.relative(dir, filePath).split(path.sep).join('/')}`;+};diff --git a/packages/lambda/src/test/unit/make-s3-key.test.ts b/packages/lambda/src/test/unit/make-s3-key.test.tsnew file mode 100644index 0000000000..4f99b1c597--- /dev/null+++ b/packages/lambda/src/test/unit/make-s3-key.test.ts@@ -0,0 +1,19 @@+import {makeS3Key} from '../../shared/make-s3-key';++test('makeS3Key should return POSIX syntax cross-platform', () => {+ const key = makeS3Key(+ 'renders/234kj324',+ 'C:\\Users\\Jonny\\Pictures',+ 'C:\\Users\\Jonny\\Pictures\\public\\index.mp4'+ );++ expect(key).toEqual('renders/234kj324/public/index.mp4');++ const key2 = makeS3Key(+ 'renders/234kj324',+ '/tmp/test/',+ '/tmp/test/public/index.mp4'+ );++ expect(key2).toEqual('renders/234kj324/public/index.mp4');+});