Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): pass organization id through video upload actions

Richie McIlroyeb35f73be401
diff --git a/apps/web/actions/video/create-for-processing.ts b/apps/web/actions/video/create-for-processing.ts
index 3bcc07857..2f3d4942d 100644
--- a/apps/web/actions/video/create-for-processing.ts
+++ b/apps/web/actions/video/create-for-processing.ts
@@ -15,6 +15,7 @@ import {
} from "@cap/web-domain";
import { Option } from "effect";
import { revalidatePath } from "next/cache";
+import { requireOrganizationAccess } from "@/actions/organization/authorization";
import { runPromise } from "@/lib/server";
export interface CreateForProcessingResult {
@@ -48,6 +49,8 @@ export async function createVideoForServerProcessing({
throw new Error("upgrade_required");
}
+ await requireOrganizationAccess(user.id, orgId);
+
const videoId = Video.VideoId.make(nanoId());
const date = new Date();
@@ -68,6 +71,7 @@ export async function createVideoForServerProcessing({
"x-amz-meta-resolution": resolution ?? "",
},
},
+ orgId,
).pipe(runPromise);
await db()
diff --git a/apps/web/actions/video/upload.ts b/apps/web/actions/video/upload.ts
index a61e035e0..1a66aa17a 100644
--- a/apps/web/actions/video/upload.ts
+++ b/apps/web/actions/video/upload.ts
@@ -16,6 +16,7 @@ import {
import { eq } from "drizzle-orm";
import { Effect, Option } from "effect";
import { revalidatePath } from "next/cache";
+import { requireOrganizationAccess } from "@/actions/organization/authorization";
import { runPromise } from "@/lib/server";
const MAX_S3_DELETE_ATTEMPTS = 3;
@@ -29,6 +30,7 @@ async function getVideoUploadPresignedUrl({
audioCodec,
video,
userId,
+ organizationId,
}: {
fileKey: string;
duration?: string;
@@ -37,6 +39,7 @@ async function getVideoUploadPresignedUrl({
audioCodec?: string;
video?: Video.Video;
userId: User.UserId;
+ organizationId?: Organisation.OrganisationId;
}) {
try {
const contentType = fileKey.endsWith(".aac")
@@ -76,10 +79,15 @@ async function getVideoUploadPresignedUrl({
};
}
- return yield* StorageService.createUploadTargetForUser(userId, fileKey, {
- contentType,
- fields: Fields,
- });
+ return yield* StorageService.createUploadTargetForUser(
+ userId,
+ fileKey,
+ {
+ contentType,
+ fields: Fields,
+ },
+ organizationId,
+ );
}).pipe(runPromise);
return {
@@ -129,6 +137,8 @@ export async function createVideoAndGetUploadUrl({
if (!userIsPro(user) && duration && duration > 300)
throw new Error("upgrade_required");
+ await requireOrganizationAccess(user.id, orgId);
+
const date = new Date();
const formattedDate = `${date.getDate()} ${date.toLocaleString("default", {
month: "long",
@@ -185,6 +195,7 @@ export async function createVideoAndGetUploadUrl({
videoCodec,
audioCodec,
userId: user.id,
+ organizationId: orgId,
});
const videoData = {