mirror of
https://github.com/v0l/route96.git
synced 2025-06-16 00:08:10 +00:00
feat: blossom media uploads
fix: file extensions in URLs
This commit is contained in:
@ -34,6 +34,22 @@ export class Blossom {
|
||||
}
|
||||
}
|
||||
|
||||
async media(file: File) {
|
||||
const hash = await window.crypto.subtle.digest(
|
||||
"SHA-256",
|
||||
await file.arrayBuffer(),
|
||||
);
|
||||
const tags = [["x", bytesToString("hex", new Uint8Array(hash))]];
|
||||
|
||||
const rsp = await this.#req("/media", "PUT", file, tags);
|
||||
if (rsp.ok) {
|
||||
return (await rsp.json()) as BlobDescriptor;
|
||||
} else {
|
||||
const text = await rsp.text();
|
||||
throw new Error(text);
|
||||
}
|
||||
}
|
||||
|
||||
async #req(
|
||||
path: string,
|
||||
method: "GET" | "POST" | "DELETE" | "PUT",
|
||||
@ -42,7 +58,7 @@ export class Blossom {
|
||||
) {
|
||||
throwIfOffline();
|
||||
|
||||
const url = `${this.url}upload`;
|
||||
const url = `${this.url}${path}`;
|
||||
const now = unixNow();
|
||||
const auth = async (url: string, method: string) => {
|
||||
const auth = await this.publisher.generic((eb) => {
|
||||
|
@ -31,7 +31,7 @@ export default function Upload() {
|
||||
setError(undefined);
|
||||
if (type === "blossom") {
|
||||
const uploader = new Blossom(url, pub);
|
||||
const result = await uploader.upload(toUpload);
|
||||
const result = noCompress ? await uploader.upload(toUpload) : await uploader.media(toUpload);
|
||||
setResults((s) => [...s, result]);
|
||||
}
|
||||
if (type === "nip96") {
|
||||
@ -128,15 +128,13 @@ export default function Upload() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{type === "nip96" && (
|
||||
<div
|
||||
className="flex gap-2 cursor-pointer"
|
||||
onClick={() => setNoCompress((s) => !s)}
|
||||
>
|
||||
Disable Compression
|
||||
<input type="checkbox" checked={noCompress} />
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className="flex gap-2 cursor-pointer"
|
||||
onClick={() => setNoCompress((s) => !s)}
|
||||
>
|
||||
Disable Compression
|
||||
<input type="checkbox" checked={noCompress} />
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={async () => {
|
||||
|
Reference in New Issue
Block a user