route96/ui/index.html
kieran 5547673331
Some checks failed
continuous-integration/drone/push Build is failing
feat: list files (nip96)
2024-05-29 14:31:44 +01:00

134 lines
3.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>void_cat_rs</title>
<style>
html {
background-color: black;
color: white;
font-size: 15px;
font-weight: 400;
font-family: Arial, serif;
}
.flex {
display: flex;
}
.flex-col {
flex-direction: column;
}
.gap-2 {
gap: 0.5rem;
}
</style>
<script>
async function dumpToLog(rsp) {
console.debug(rsp);
const text = await rsp.text();
if (rsp.ok) {
document.querySelector("#log").append(JSON.stringify(JSON.parse(text), undefined, 2));
} else {
document.querySelector("#log").append(text);
}
document.querySelector("#log").append("\n");
}
async function listFiles() {
try {
const auth_event = await window.nostr.signEvent({
kind: 27235,
created_at: Math.floor(new Date().getTime() / 1000),
content: "",
tags: [
["u", `${window.location.protocol}//${window.location.host}/n96`],
["method", "GET"]
]
});
const rsp = await fetch("/n96?page=0&count=100", {
method: "GET",
headers: {
accept: "application/json",
authorization: `Nostr ${btoa(JSON.stringify(auth_event))}`,
},
});
await dumpToLog(rsp);
} catch (e) {
}
}
async function uploadFiles(e) {
try {
const input = document.querySelector("#file");
const file = input.files[0];
console.debug(file);
const fd = new FormData();
fd.append("size", file.size.toString());
fd.append("caption", file.name);
fd.append("media_type", file.type);
fd.append("file", file);
fd.append("no_transform", document.querySelector("#no_transform").checked.toString())
const auth_event = await window.nostr.signEvent({
kind: 27235,
created_at: Math.floor(new Date().getTime() / 1000),
content: "",
tags: [
["u", `${window.location.protocol}//${window.location.host}/n96`],
["method", "POST"]
]
});
const rsp = await fetch("/n96", {
body: fd,
method: "POST",
headers: {
accept: "application/json",
authorization: `Nostr ${btoa(JSON.stringify(auth_event))}`,
},
});
await dumpToLog(rsp);
} catch (ex) {
if (ex instanceof Error) {
alert(ex.message);
}
}
}
</script>
</head>
<body>
<h1>
Welcome to void_cat_rs
</h1>
<div class="flex flex-col gap-2">
<div>
Upload a file using NIP-96
</div>
<div style="color: #ff8383;">
You must have a nostr extension for this to work
</div>
<input type="file" id="file">
<div>
<input type="checkbox" id="no_transform">
<label for="no_transform">
Disable compression (images)
</label>
</div>
<div>
<button type="submit" onclick="uploadFiles(event)">
Upload
</button>
</div>
<div>
<button type="submit" onclick="listFiles()">
List Uploads
</button>
</div>
</div>
<pre id="log"></pre>
</body>
</html>