@@ -31,39 +31,23 @@ async function getVideoUploadPresignedUrl({
3131 resolution,
3232 videoCodec,
3333 audioCodec,
34+ bucketId,
35+ userId,
3436} : {
3537 fileKey : string ;
3638 duration ?: string ;
3739 resolution ?: string ;
3840 videoCodec ?: string ;
3941 audioCodec ?: string ;
42+ bucketId : string | undefined ;
43+ userId : string ;
4044} ) {
41- const user = await getCurrentUser ( ) ;
42-
43- if ( ! user ) {
44- throw new Error ( "Unauthorized" ) ;
45- }
46-
4745 try {
48- const [ customBucket ] = await db ( )
49- . select ( )
50- . from ( s3Buckets )
51- . where ( eq ( s3Buckets . ownerId , user . id ) ) ;
52-
53- const s3Config = customBucket
54- ? {
55- endpoint : customBucket . endpoint || undefined ,
56- region : customBucket . region ,
57- accessKeyId : customBucket . accessKeyId ,
58- secretAccessKey : customBucket . secretAccessKey ,
59- }
60- : null ;
46+ const bucketIdOption = Option . fromNullable ( bucketId ) . pipe (
47+ Option . map ( ( id ) => S3Bucket . S3BucketId . make ( id ) ) ,
48+ ) ;
6149
62- if (
63- ! customBucket ||
64- ! s3Config ||
65- customBucket . bucketName !== serverEnv ( ) . CAP_AWS_BUCKET
66- ) {
50+ if ( Option . isNone ( bucketIdOption ) ) {
6751 const distributionId = serverEnv ( ) . CAP_CLOUDFRONT_DISTRIBUTION_ID ;
6852 if ( distributionId ) {
6953 const cloudfront = new CloudFrontClient ( {
@@ -108,17 +92,15 @@ async function getVideoUploadPresignedUrl({
10892
10993 const Fields = {
11094 "Content-Type" : contentType ,
111- "x-amz-meta-userid" : user . id ,
95+ "x-amz-meta-userid" : userId ,
11296 "x-amz-meta-duration" : duration ?? "" ,
11397 "x-amz-meta-resolution" : resolution ?? "" ,
11498 "x-amz-meta-videocodec" : videoCodec ?? "" ,
11599 "x-amz-meta-audiocodec" : audioCodec ?? "" ,
116100 } ;
117101
118102 const presignedPostData = await Effect . gen ( function * ( ) {
119- const [ bucket ] = yield * S3Buckets . getBucketAccess (
120- Option . fromNullable ( customBucket ?. id ) ,
121- ) ;
103+ const [ bucket ] = yield * S3Buckets . getBucketAccess ( bucketIdOption ) ;
122104
123105 return yield * bucket . getPresignedPostUrl ( fileKey , {
124106 Fields,
@@ -193,6 +175,8 @@ export async function createVideoAndGetUploadUrl({
193175 resolution,
194176 videoCodec,
195177 audioCodec,
178+ bucketId : existingVideo . bucket ?? customBucket ?. id ,
179+ userId : user . id ,
196180 } ) ;
197181
198182 return {
@@ -234,6 +218,8 @@ export async function createVideoAndGetUploadUrl({
234218 resolution,
235219 videoCodec,
236220 audioCodec,
221+ bucketId : customBucket ?. id ,
222+ userId : user . id ,
237223 } ) ;
238224
239225 if ( buildEnv . NEXT_PUBLIC_IS_CAP && NODE_ENV === "production" ) {
0 commit comments