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];