From 813026e734d99527cff9c171666bc1fa0eeac914 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 28 Feb 2025 09:36:26 -0600 Subject: [PATCH] Transcode video before uploading --- packages/ditto/utils/upload.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/ditto/utils/upload.ts b/packages/ditto/utils/upload.ts index 1dcce807..3fe6ac94 100644 --- a/packages/ditto/utils/upload.ts +++ b/packages/ditto/utils/upload.ts @@ -1,3 +1,4 @@ +import { transcodeVideo } from '@ditto/transcode'; import { HTTPException } from '@hono/hono/http-exception'; import { logi } from '@soapbox/logi'; import { crypto } from '@std/crypto'; @@ -35,6 +36,21 @@ export async function uploadFile( throw new Error('File size is too large.'); } + const [baseType] = file.type.split('/'); + + if (baseType === 'video') { + file = new Proxy(file, { + get(target, prop) { + if (prop === 'stream') { + return () => transcodeVideo(target.stream()); + } else { + // @ts-ignore This is fine. + return target[prop]; + } + }, + }); + } + const tags = await uploader.upload(file, { signal }); const url = tags[0][1];