Skip to content

Commit

Permalink
deploy s3 6
Browse files Browse the repository at this point in the history
  • Loading branch information
aliamerj committed Mar 10, 2024
1 parent e866f44 commit bb52dec
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions app/api/project/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../auth/[...nextauth]/route";
import sharp from 'sharp'
import {
projectSchema,
updateProjectSchema,
Expand Down Expand Up @@ -63,19 +62,19 @@ export async function POST(request: NextRequest) {
} = validation.data;

try {
var imageUrl;
if (logo && logo instanceof File) {
imageUrl = await setImageInBucket(
session.user.id!,
`${session.user.id!}-${name}`,
logo,
);
}
// let imageUrl = "x";
// if (logo && logo instanceof File) {
// imageUrl = await setImageInBucket(
// session.user.id!,
// `${session.user.id!}-${name}`,
// logo,
// );
// }

const newProject: ProjectInsertion = {
owner: session.user.id!,
name: name,
logo: imageUrl && imageUrl.split("?")[0],
logo: "x", // imageUrl && imageUrl.split("?")[0],
type: type as ProjectSelection["type"],
link: link,
projectGoal: projectGoal,
Expand Down Expand Up @@ -256,8 +255,6 @@ function serializeProjectData(project: FormData) {
}

async function setImageInBucket(userId: string, logoKey: string, logo: File) {
const img = Buffer.from(await logo.arrayBuffer())
const resizedImageBuffer = await sharp(img).resize(400,500).toBuffer()
const signedUrl = await getSignedUrl(
s3,
uploadProjectLogo(logoKey, logo.type, logo.size, userId),
Expand All @@ -268,7 +265,7 @@ async function setImageInBucket(userId: string, logoKey: string, logo: File) {

fetch(signedUrl, {
method: "PUT",
body: resizedImageBuffer,
body: logo,
headers: {
"content-type": logo.type,
},
Expand Down

0 comments on commit bb52dec

Please sign in to comment.