mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Make media analyze optional (disabled by default)
This commit is contained in:
parent
721fe52142
commit
f987effc15
2 changed files with 10 additions and 1 deletions
|
|
@ -201,6 +201,13 @@ class Conf {
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Whether to analyze media metadata with [blurhash](https://www.npmjs.com/package/blurhash) and [sharp](https://www.npmjs.com/package/sharp).
|
||||||
|
* This is prone to security vulnerabilities, which is why it's not enabled by default.
|
||||||
|
*/
|
||||||
|
static get mediaAnalyze(): boolean {
|
||||||
|
return optionalBooleanSchema.parse(Deno.env.get('MEDIA_ANALYZE')) ?? false;
|
||||||
|
}
|
||||||
/** Max upload size for files in number of bytes. Default 100MiB. */
|
/** Max upload size for files in number of bytes. Default 100MiB. */
|
||||||
static get maxUploadSize(): number {
|
static get maxUploadSize(): number {
|
||||||
return Number(Deno.env.get('MAX_UPLOAD_SIZE') || 100 * 1024 * 1024);
|
return Number(Deno.env.get('MAX_UPLOAD_SIZE') || 100 * 1024 * 1024);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,9 @@ export async function uploadFile(
|
||||||
tags.push(['m', file.type]);
|
tags.push(['m', file.type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!blurhash || !dim) {
|
// If the uploader didn't already, try to get a blurhash and media dimensions.
|
||||||
|
// This requires `MEDIA_ANALYZE=true` to be configured because it comes with security tradeoffs.
|
||||||
|
if (Conf.mediaAnalyze && (!blurhash || !dim)) {
|
||||||
try {
|
try {
|
||||||
const bytes = await new Response(file.stream()).bytes();
|
const bytes = await new Response(file.stream()).bytes();
|
||||||
const img = sharp(bytes);
|
const img = sharp(bytes);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue