mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 01:11:25 +00:00
rm matrix
This commit is contained in:
parent
cafb027e10
commit
17d37a2eaf
@ -13,16 +13,21 @@ const whitelistImageURL = ["nostr.build", "void.cat", "blossom.oxtr"];
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default async function FileUpload(file: File): Promise<UploadResult> {
|
export default async function FileUpload(file: File): Promise<UploadResult> {
|
||||||
const buf = await file.arrayBuffer();
|
|
||||||
const sk = generateSecretKey();
|
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 auth = async () => {
|
||||||
const authEvent = {
|
const authEvent = {
|
||||||
kind: 27235,
|
kind: 24242,
|
||||||
|
content: "Upload " + file.name + " from getwired.app",
|
||||||
tags: [
|
tags: [
|
||||||
["u", "https://files.v0l.io/upload"],
|
["t", "upload"],
|
||||||
["method", "POST"]
|
["x", hashHex],
|
||||||
|
["expiration", (Math.floor(Date.now() / 1000) + 24 * 60 * 60).toString()]
|
||||||
],
|
],
|
||||||
content: "",
|
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
pubkey: getPublicKey(sk),
|
pubkey: getPublicKey(sk),
|
||||||
}
|
}
|
||||||
@ -31,22 +36,16 @@ export default async function FileUpload(file: File): Promise<UploadResult> {
|
|||||||
return `Nostr ${authBase64}`;
|
return `Nostr ${authBase64}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const req = await fetch("https://files.v0l.io/upload", {
|
const req = await fetch("https://blossom.oxtr.dev/upload", {
|
||||||
body: buf,
|
body: file,
|
||||||
method: "POST",
|
method: "PUT",
|
||||||
headers: {
|
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
|
"authorization": await auth() // Use the encoded authorization header
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (req.ok) {
|
if (req.ok) {
|
||||||
let rsp: VoidUploadResponse = await req.json();
|
|
||||||
const fileExtension = file.name.split(".").pop(); // Extracting the file extension
|
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 { url: resultUrl };
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -127,29 +126,3 @@ export interface UploadResult {
|
|||||||
url?: string;
|
url?: string;
|
||||||
error?: 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;
|
|
||||||
};
|
|
||||||
|
@ -11,7 +11,7 @@ type Subscribe = {
|
|||||||
unsub?: boolean;
|
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<Subscription> = [];
|
const subList: Array<Subscription> = [];
|
||||||
const currentSubList: Array<Subscribe> = [];
|
const currentSubList: Array<Subscribe> = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user