Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(multipart): extract multipart-utils for subpath and file key helpers

Richie McIlroyd8f527b22f0f
diff --git a/apps/web/app/api/upload/[...route]/multipart-utils.ts b/apps/web/app/api/upload/[...route]/multipart-utils.ts
new file mode 100644
index 000000000..8365d747e
--- /dev/null
+++ b/apps/web/app/api/upload/[...route]/multipart-utils.ts
@@ -0,0 +1,34 @@
+import { parseVideoIdOrFileKey } from "../utils";
+
+export const getSubpath = (input: { subpath?: string; fileKey?: string }) => {
+ if ("fileKey" in input) {
+ return undefined;
+ }
+
+ return input.subpath ?? "result.mp4";
+};
+
+export const getMultipartFileKey = (
+ userId: string,
+ input:
+ | { videoId?: string; subpath?: string }
+ | {
+ fileKey?: string;
+ },
+) => {
+ if ("fileKey" in input && input.fileKey) {
+ return parseVideoIdOrFileKey(userId, { fileKey: input.fileKey });
+ }
+
+ if (!("videoId" in input) || !input.videoId) {
+ throw new Error("Video id not found");
+ }
+
+ return parseVideoIdOrFileKey(userId, {
+ videoId: input.videoId,
+ subpath: input.subpath ?? "result.mp4",
+ });
+};
+
+export const isRawRecorderUpload = (subpath: string) =>
+ subpath.startsWith("raw-upload.");