mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: refactoring of storage method
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user