Add support for storing images in S3 (#896)

This commit is contained in:
solidDoWant
2025-04-20 11:47:49 -05:00
committed by GitHub
parent 1d1ea295c0
commit 099d893da9
3 changed files with 29 additions and 9 deletions
+4 -4
View File
@@ -1,4 +1,3 @@
import { mkdir, writeFile } from "node:fs/promises";
import path from "node:path";
import { encode } from "blurhash";
import { type SQL, and, eq, is, lt, sql } from "drizzle-orm";
@@ -9,10 +8,9 @@ import sharp from "sharp";
import { type Transaction, db } from "~/db";
import { mqueue } from "~/db/schema/mqueue";
import type { Image } from "~/models/utils";
import { getFile } from "~/utils";
export const imageDir = process.env.IMAGES_PATH ?? "./images";
await mkdir(imageDir, { recursive: true });
export const defaultBlurhash = "000000";
type ImageTask = {
@@ -164,7 +162,9 @@ async function downloadImage(id: string, url: string): Promise<string> {
await Promise.all(
Object.entries(resolutions).map(async ([resolution, dimensions]) => {
const buffer = await image.clone().resize(dimensions.width).toBuffer();
await writeFile(path.join(imageDir, `${id}.${resolution}.jpg`), buffer);
const file = getFile(path.join(imageDir, `${id}.${resolution}.jpg`));
await Bun.write(file, buffer, { mode: 0o660 });
}),
);