mirror of
https://github.com/fergalmoran/opengifame.git
synced 2025-12-22 09:38:44 +00:00
Added upload route handler
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user