Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add image content types for upload presigning

Richie McIlroyfd741b15db96
diff --git a/apps/web/actions/video/upload.ts b/apps/web/actions/video/upload.ts
index 1a66aa17a..f2be03256 100644
--- a/apps/web/actions/video/upload.ts
+++ b/apps/web/actions/video/upload.ts
@@ -48,11 +48,15 @@ async function getVideoUploadPresignedUrl({
? "audio/webm"
: fileKey.endsWith(".mp4")
? "video/mp4"
- : fileKey.endsWith(".mp3")
- ? "audio/mpeg"
- : fileKey.endsWith(".m3u8")
- ? "application/x-mpegURL"
- : "video/mp2t";
+ : fileKey.endsWith(".jpg") || fileKey.endsWith(".jpeg")
+ ? "image/jpeg"
+ : fileKey.endsWith(".png")
+ ? "image/png"
+ : fileKey.endsWith(".mp3")
+ ? "audio/mpeg"
+ : fileKey.endsWith(".m3u8")
+ ? "application/x-mpegURL"
+ : "video/mp2t";
const Fields = {
"x-amz-meta-userid": userId,
@@ -115,6 +119,7 @@ export async function createVideoAndGetUploadUrl({
isUpload = false,
folderId,
orgId,
+ screenshotContentType,
supportsUploadProgress = false,
}: {
videoId?: Video.VideoId;
@@ -126,6 +131,7 @@ export async function createVideoAndGetUploadUrl({
isUpload?: boolean;
folderId?: Folder.FolderId;
orgId: Organisation.OrganisationId;
+ screenshotContentType?: string;
// TODO: Remove this once we are happy with it's stability
supportsUploadProgress?: boolean;
}) {
@@ -161,8 +167,12 @@ export async function createVideoAndGetUploadUrl({
updatedAt: existingVideo.updatedAt.toISOString(),
metadata: existingVideo.metadata,
});
+ const screenshotExtension =
+ screenshotContentType?.toLowerCase() === "image/png" ? "png" : "jpg";
const fileKey = `${user.id}/${videoId}/${
- isScreenshot ? "screenshot/screen-capture.jpg" : "result.mp4"
+ isScreenshot
+ ? `screenshot/screen-capture.${screenshotExtension}`
+ : "result.mp4"
}`;
const { presignedPostData, upload } = await getVideoUploadPresignedUrl({
fileKey,
@@ -184,8 +194,12 @@ export async function createVideoAndGetUploadUrl({
const idToUse = Video.VideoId.make(videoId || nanoId());
+ const screenshotExtension =
+ screenshotContentType?.toLowerCase() === "image/png" ? "png" : "jpg";
const fileKey = `${user.id}/${idToUse}/${
- isScreenshot ? "screenshot/screen-capture.jpg" : "result.mp4"
+ isScreenshot
+ ? `screenshot/screen-capture.${screenshotExtension}`
+ : "result.mp4"
}`;
const { presignedPostData, upload, bucketId, storageIntegrationId } =
await getVideoUploadPresignedUrl({
diff --git a/apps/web/app/api/upload/[...route]/signed.ts b/apps/web/app/api/upload/[...route]/signed.ts
index 63224b0f7..48f6f3813 100644
--- a/apps/web/app/api/upload/[...route]/signed.ts
+++ b/apps/web/app/api/upload/[...route]/signed.ts
@@ -23,6 +23,7 @@ function contentTypeForSubpath(subpath: string): string {
if (subpath.endsWith(".mp4") || subpath.endsWith(".m4s")) return "video/mp4";
if (subpath.endsWith(".jpg") || subpath.endsWith(".jpeg"))
return "image/jpeg";
+ if (subpath.endsWith(".png")) return "image/png";
if (subpath.endsWith(".aac")) return "audio/aac";
if (subpath.endsWith(".webm")) return "audio/webm";
if (subpath.endsWith(".m3u8")) return "application/x-mpegURL";
@@ -145,7 +146,11 @@ app.post(
? "audio/mpeg"
: fileKey.endsWith(".m3u8")
? "application/x-mpegURL"
- : "video/mp2t";
+ : fileKey.endsWith(".jpg") || fileKey.endsWith(".jpeg")
+ ? "image/jpeg"
+ : fileKey.endsWith(".png")
+ ? "image/png"
+ : "video/mp2t";
const data = await Effect.gen(function* () {
const [bucket] = yield* Storage.getAccessForVideo(videoDomain);