feat: nostr.build

This commit is contained in:
2023-01-23 17:36:49 +00:00
parent d2ac231f89
commit 385b4479ae
7 changed files with 108 additions and 27 deletions

View File

@ -1,11 +1,12 @@
import * as secp from "@noble/secp256k1";
import { VoidCatHost } from "Const";
import { FileExtensionRegex, VoidCatHost } from "Const";
import { UploadResult } from "./FileUpload";
/**
* Upload file to void.cat
* https://void.cat/swagger/index.html
*/
export default async function VoidUpload(file: File | Blob, filename: string) {
export default async function VoidUpload(file: File | Blob, filename: string): Promise<UploadResult> {
const buf = await file.arrayBuffer();
const digest = await crypto.subtle.digest("SHA-256", buf);
@ -25,9 +26,20 @@ export default async function VoidUpload(file: File | Blob, filename: string) {
if (req.ok) {
let rsp: VoidUploadResponse = await req.json();
return rsp;
if (rsp.ok) {
let ext = filename.match(FileExtensionRegex);
return {
url: rsp.file?.meta?.url ?? `${VoidCatHost}/d/${rsp.file?.id}${ext ? `.${ext[1]}` : ""}`
}
} else {
return {
error: rsp.errorMessage
}
}
}
return null;
return {
error: "Upload failed"
};
}
export type VoidUploadResponse = {