API routes now return proper Responses and basic errors are handled

slight improvements in layouting
This commit is contained in:
2023-07-02 23:39:31 +02:00
parent ece3b3634c
commit 24ddd39f35
12 changed files with 349 additions and 78 deletions

View File

@ -6,7 +6,6 @@ import { error } from '@sveltejs/kit';
export const POST = (async ({ request }) => {
const data = await request.json();
console.log(data)
const filePath = path.join(
process.cwd(),
"static",
@ -14,13 +13,13 @@ export const POST = (async ({ request }) => {
data.filename as string
);
const file = data.image;
console.log(data.headers)
if(data.bearer === BEARER_TOKEN){
console.log("PASSWORD CORRECT")
writeFileSync(filePath, file, 'base64');
return new Response(JSON.stringify({msg: "Added image successfully"}),{
status: 200,
});
}
else{
console.log("PASSWORD INCORRECT")
throw error(403, "Password incorrect")
}