bodge img upload on edit if no img available

This commit is contained in:
Alexander Bocken 2023-07-13 18:18:01 +02:00
parent 878aeff52d
commit be331343e7
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8
2 changed files with 7 additions and 5 deletions

View File

@ -10,7 +10,7 @@ export const POST = (async ({ request }) => {
if(data.bearer === BEARER_TOKEN){ if(data.bearer === BEARER_TOKEN){
[ "full", "thumb", "placeholder"].forEach((folder) => { [ "full", "thumb", "placeholder"].forEach((folder) => {
unlink(path.join(IMAGE_DIR, "rezepte", folder, data.name + ".webp"), (e) => { unlink(path.join(IMAGE_DIR, "rezepte", folder, data.name + ".webp"), (e) => {
if(e) throw error(500, "could not delete: " + folder + "/" + data.name + ".webp") if(e) error(404, "could not delete: " + folder + "/" + data.name + ".webp" + e)
}) })
}) })
return new Response(JSON.stringify({msg: "Deleted image successfully"}),{ return new Response(JSON.stringify({msg: "Deleted image successfully"}),{

View File

@ -136,10 +136,12 @@
// two cases: // two cases:
//new image uploaded (not implemented yet) //new image uploaded (not implemented yet)
// new short_name -> move images as well // new short_name -> move images as well
// if new image // if new image
console.log("img_local", img_local)
if(img_local != ""){ if(img_local != ""){
async function delete_img(){ async function delete_img(){
const res_img = await fetch('/api/img/delete', { const res = await fetch('/api/img/delete', {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
name: old_short_name, name: old_short_name,
@ -150,8 +152,8 @@
bearer: password bearer: password
} }
}) })
if(!res_img.ok){ if(!res.ok){
const item = await res_img.json(); const item = await res.json();
alert(item.message) alert(item.message)
} }
} }
@ -171,7 +173,7 @@
body: JSON.stringify(data) body: JSON.stringify(data)
}); });
if(!res.ok){ if(!res.ok){
const item = await res_img.json(); const item = await res.json();
alert(item.message) alert(item.message)
} }
} }