From 17d37a2eafe99c39eb8cc272a67a79774aacc0a7 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Thu, 25 Jul 2024 10:18:43 +1000 Subject: [PATCH] rm matrix --- client/src/utils/FileUpload.tsx | 55 +++++++++------------------------ client/src/utils/relays.ts | 2 +- 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/client/src/utils/FileUpload.tsx b/client/src/utils/FileUpload.tsx index 58abf14..2be9544 100644 --- a/client/src/utils/FileUpload.tsx +++ b/client/src/utils/FileUpload.tsx @@ -13,16 +13,21 @@ const whitelistImageURL = ["nostr.build", "void.cat", "blossom.oxtr"]; */ export default async function FileUpload(file: File): Promise { - const buf = await file.arrayBuffer(); const sk = generateSecretKey(); + const fileBuffer = await file.arrayBuffer(); + const hashBuffer = await crypto.subtle.digest('SHA-256', fileBuffer); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + const auth = async () => { const authEvent = { - kind: 27235, + kind: 24242, + content: "Upload " + file.name + " from getwired.app", tags: [ - ["u", "https://files.v0l.io/upload"], - ["method", "POST"] + ["t", "upload"], + ["x", hashHex], + ["expiration", (Math.floor(Date.now() / 1000) + 24 * 60 * 60).toString()] ], - content: "", created_at: Math.floor(Date.now() / 1000), pubkey: getPublicKey(sk), } @@ -31,22 +36,16 @@ export default async function FileUpload(file: File): Promise { return `Nostr ${authBase64}`; }; - const req = await fetch("https://files.v0l.io/upload", { - body: buf, - method: "POST", + const req = await fetch("https://blossom.oxtr.dev/upload", { + body: file, + method: "PUT", headers: { - "Content-Type": "application/octet-stream", - "V-Content-Type": encodeURIComponent(file.type), - "V-Filename": encodeURIComponent(file.name), - "V-Description": "Upload from https://tao-green.vercel.app/", - "V-Strip-Metadata": "true", "authorization": await auth() // Use the encoded authorization header }, }); if (req.ok) { - let rsp: VoidUploadResponse = await req.json(); const fileExtension = file.name.split(".").pop(); // Extracting the file extension - const resultUrl = `https://void.cat/d/${rsp.file?.id}.${fileExtension}`; + const resultUrl = `https://blossom.oxtr.dev/${hashHex}.${fileExtension}`; return { url: resultUrl }; } return { @@ -127,29 +126,3 @@ export interface UploadResult { url?: string; error?: string; } - -export type VoidUploadResponse = { - ok: boolean; - file?: VoidFile; - errorMessage?: string; -}; - -export type VoidFile = { - id: string; - meta?: VoidFileMeta; -}; - -export type VoidFileMeta = { - version: number; - id: string; - name?: string; - size: number; - uploaded: Date; - description?: string; - mimeType?: string; - digest?: string; - url?: string; - expires?: Date; - storage?: string; - encryptionParams?: string; -}; diff --git a/client/src/utils/relays.ts b/client/src/utils/relays.ts index 9da25a7..9634a78 100644 --- a/client/src/utils/relays.ts +++ b/client/src/utils/relays.ts @@ -11,7 +11,7 @@ type Subscribe = { unsub?: boolean; }; -const blacklistUrl = ["lain.la", "casualcrypto.date", "files.catbox.moe", "m.primal.net", "i.ibb.co"]; +const blacklistUrl = ["lain.la", "casualcrypto.date", "files.catbox.moe", "i.ibb.co", "matrix"]; const subList: Array = []; const currentSubList: Array = [];