Merge branch 'upload-conf' into 'main'

Remove `@/config.ts` import from utils/upload.ts

See merge request soapbox-pub/ditto!703
This commit is contained in:
Alex Gleason 2025-02-27 23:34:52 +00:00
commit 6874527ea4

View file

@ -6,7 +6,6 @@ import { encode } from 'blurhash';
import sharp from 'sharp'; import sharp from 'sharp';
import { AppContext } from '@/app.ts'; import { AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import { DittoUpload, dittoUploads } from '@/DittoUploads.ts'; import { DittoUpload, dittoUploads } from '@/DittoUploads.ts';
import { errorJson } from '@/utils/log.ts'; import { errorJson } from '@/utils/log.ts';
@ -22,7 +21,8 @@ export async function uploadFile(
meta: FileMeta, meta: FileMeta,
signal?: AbortSignal, signal?: AbortSignal,
): Promise<DittoUpload> { ): Promise<DittoUpload> {
const uploader = c.get('uploader'); const { conf, uploader } = c.var;
if (!uploader) { if (!uploader) {
throw new HTTPException(500, { throw new HTTPException(500, {
res: c.json({ error: 'No uploader configured.' }), res: c.json({ error: 'No uploader configured.' }),
@ -31,7 +31,7 @@ export async function uploadFile(
const { pubkey, description } = meta; const { pubkey, description } = meta;
if (file.size > Conf.maxUploadSize) { if (file.size > conf.maxUploadSize) {
throw new Error('File size is too large.'); throw new Error('File size is too large.');
} }
@ -63,7 +63,7 @@ export async function uploadFile(
// If the uploader didn't already, try to get a blurhash and media dimensions. // 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. // This requires `MEDIA_ANALYZE=true` to be configured because it comes with security tradeoffs.
if (Conf.mediaAnalyze && (!blurhash || !dim)) { 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);