fix: refactoring of storage method

This commit is contained in:
charlesgauthereau
2026-01-24 13:14:38 +01:00
parent a64a80910d
commit b2c19e7ed0
6 changed files with 77 additions and 31 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ import * as drizzleDb from "@/db";
import {ServerActionResult} from "@/types/action-type";
import {dispatchStorage} from "@/features/storages/dispatch";
import {StorageInput} from "@/features/storages/types";
import sharp from "sharp";
export const uploadUserImageAction = userAction.schema(
@@ -22,6 +23,19 @@ export const uploadUserImageAction = userAction.schema(
const buffer = Buffer.from(arrayBuffer);
const isPng = fileFormat === "png";
const isWebp = fileFormat === "webp";
const compressedBuffer = await sharp(buffer)
.resize({ width: 1024 })
.toFormat(isPng ? "png" : isWebp ? "webp" : "jpeg", {
quality: 80,
compressionLevel: isPng ? 9 : undefined
})
.toBuffer();
const settings = await db.query.setting.findFirst({
where: eq(drizzleDb.schemas.setting.name, "system"),
with: {
@@ -45,7 +59,7 @@ export const uploadUserImageAction = userAction.schema(
action: "upload",
data: {
path: path,
file: buffer,
file: compressedBuffer,
url: true
},
metadata: {