Spaces:
Sleeping
Sleeping
import { getPresignedUrl } from '@/lib/aws'; | |
import { withLogging } from '../../../lib/logger'; | |
import { nanoid } from '@/lib/utils'; | |
/** | |
* @param req | |
* @returns | |
*/ | |
export const POST = withLogging( | |
async ( | |
session, | |
json: { | |
id?: string; | |
fileName: string; | |
fileType: string; | |
}, | |
): Promise<Response> => { | |
const user = session?.user?.email ?? 'anonymous'; | |
// if (!email) { | |
// return new Response('Unauthorized', { | |
// status: 401, | |
// }); | |
// } | |
try { | |
const { fileName, fileType, id = nanoid() } = json; | |
const res = await getPresignedUrl(fileName, fileType, id, user); | |
return Response.json(res); | |
} catch (error) { | |
return new Response((error as Error).message, { | |
status: 400, | |
}); | |
} | |
}, | |
); | |