Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Reupload video to same ID if it no longer exists

Richie McIlroy3894c058bb63
diff --git a/apps/web/app/api/desktop/video/app.ts b/apps/web/app/api/desktop/video/app.ts
index 844d2fb70..4b2aa4ecd 100644
--- a/apps/web/app/api/desktop/video/app.ts
+++ b/apps/web/app/api/desktop/video/app.ts
@@ -47,7 +47,6 @@ app.get(
const s3Config = await getS3Config(bucket);
const bucketName = await getS3Bucket(bucket);
- const id = nanoId();
const date = new Date();
const formattedDate = `${date.getDate()} ${date.toLocaleString("default", {
month: "long",
@@ -59,18 +58,20 @@ app.get(
.from(videos)
.where(eq(videos.id, videoId));
- if (!video) return c.json({ error: "video_not_found" }, { status: 404 });
-
- return c.json({
- id: video.id,
- user_id: user.id,
- aws_region: video.awsRegion,
- aws_bucket: video.awsBucket,
- });
+ if (video) {
+ return c.json({
+ id: video.id,
+ user_id: user.id,
+ aws_region: video.awsRegion,
+ aws_bucket: video.awsBucket,
+ });
+ }
}
+ const idToUse = videoId !== undefined ? videoId : nanoId();
+
const videoData = {
- id: id,
+ id: idToUse,
name: `Cap ${
isScreenshot ? "Screenshot" : "Recording"
} - ${formattedDate}`,
@@ -91,9 +92,9 @@ app.get(
if (clientEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production")
await dub.links.create({
- url: `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`,
+ url: `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${idToUse}`,
domain: "cap.link",
- key: id,
+ key: idToUse,
});
// Check if this is the user's first video and send the first shareable link email
@@ -114,8 +115,8 @@ app.get(
);
const videoUrl = clientEnv.NEXT_PUBLIC_IS_CAP
- ? `https://cap.link/${id}`
- : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`;
+ ? `https://cap.link/${idToUse}`
+ : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${idToUse}`;
// Send email with 5-minute delay using Resend's scheduling feature
await sendEmail({
@@ -139,7 +140,7 @@ app.get(
}
return c.json({
- id,
+ id: idToUse,
user_id: user.id,
aws_region: s3Config.region,
aws_bucket: bucketName,