fix(route): update parameter type for PATCH function and correct image directory handling
This commit is contained in:
@@ -6,16 +6,16 @@ const API_BASE =
|
|||||||
|
|
||||||
export async function PATCH(
|
export async function PATCH(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: { id: string } },
|
{ params }: { params: Promise<{ id: string }> },
|
||||||
) {
|
) {
|
||||||
|
const { id } = await params;
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session || (session.user as any)?.role !== 'admin') {
|
if (!session || (session.user as any)?.role !== 'admin') {
|
||||||
return NextResponse.json({ message: 'Förbjuden' }, { status: 403 });
|
return NextResponse.json({ message: 'Förbjuden' }, { status: 403 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const res = await fetch(`${API_BASE}/api/users/${params.id}/role`, {
|
const res = await fetch(`${API_BASE}/api/users/${id}/role`, {
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${session.accessToken}`,
|
Authorization: `Bearer ${session.accessToken}`,
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const IMAGE_DIR = process.env.IMAGE_DIR || '/app/public/images';
|
// turbopackIgnore: true — IMAGE_DIR är en runtime env-variabel, inte statisk sökväg
|
||||||
|
const IMAGE_DIR: string = /* turbopackIgnore: true */ (process.env.IMAGE_DIR || '/app/public/images') as string;
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
_request: NextRequest,
|
_request: NextRequest,
|
||||||
@@ -15,7 +16,7 @@ export async function GET(
|
|||||||
return new NextResponse('Not found', { status: 404 });
|
return new NextResponse('Not found', { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = path.join(/*turbopackIgnore: true*/ IMAGE_DIR, filename);
|
const filePath = path.join(IMAGE_DIR, filename);
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
return new NextResponse('Not found', { status: 404 });
|
return new NextResponse('Not found', { status: 404 });
|
||||||
|
|||||||
Reference in New Issue
Block a user