mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Transcode video before uploading
This commit is contained in:
parent
26ca4aa7f7
commit
813026e734
1 changed files with 16 additions and 0 deletions
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue