login-template/web/myimages.html

40 lines
1.4 KiB
HTML
Raw Normal View History

2024-03-29 11:16:27 -07:00
<!doctype html>
<html lang="en">
<head>
<title>My Images</title>
2024-03-29 11:16:27 -07:00
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
2024-03-29 11:16:27 -07:00
<div id="images" style="display: none"></div>
<button id="showImages-button" onclick="getImages()">Get Images</button>
</body>
<script defer>
async function getImages(user) {
// get current username
let username = JSON.parse(await (await fetch("/account")).text()).username;
// get images for username
2024-03-29 11:16:27 -07:00
let images = JSON.parse(await (await fetch(`/images/by-user/${username}`)).text());
let imagestrings = [];
2024-03-29 11:16:27 -07:00
for (const img of images) {
imagestrings.push(
`<div id='img-${img}'>ID: ${img} <button id='delimg' onclick="deleteImage('${img}')">Delete</button><br><img src="/images/${img}.png" alt="${img}" style="max-width: 100%"></div>`,
);
}
2024-03-29 11:16:27 -07:00
document.getElementById("images").innerHTML = imagestrings.join("<br><br>");
document.getElementById("images").style.display = "";
document.getElementById("showImages-button").style.display = "none";
}
async function deleteImage(uuid) {
// delete the image
alert(await (await fetch(`/images/${uuid}`, { method: "DELETE" })).text());
// remove the image from html
document.getElementById(`img-${uuid}`).remove();
}
</script>
</html>