Transcode video before uploading

This commit is contained in:
Alex Gleason 2025-02-28 09:36:26 -06:00
parent 26ca4aa7f7
commit 813026e734
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

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