feat: request metadata stripping from void.cat

This commit is contained in:
Kieran 2023-01-26 13:55:30 +00:00
parent e067d1b75e
commit 39fbe3b10f
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 14 additions and 6 deletions

View File

@ -5,6 +5,11 @@ import { RelaySettings } from "Nostr/Connection";
*/
export const ApiHost = "https://api.snort.social";
/**
* Void.cat file upload service url
*/
export const VoidCatHost = "https://void.cat";
/**
* Websocket re-connect timeout
*/

View File

@ -7,7 +7,7 @@ import "./NoteCreator.css";
import useEventPublisher from "Feed/EventPublisher";
import { openFile } from "Util";
import VoidUpload from "Feed/VoidUpload";
import { FileExtensionRegex } from "Const";
import { FileExtensionRegex, VoidCatHost } from "Const";
import Textarea from "Element/Textarea";
import Event, { default as NEvent } from "Nostr/Event";
@ -46,7 +46,7 @@ export function NoteCreator(props: NoteCreatorProps) {
let ext = file.name.match(FileExtensionRegex);
// extension tricks note parser to embed the content
let url = rx.file.meta?.url ?? `https://void.cat/d/${rx.file.id}${ext ? `.${ext[1]}` : ""}`;
let url = rx.file.meta?.url ?? `${VoidCatHost}/d/${rx.file.id}${ext ? `.${ext[1]}` : ""}`;
setNote(n => `${n}\n${url}`);
} else if (rx?.errorMessage) {

View File

@ -1,4 +1,5 @@
import * as secp from "@noble/secp256k1";
import { VoidCatHost } from "Const";
/**
* Upload file to void.cat
@ -8,7 +9,7 @@ export default async function VoidUpload(file: File | Blob, filename: string) {
const buf = await file.arrayBuffer();
const digest = await crypto.subtle.digest("SHA-256", buf);
let req = await fetch(`https://void.cat/upload`, {
let req = await fetch(`${VoidCatHost}/upload`, {
mode: "cors",
method: "POST",
body: buf,
@ -17,7 +18,8 @@ export default async function VoidUpload(file: File | Blob, filename: string) {
"V-Content-Type": file.type,
"V-Filename": filename,
"V-Full-Digest": secp.utils.bytesToHex(new Uint8Array(digest)),
"V-Description": "Upload from https://snort.social"
"V-Description": "Upload from https://snort.social",
"V-Strip-Metadata": "true"
}
});

View File

@ -15,6 +15,7 @@ import { hexToBech32, openFile } from "Util";
import Copy from "Element/Copy";
import { RootState } from "State/Store";
import { HexKey } from "Nostr";
import { VoidCatHost } from "Const";
export default function ProfileSettings() {
const navigate = useNavigate();
@ -86,14 +87,14 @@ export default function ProfileSettings() {
async function setNewAvatar() {
const rsp = await uploadFile();
if (rsp) {
setPicture(rsp.meta?.url ?? `https://void.cat/d/${rsp.id}`);
setPicture(rsp.meta?.url ?? `${VoidCatHost}d/${rsp.id}`);
}
}
async function setNewBanner() {
const rsp = await uploadFile();
if (rsp) {
setBanner(rsp.meta?.url ?? `https://void.cat/d/${rsp.id}`);
setBanner(rsp.meta?.url ?? `${VoidCatHost}/d/${rsp.id}`);
}
}