Skip to content

🎥 Make videos programmatically with React

validate privacy

Jonny Burger6496dbbdc02c
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 8cf7048554..714fb465ad 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -18,6 +18,7 @@ import {
} from '../shared/constants';
import {getServeUrlHash} from '../shared/make-s3-url';
import {randomHash} from '../shared/random-hash';
+import {validatePrivacy} from '../shared/validate-privacy';
import {formatCostsInfo} from './helpers/format-costs-info';
import {closeBrowser, getBrowserInstance} from './helpers/get-browser-instance';
import {getCurrentRegionInFunction} from './helpers/get-current-region';
@@ -40,6 +41,8 @@ export const innerStillHandler = async (
throw new TypeError('Expected still type');
}
+ validatePrivacy(lambdaParams.privacy);
+
const start = Date.now();
const renderId = randomHash();
@@ -148,7 +151,6 @@ export const innerStillHandler = async (
await lambdaWriteFile({
bucketName,
key: outName,
- // TODO: validate
acl: lambdaParams.privacy === 'private' ? 'private' : 'public-read',
body: fs.createReadStream(outputPath),
expectedBucketOwner: options.expectedBucketOwner,
diff --git a/packages/lambda/src/shared/validate-privacy.ts b/packages/lambda/src/shared/validate-privacy.ts
new file mode 100644
index 0000000000..c5bbbb811c
--- /dev/null
+++ b/packages/lambda/src/shared/validate-privacy.ts
@@ -0,0 +1,11 @@
+export function validatePrivacy(
+ privacy: unknown
+): asserts privacy is 'private' | 'public' {
+ if (typeof privacy !== 'string') {
+ throw new TypeError('Privacy must be a string');
+ }
+
+ if (privacy !== 'private' && privacy !== 'public') {
+ throw new TypeError('Privacy must be either "private" or "public-read"');
+ }
+}