diff --git a/.changeset/ten-snakes-tap.md b/.changeset/ten-snakes-tap.md new file mode 100644 index 000000000..1e97bca55 --- /dev/null +++ b/.changeset/ten-snakes-tap.md @@ -0,0 +1,5 @@ +--- +"nostrudel": minor +--- + +Support video and audio file uploads to nostr.build diff --git a/src/components/post-modal/index.tsx b/src/components/post-modal/index.tsx index 2d27d4e2d..704673853 100644 --- a/src/components/post-modal/index.tsx +++ b/src/components/post-modal/index.tsx @@ -40,7 +40,7 @@ import { import { UserAvatarStack } from "../compact-user-stack"; import MagicTextArea, { RefType } from "../magic-textarea"; import { useContextEmojis } from "../../providers/emoji-provider"; -import { nostrBuildUploadImage } from "../../helpers/nostr-build"; +import { nostrBuildUploadImage as nostrBuildUpload } from "../../helpers/nostr-build"; import CommunitySelect from "./community-select"; import ZapSplitCreator, { fillRemainingPercent } from "./zap-split-creator"; import { EventSplit } from "../../helpers/nostr/zaps"; @@ -89,13 +89,15 @@ export default function PostModal({ const textAreaRef = useRef(null); const imageUploadRef = useRef(null); const [uploading, setUploading] = useState(false); - const uploadImage = useCallback( - async (imageFile: File) => { + const uploadFile = useCallback( + async (file: File) => { try { - if (!imageFile.type.includes("image")) throw new Error("Only images are supported"); + if (!(file.type.includes("image") || file.type.includes("video") || file.type.includes("audio"))) + throw new Error("Unsupported file type"); + setUploading(true); - const response = await nostrBuildUploadImage(imageFile, requestSignature); + const response = await nostrBuildUpload(file, requestSignature); const imageUrl = response.url; const content = getValues().content; @@ -177,7 +179,7 @@ export default function PostModal({ instanceRef={(inst) => (textAreaRef.current = inst)} onPaste={(e) => { const imageFile = Array.from(e.clipboardData.files).find((f) => f.type.includes("image")); - if (imageFile) uploadImage(imageFile); + if (imageFile) uploadFile(imageFile); }} /> {getValues().content.length > 0 && ( @@ -194,11 +196,11 @@ export default function PostModal({ { const img = e.target.files?.[0]; - if (img) uploadImage(img); + if (img) uploadFile(img); }} /> ; @@ -31,13 +31,14 @@ type NostrBuildResponse = { ]; }; -export async function nostrBuildUploadImage(image: File, sign?: (draft: DraftNostrEvent) => Promise) { - if (!image.type.includes("image")) throw new Error("Only images are supported"); +export async function nostrBuildUploadImage(file: File, sign?: (draft: DraftNostrEvent) => Promise) { + if (!(file.type.includes("image") || file.type.includes("video") || file.type.includes("audio"))) + throw new Error("Unsupported file type"); const url = "https://nostr.build/api/v2/upload/files"; const payload = new FormData(); - payload.append("fileToUpload", image); + payload.append("fileToUpload", file); const headers: HeadersInit = {}; if (sign) {