Skip to content

Commit f3d5335

Browse files
committed
effectify everywhere
1 parent 5847ded commit f3d5335

File tree

10 files changed

+418
-529
lines changed

10 files changed

+418
-529
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3b3a0bb176ac922bc623271fc64a60cf7f5bd8b
1+
b0773ee5cd650542153d189bc020753467af21a2

apps/web/actions/videos/get-status.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { getCurrentUser } from "@cap/database/auth/session";
55
import { users, videos } from "@cap/database/schema";
66
import type { VideoMetadata } from "@cap/database/types";
77
import { eq } from "drizzle-orm";
8-
import { userHasAccessToVideo } from "@/utils/auth";
98
import { isAiGenerationEnabled } from "@/utils/flags";
109
import { transcribeVideo } from "../../lib/transcribe";
1110
import { generateAiMetadata } from "./generate-ai-metadata";
11+
import { Cause, Effect, Exit, Option } from "effect";
12+
import { provideOptionalAuth, VideosPolicy } from "@cap/web-backend";
13+
import { Policy, Video } from "@cap/web-domain";
14+
import { EffectRuntime } from "@/lib/server";
1215

1316
const MAX_AI_PROCESSING_TIME = 10 * 60 * 1000;
1417

@@ -23,20 +26,26 @@ export interface VideoStatusResult {
2326
}
2427

2528
export async function getVideoStatus(
26-
videoId: string,
27-
): Promise<VideoStatusResult | { success: false; access: string }> {
28-
const userPromise = getCurrentUser();
29+
videoId: Video.VideoId,
30+
): Promise<VideoStatusResult | { success: false }> {
31+
if (!videoId) throw new Error("Video ID not provided");
2932

30-
if (!videoId) {
31-
throw new Error("Video ID not provided");
32-
}
33+
const exit = await Effect.gen(function* () {
34+
const videosPolicy = yield* VideosPolicy;
3335

34-
const result = await db().select().from(videos).where(eq(videos.id, videoId));
35-
if (result.length === 0 || !result[0]) {
36-
throw new Error("Video not found");
37-
}
36+
return yield* Effect.promise(() =>
37+
db().select().from(videos).where(eq(videos.id, videoId))
38+
).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
39+
}).pipe(
40+
provideOptionalAuth,
41+
EffectRuntime.runPromiseExit,
42+
);
43+
44+
if (Exit.isFailure(exit)) return { success: false }
45+
46+
const video = exit.value[0];
47+
if (!video) throw new Error("Video not found");
3848

39-
const video = result[0];
4049
const metadata: VideoMetadata = (video.metadata as VideoMetadata) || {};
4150

4251
if (!video.transcriptionStatus) {
@@ -226,9 +235,6 @@ export async function getVideoStatus(
226235
}
227236
}
228237

229-
const access = await userHasAccessToVideo(userPromise, video);
230-
if (access !== "has-access") return { success: false, access };
231-
232238
return {
233239
transcriptionStatus:
234240
(video.transcriptionStatus as "PROCESSING" | "COMPLETE" | "ERROR") ||

apps/web/app/api/playlist/route.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Api extends HttpApi.make("CapWebApi").add(
4141
.addError(HttpApiError.InternalServerError)
4242
.addError(HttpApiError.NotFound),
4343
),
44-
) {}
44+
) { }
4545

4646
const ApiLive = HttpApiBuilder.api(Api).pipe(
4747
Layer.provide(
@@ -198,13 +198,9 @@ const getPlaylistResponse = (
198198
const generatedPlaylist = generateMasterPlaylist(
199199
videoMetadata?.Metadata?.resolution ?? "",
200200
videoMetadata?.Metadata?.bandwidth ?? "",
201-
`${serverEnv().WEB_URL}/api/playlist?userId=${
202-
video.ownerId
203-
}&videoId=${video.id}&videoType=video`,
201+
`${serverEnv().WEB_URL}/api/playlist?videoId=${video.id}&videoType=video`,
204202
audioMetadata
205-
? `${serverEnv().WEB_URL}/api/playlist?userId=${
206-
video.ownerId
207-
}&videoId=${video.id}&videoType=audio`
203+
? `${serverEnv().WEB_URL}/api/playlist?videoId=${video.id}&videoType=audio`
208204
: null,
209205
);
210206

0 commit comments

Comments
 (0)