Skip to content

Commit 0baadd1

Browse files
fixes
1 parent a0ba0ec commit 0baadd1

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

apps/web/app/api/upload/[...route]/multipart.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ app.post(
5050

5151
const videoIdFromFileKey = fileKey.split("/")[1];
5252
const videoIdRaw = "videoId" in body ? body.videoId : videoIdFromFileKey;
53-
if (!videoIdRaw) throw new Error("Video ID is required");
53+
if (!videoIdRaw) return c.text("Video id not found", 400);
5454
const videoId = Video.VideoId.make(videoIdRaw);
5555

5656
const resp = await Effect.gen(function* () {
@@ -76,9 +76,6 @@ app.post(
7676
if (e._tag === "VideoNotFoundError")
7777
return Effect.succeed<Response>(c.text("Video not found", 404));
7878

79-
// if (e._tag === "DatabaseError")
80-
// return Effect.succeed<Response>(c.text("Video not found", 404));
81-
8279
return Effect.succeed<Response>(
8380
c.json({ error: "Error initiating multipart upload" }, 500),
8481
);
@@ -245,7 +242,8 @@ app.post(
245242
const user = c.get("user");
246243

247244
return Effect.gen(function* () {
248-
const videos = yield* Videos;
245+
const repo = yield* VideosRepo;
246+
const policy = yield* VideosPolicy;
249247
const db = yield* Database;
250248

251249
const fileKey = parseVideoIdOrFileKey(user.id, {
@@ -254,12 +252,13 @@ app.post(
254252
});
255253

256254
const videoIdFromFileKey = fileKey.split("/")[1];
257-
const videoId = "videoId" in body ? body.videoId : videoIdFromFileKey;
258-
if (!videoId) throw new Error("Video ID is required");
255+
const videoIdRaw = "videoId" in body ? body.videoId : videoIdFromFileKey;
256+
if (!videoIdRaw) return c.text("Video id not found", 400);
257+
const videoId = Video.VideoId.make(videoIdRaw);
259258

260-
const maybeVideo = yield* videos.getByIdForOwner(
261-
Video.VideoId.make(videoId),
262-
);
259+
const maybeVideo = yield* repo
260+
.getById(videoId)
261+
.pipe(Policy.withPolicy(policy.isOwner(videoId)));
263262
if (Option.isNone(maybeVideo)) {
264263
c.status(404);
265264
return c.text(`Video '${encodeURIComponent(videoId)}' not found`);

packages/web-backend/src/Videos/index.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ export class Videos extends Effect.Service<Videos>()("Videos", {
2424
Effect.withSpan("Videos.getById"),
2525
);
2626

27-
const getByIdForOwner = (id: Video.VideoId) =>
28-
repo
29-
.getById(id)
30-
.pipe(
31-
Policy.withPublicPolicy(policy.isOwner(id)),
32-
Effect.withSpan("Videos.getByIdForOwner"),
33-
);
34-
3527
return {
3628
/*
3729
* Get a video by ID. Will fail if the user does not have access.
@@ -40,11 +32,6 @@ export class Videos extends Effect.Service<Videos>()("Videos", {
4032
// internal use should prefer the repo directly
4133
getByIdForViewing,
4234

43-
/*
44-
* Get a video by ID. Will fail if the user isn't the owner.
45-
*/
46-
getByIdForOwner,
47-
4835
/*
4936
* Delete a video. Will fail if the user does not have access.
5037
*/

0 commit comments

Comments
 (0)