Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Update route.ts (#763)

Ameer Al Ashhab05ae15738b6b
diff --git a/apps/web/app/api/playlist/route.ts b/apps/web/app/api/playlist/route.ts
index 3bfe6b618..f2078f2e5 100644
--- a/apps/web/app/api/playlist/route.ts
+++ b/apps/web/app/api/playlist/route.ts
@@ -73,15 +73,36 @@ const app = new Hono()
const bucket = await createBucketProvider(customBucket);
- if (!customBucket || video.awsBucket === serverEnv().CAP_AWS_BUCKET) {
- if (video.source.type === "desktopMP4") {
- return c.redirect(
- await bucket.getSignedObjectUrl(
- `${video.ownerId}/${videoId}/result.mp4`
- )
- );
+ // Handle .mp4 video streaming
+ if (video.source.type === "desktopMP4" || videoType === "mp4") {
+ const preSignedUrl = await bucket.getSignedObjectUrl(
+ `${video.ownerId}/${videoId}/result.mp4`
+ );
+
+ if (!preSignedUrl)
+ return c.json({ error: true, message: "Video not found" }, 404);
+
+ const videoResponse = await fetch(preSignedUrl);
+
+ if (!videoResponse.ok) {
+ throw new Error(`Failed to fetch video: ${videoResponse.statusText}`);
}
+ const videoBody = videoResponse.body;
+
+ if (!videoBody) {
+ throw new Error("Failed to fetch video body");
+ }
+
+ c.header("Content-Type", "video/mp4");
+ c.header(
+ "Content-Length",
+ videoResponse.headers.get("content-length") || ""
+ );
+ return c.body(videoBody);
+ }
+
+ if (!customBucket || video.awsBucket === serverEnv().CAP_AWS_BUCKET) {
if (video.source.type === "MediaConvert") {
return c.redirect(
await bucket.getSignedObjectUrl(
@@ -150,17 +171,6 @@ const app = new Hono()
});
}
- if (video.source.type === "desktopMP4") {
- const playlistUrl = await bucket.getSignedObjectUrl(
- `${video.ownerId}/${videoId}/result.mp4`
- );
- if (!playlistUrl) return new Response(null, { status: 404 });
-
- console.log(`Got signed url for desktop: ${playlistUrl}`);
-
- return c.redirect(playlistUrl);
- }
-
let prefix;
switch (videoType) {
case "video":