mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 05:26:24 +09:00
more pr fixes
This commit is contained in:
1 parent
c00b96675d
commit
16793374ec
2 files changed
+14
-13
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { UploadHandlerPart } from "@remix-run/node";
|
||||
import { z } from "zod";
|
||||
import { NodeOnDiskFile } from "@remix-run/node";
|
||||
import { DEFAULT_UPLPOAD_PATH } from "./constants";
|
||||
@@ -21,7 +20,7 @@ export const s3EnvVariables = z.object({
|
||||
S3_ACCESS_KEY_ID: z.string(),
|
||||
S3_SECRET_ACCESS_KEY: z.string(),
|
||||
S3_BUCKET: z.string(),
|
||||
S3_ACL: z.string().optional(),
|
||||
S3_ACL: z.string().optional().default("public-read"),
|
||||
});
|
||||
|
||||
export const fsEnvVariables = z.object({
|
||||
@@ -31,11 +30,3 @@ export const fsEnvVariables = z.object({
|
||||
export const assetEnvVariables = z.object({
|
||||
MAX_UPLOAD_SIZE: z.number().optional().default(10),
|
||||
});
|
||||
|
||||
export type S3UploadHandler = ({
|
||||
file,
|
||||
maxPartSize,
|
||||
}: {
|
||||
file: UploadHandlerPart;
|
||||
maxPartSize: number;
|
||||
}) => Promise<File | string | null | undefined>;
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UploadHandlerPart } from "@remix-run/node";
|
||||
import { PutObjectCommandInput, S3Client } from "@aws-sdk/client-s3";
|
||||
import { Upload } from "@aws-sdk/lib-storage";
|
||||
import ObjectID from "bson-objectid";
|
||||
@@ -7,20 +8,29 @@ import {
|
||||
assetEnvVariables,
|
||||
ImagesUploadedSuccess,
|
||||
s3EnvVariables,
|
||||
S3UploadHandler,
|
||||
} from "../../schema";
|
||||
import {
|
||||
getArrayBufferFromIterable,
|
||||
getFilenameAndExtension,
|
||||
} from "../../helpers/array-buffer-helpers";
|
||||
|
||||
export type S3UploadHandler = ({
|
||||
file,
|
||||
maxPartSize,
|
||||
}: {
|
||||
file: UploadHandlerPart;
|
||||
maxPartSize: number;
|
||||
}) => Promise<string>;
|
||||
|
||||
export const s3UploadHandler: S3UploadHandler = async ({
|
||||
file: { data, filename: baseFileName, contentType },
|
||||
maxPartSize,
|
||||
}) => {
|
||||
const s3Envs = s3EnvVariables.parse(process.env);
|
||||
const { MAX_UPLOAD_SIZE } = assetEnvVariables.parse(process.env);
|
||||
if (!data) return;
|
||||
if (!data) {
|
||||
throw new Error("Your asset seems to be empty");
|
||||
}
|
||||
const filename = baseFileName ?? ObjectID().toString();
|
||||
|
||||
const uint8Array = await getArrayBufferFromIterable(data);
|
||||
@@ -34,7 +44,7 @@ export const s3UploadHandler: S3UploadHandler = async ({
|
||||
|
||||
const params: PutObjectCommandInput = {
|
||||
Bucket: s3Envs.S3_BUCKET,
|
||||
ACL: s3Envs.S3_ACL ?? "public-read",
|
||||
ACL: s3Envs.S3_ACL,
|
||||
Key: key,
|
||||
Body: uint8Array,
|
||||
ContentType: contentType,
|
||||
|
||||
Reference in new issue
Block a user