fix: nip96 bugs
This commit is contained in:
@ -1,20 +1,23 @@
|
|||||||
import { base64 } from "@scure/base";
|
import { base64 } from "@scure/base";
|
||||||
import { throwIfOffline } from "@snort/shared";
|
import { throwIfOffline } from "@snort/shared";
|
||||||
import { EventKind, EventPublisher } from "@snort/system";
|
import { EventKind, EventPublisher } from "@snort/system";
|
||||||
import { Uploader, UploadResult } from "Upload";
|
|
||||||
|
import { Uploader, UploadResult } from ".";
|
||||||
|
|
||||||
export class Nip96Uploader implements Uploader {
|
export class Nip96Uploader implements Uploader {
|
||||||
constructor(
|
constructor(
|
||||||
readonly url: string,
|
readonly url: string,
|
||||||
readonly publisher: EventPublisher,
|
readonly publisher: EventPublisher,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
get progress() {
|
get progress() {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadInfo() {
|
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;
|
return (await rsp.json()) as Nip96Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,16 +33,20 @@ export class Nip96Uploader implements Uploader {
|
|||||||
const info = await this.loadInfo();
|
const info = await this.loadInfo();
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append("size", file.size.toString());
|
fd.append("size", file.size.toString());
|
||||||
fd.append("alt", filename);
|
fd.append("caption", filename);
|
||||||
fd.append("media_type", file.type);
|
fd.append("media_type", file.type);
|
||||||
fd.append("file", file);
|
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,
|
body: fd,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json",
|
accept: "application/json",
|
||||||
authorization: await auth(info.api_url, "POST"),
|
authorization: await auth(u, "POST"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (rsp.ok) {
|
if (rsp.ok) {
|
||||||
|
Reference in New Issue
Block a user