feat: no_transform

This commit is contained in:
kieran 2024-05-29 12:14:00 +01:00
parent a85dbf88b9
commit a9a9ba6328
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 77 additions and 44 deletions

View File

@ -6,7 +6,8 @@ Image hosting service
- [NIP-96 Support](https://github.com/nostr-protocol/nips/blob/master/96.md)
- [Blossom Support](https://github.com/hzrd149/blossom/blob/master/buds/bud-01.md)
- Image compression to WebP (FFMPEG, NIP-96)
- Blurhash calculation (NIP-96)
- Blurhash calculation (NIP-96 only)
- AI image labeling ([ViT224](https://huggingface.co/google/vit-base-patch16-224))
## Planned
- Torrent seed V2

View File

@ -117,6 +117,7 @@ struct Nip96Form<'r> {
caption: Option<&'r str>,
media_type: Option<&'r str>,
content_type: Option<&'r str>,
no_transform: Option<bool>,
}
pub fn nip96_routes() -> Vec<Route> {
@ -161,6 +162,9 @@ async fn upload(
return Nip96Response::error("File too large");
}
}
if form.size > settings.max_upload_bytes {
return Nip96Response::error("File too large");
}
let file = match form.file.open().await {
Ok(f) => f,
Err(e) => return Nip96Response::error(&format!("Could not open file: {}", e)),
@ -175,7 +179,7 @@ async fn upload(
}
}
match fs
.put(file, mime_type, true)
.put(file, mime_type, !form.no_transform.unwrap_or(false))
.await
{
Ok(blob) => {

View File

@ -7,10 +7,26 @@
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 uploadFiles(e) {
try {
const input = document.querySelector("#file");
const file = input.files[0];
console.debug(file);
@ -20,6 +36,7 @@
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,
@ -46,6 +63,11 @@
document.querySelector("#log").append(text);
}
document.querySelector("#log").append("\n");
} catch (ex) {
if (ex instanceof Error) {
alert(ex.message);
}
}
}
</script>
</head>
@ -53,20 +75,26 @@
<h1>
Welcome to void_cat_rs
</h1>
<div class="flex flex-col gap-2">
<div>
<p>
Upload a file using NIP-96
</p>
<small>
</div>
<div style="color: #ff8383;">
You must have a nostr extension for this to work
</small>
</div>
<input type="file" id="file">
<div>
<input type="checkbox" id="no_transform">
<label for="no_transform">
Disable compression (images)
</label>
</div>
<div>
<input type="file" id="file">
<button type="submit" onclick="uploadFiles(event)">
Upload
</button>
</div>
</div>
<pre id="log"></pre>
</body>
</html>