From 8b37a2e06a1fecc5706eba64141864223aa51512 Mon Sep 17 00:00:00 2001 From: mariodev Date: Sat, 10 Aug 2024 07:25:45 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improved=20new=20getVideoUrl=20f?= =?UTF-8?q?unction=20calls=20and=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/app/[organization]/watch/page.tsx | 21 ++++++++++++------- .../[organization]/library/[session]/page.tsx | 19 ++++++++++++----- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/app/app/[organization]/watch/page.tsx b/packages/app/app/[organization]/watch/page.tsx index 8ca7c8bac..83d853987 100644 --- a/packages/app/app/[organization]/watch/page.tsx +++ b/packages/app/app/[organization]/watch/page.tsx @@ -52,15 +52,20 @@ export default async function Watch({ session: searchParams.session, }); - if (!session || !session.playbackId) return notFound(); + // Check if session exists and has a playbackId. If not, return a 'not found' response. + if (!session?.playbackId) return notFound(); + // Determine which identifier to use. Prioritize assetId if it exists, otherwise use playbackId. + const identifier = session.assetId || session.playbackId; + // Set the idType based on which identifier we're using. + // This ternary operation will set 'assetId' if session.assetId exists, otherwise 'playbackId'. + const idType = session.assetId ? 'assetId' : 'playbackId'; + // Log which type of identifier we're using for debugging purposes. + // console.log(`Using ${idType} for video retrieval: ${identifier}`); - const videoUrl = await getVideoUrlAction( - session.assetId || session.playbackId - ); - - if (!videoUrl) { - return notFound(); - } + // Attempt to get the video URL using the determined identifier and type. + const videoUrl = await getVideoUrlAction(identifier, idType); + // If we couldn't get a video URL, return a 'not found' response. + if (!videoUrl) return notFound(); const thumbnail = await generateThumbnailAction(session); diff --git a/packages/app/app/studio/[organization]/library/[session]/page.tsx b/packages/app/app/studio/[organization]/library/[session]/page.tsx index 9cfbc2707..1fdfed003 100644 --- a/packages/app/app/studio/[organization]/library/[session]/page.tsx +++ b/packages/app/app/studio/[organization]/library/[session]/page.tsx @@ -32,13 +32,22 @@ const EditSession = async ({ params, searchParams }: studioPageParams) => { session: params.session, }); - if (!session || !session.playbackId) return notFound(); + // Check if session exists and has a playbackId. If not, return a 'not found' response. + if (!session?.playbackId) return notFound(); + // Determine which identifier to use. Prioritize assetId if it exists, otherwise use playbackId. + const identifier = session.assetId || session.playbackId; + // Set the idType based on which identifier we're using. + // This ternary operation will set 'assetId' if session.assetId exists, otherwise 'playbackId'. + const idType = session.assetId ? 'assetId' : 'playbackId'; - const videoUrl = await getVideoUrlAction(session.assetId as string); + // Log which type of identifier we're using for debugging purposes. + // console.log(`Using ${idType} for video retrieval: ${identifier}`); - if (!videoUrl) { - return notFound(); - } + // Attempt to get the video URL using the determined identifier and type. + const videoUrl = await getVideoUrlAction(identifier, idType); + + // If we couldn't get a video URL, return a 'not found' response. + if (!videoUrl) return notFound(); return (