feat: no_transform
This commit is contained in:
parent
a85dbf88b9
commit
a9a9ba6328
@ -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
|
||||
|
@ -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) => {
|
||||
|
112
ui/index.html
112
ui/index.html
@ -7,45 +7,67 @@
|
||||
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) {
|
||||
const input = document.querySelector("#file");
|
||||
const file = input.files[0];
|
||||
console.debug(file);
|
||||
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);
|
||||
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))}`,
|
||||
},
|
||||
});
|
||||
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);
|
||||
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))}`,
|
||||
},
|
||||
});
|
||||
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");
|
||||
} catch (ex) {
|
||||
if (ex instanceof Error) {
|
||||
alert(ex.message);
|
||||
}
|
||||
}
|
||||
document.querySelector("#log").append("\n");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
@ -53,19 +75,25 @@
|
||||
<h1>
|
||||
Welcome to void_cat_rs
|
||||
</h1>
|
||||
<div>
|
||||
<p>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div>
|
||||
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>
|
||||
<div>
|
||||
</div>
|
||||
<input type="file" id="file">
|
||||
<button type="submit" onclick="uploadFiles(event)">
|
||||
Upload
|
||||
</button>
|
||||
<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>
|
||||
<pre id="log"></pre>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user