Added upload route handler

This commit is contained in:
Fergal Moran
2024-09-13 19:45:35 +01:00
parent eb33c390bf
commit d52c5670a8
4 changed files with 24 additions and 3 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -52,6 +52,7 @@
"@trpc/react-query": "^11.0.0-rc.446",
"@trpc/server": "^11.0.0-rc.446",
"@types/bcrypt": "^5.0.2",
"@types/http-status-codes": "^1.2.0",
"@types/lodash": "^4.17.7",
"@types/loglevel": "^1.6.3",
"@types/react-copy-to-clipboard": "^5.0.7",
@@ -64,6 +65,7 @@
"drizzle-orm": "^0.33.0",
"embla-carousel-react": "^8.3.0",
"geist": "^1.3.1",
"http-status-codes": "^2.3.0",
"input-otp": "^1.2.4",
"lodash": "^4.17.21",
"loglevel": "^1.9.2",

View File

@@ -1,6 +1,26 @@
import { getServerSession } from "next-auth";
import { NextRequest } from "next/server";
import { StatusCodes } from "http-status-codes";
import { env } from "@/env";
import { type NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const session = await getServerSession();
if (!session) {
return NextResponse.json({
error: "Unauthorized",
status: StatusCodes.UNAUTHORIZED,
});
}
const searchParams = request.nextUrl.searchParams;
const id = searchParams.get("id");
const uploadDir = env.UPLOAD_PATH;
return Response.json(
{
id,
session,
uploadDir,
}
);
}

View File

@@ -45,8 +45,7 @@ const UploadPage: React.FC = () => {
if (e.id && file) {
const body = new FormData();
body.set("image", file);
body.set("id", e.id);
const response = await fetch("/api/upload/profile-image", {
const response = await fetch(`/api/upload/profile-image?${e.id}`, {
method: "POST",
body,
});