@@ -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` ) ;
0 commit comments