chore: optimize code for type safe
This commit is contained in:
parent
9c120d776d
commit
0684b16278
@ -6,7 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server';
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { key } = body;
|
||||
const { key } = body as { key: string };
|
||||
|
||||
if (!key) {
|
||||
return NextResponse.json(
|
||||
|
@ -6,7 +6,11 @@ import { type NextRequest, NextResponse } from 'next/server';
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { filename, contentType, folder } = body;
|
||||
const { filename, contentType, folder } = body as {
|
||||
filename: string;
|
||||
contentType: string;
|
||||
folder: string;
|
||||
};
|
||||
|
||||
if (!filename) {
|
||||
return NextResponse.json(
|
||||
|
@ -125,7 +125,7 @@ export const uploadFileFromBrowser = async (
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
const error = (await response.json()) as { message: string };
|
||||
throw new Error(error.message || 'Failed to upload file');
|
||||
}
|
||||
|
||||
@ -147,11 +147,14 @@ export const uploadFileFromBrowser = async (
|
||||
});
|
||||
|
||||
if (!presignedUrlResponse.ok) {
|
||||
const error = await presignedUrlResponse.json();
|
||||
const error = (await presignedUrlResponse.json()) as { message: string };
|
||||
throw new Error(error.message || 'Failed to get pre-signed URL');
|
||||
}
|
||||
|
||||
const { url, key } = await presignedUrlResponse.json();
|
||||
const { url, key } = (await presignedUrlResponse.json()) as {
|
||||
url: string;
|
||||
key: string;
|
||||
};
|
||||
|
||||
// Then upload directly to the storage provider
|
||||
const uploadResponse = await fetch(url, {
|
||||
@ -176,7 +179,7 @@ export const uploadFileFromBrowser = async (
|
||||
});
|
||||
|
||||
if (!fileUrlResponse.ok) {
|
||||
const error = await fileUrlResponse.json();
|
||||
const error = (await fileUrlResponse.json()) as { message: string };
|
||||
throw new Error(error.message || 'Failed to get file URL');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user