Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
refactor: get video length but don't process over 500MB
Marc Seitzdb26a9abc9a9
diff --git a/lib/trigger/optimize-video-files.ts b/lib/trigger/optimize-video-files.tsindex 064647f0..efd77621 100644--- a/lib/trigger/optimize-video-files.ts+++ b/lib/trigger/optimize-video-files.ts@@ -21,8 +21,9 @@ export const processVideo = task({teamId: string;docId: string;documentVersionId: string;+ fileSize: number;}) => {- const { videoUrl, teamId, docId, documentVersionId } = payload;+ const { videoUrl, teamId, docId, documentVersionId, fileSize } = payload;try {const fileUrl = await getFile({@@ -84,6 +85,29 @@ export const processVideo = task({});});+ // Update document version with metadata+ await prisma.documentVersion.update({+ where: { id: documentVersionId },+ data: {+ length: metadata.duration,+ },+ });++ if (fileSize > 500 * 1024 * 1024) {+ // if file size is greater than 500MB, skip optimization+ logger.info(+ `File size is ${fileSize / 1024 / 1024} MB, skipping optimization`,+ );++ // Clean up temporary directory+ await fs.rm(tempDirectory, { recursive: true });+ logger.info("Temporary directory cleaned up", { tempDirectory });+ return {+ success: true,+ message: "File size is too large, skipping optimization",+ };+ }+// Calculate encoding parametersconst keyframeInterval = Math.round(metadata.fps * 2);const bitrate = "6000k";@@ -184,7 +208,6 @@ export const processVideo = task({},data: {file: data,- length: metadata.duration,},});diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex 491391bd..57a97281 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -307,17 +307,13 @@ export default async function handle(}if (type === "video") {- if (fileSize && fileSize > 500 * 1024 * 1024) {- // INFO: if the file size is greater than 500MB, skip the video processing- return res.status(201).json(document);- }-await processVideo.trigger({videoUrl: fileUrl,teamId,docId: fileUrl.split("/")[1], // Extract doc_xxxx from teamId/doc_xxxx/filenamedocumentVersionId: document.versions[0].id,+ fileSize: fileSize || 0,},{idempotencyKey: `${teamId}-${document.versions[0].id}`,