1
0
forked from Kieran/snort

fix: nip96 bugs

This commit is contained in:
kieran 2024-05-01 17:58:40 +01:00
parent 1c44eeabf2
commit e4f611834e
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -1,20 +1,23 @@
import { base64 } from "@scure/base";
import { throwIfOffline } from "@snort/shared";
import { EventKind, EventPublisher } from "@snort/system";
import { Uploader, UploadResult } from "Upload";
import { Uploader, UploadResult } from ".";
export class Nip96Uploader implements Uploader {
constructor(
readonly url: string,
readonly publisher: EventPublisher,
) {}
) { }
get progress() {
return [];
}
async loadInfo() {
const rsp = await fetch(this.url);
const u = new URL(this.url);
const rsp = await fetch(`${u.protocol}//${u.host}/.well-known/nostr/nip96.json`);
return (await rsp.json()) as Nip96Info;
}
@ -30,16 +33,20 @@ export class Nip96Uploader implements Uploader {
const info = await this.loadInfo();
const fd = new FormData();
fd.append("size", file.size.toString());
fd.append("alt", filename);
fd.append("caption", filename);
fd.append("media_type", file.type);
fd.append("file", file);
const rsp = await fetch(info.api_url, {
let u = info.api_url;
if (u.startsWith("/")) {
u = `${this.url}${u.slice(1)}`;
}
const rsp = await fetch(u, {
body: fd,
method: "POST",
headers: {
accept: "application/json",
authorization: await auth(info.api_url, "POST"),
authorization: await auth(u, "POST"),
},
});
if (rsp.ok) {