feat: (nip96) nostrcheck.me
This commit is contained in:
parent
c9baf487ae
commit
e8bcba129e
@ -45,7 +45,7 @@ export interface UserPreferences {
|
||||
/**
|
||||
* File uploading service to upload attachments to
|
||||
*/
|
||||
fileUploader: "void.cat" | "nostr.build" | "nostrimg.com" | "void.cat-NIP96";
|
||||
fileUploader: "void.cat" | "nostr.build" | "nostrimg.com" | "void.cat-NIP96" | "nostrcheck.me";
|
||||
|
||||
/**
|
||||
* Use imgproxy to optimize images
|
||||
|
@ -474,6 +474,7 @@ const PreferencesPage = () => {
|
||||
<option value="void.cat-NIP96">void.cat (NIP-96)</option>
|
||||
<option value="nostr.build">nostr.build</option>
|
||||
<option value="nostrimg.com">nostrimg.com</option>
|
||||
<option value="nostrcheck.me">nostrcheck.me (NIP-96)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
|
@ -13,6 +13,11 @@ export class Nip96Uploader implements Uploader {
|
||||
return [];
|
||||
}
|
||||
|
||||
async loadInfo() {
|
||||
const rsp = await fetch(this.url);
|
||||
return (await rsp.json()) as Nip96Info;
|
||||
}
|
||||
|
||||
async upload(file: File | Blob, filename: string): Promise<UploadResult> {
|
||||
throwIfOffline();
|
||||
const auth = async (url: string, method: string) => {
|
||||
@ -22,18 +27,19 @@ export class Nip96Uploader implements Uploader {
|
||||
return `Nostr ${base64.encode(new TextEncoder().encode(JSON.stringify(auth)))}`;
|
||||
};
|
||||
|
||||
const info = await this.loadInfo();
|
||||
const fd = new FormData();
|
||||
fd.append("size", file.size.toString());
|
||||
fd.append("alt", filename);
|
||||
fd.append("media_type", file.type);
|
||||
fd.append("file", file);
|
||||
|
||||
const rsp = await fetch(this.url, {
|
||||
const rsp = await fetch(info.api_url, {
|
||||
body: fd,
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
authorization: await auth(this.url, "POST"),
|
||||
authorization: await auth(info.api_url, "POST"),
|
||||
},
|
||||
});
|
||||
if (rsp.ok) {
|
||||
@ -62,6 +68,11 @@ export class Nip96Uploader implements Uploader {
|
||||
}
|
||||
}
|
||||
|
||||
export interface Nip96Info {
|
||||
api_url: string;
|
||||
download_url?: string;
|
||||
}
|
||||
|
||||
export interface Nip96Result {
|
||||
status: string;
|
||||
message: string;
|
||||
|
@ -78,6 +78,9 @@ export default function useFileUpload(): Uploader {
|
||||
case "void.cat-NIP96": {
|
||||
return new Nip96Uploader("https://void.cat/nostr", unwrap(publisher));
|
||||
}
|
||||
case "nostrcheck.me": {
|
||||
return new Nip96Uploader("https://nostrcheck.me/api/v2/nip96", unwrap(publisher));
|
||||
}
|
||||
case "nostrimg.com": {
|
||||
return {
|
||||
upload: NostrImg,
|
||||
|
Loading…
x
Reference in New Issue
Block a user