feat: nostrimg.com
This commit is contained in:
parent
14769f8f33
commit
6652c92064
@ -10,7 +10,7 @@ import { openFile } from "Util";
|
||||
import Textarea from "Element/Textarea";
|
||||
import Modal from "Element/Modal";
|
||||
import { default as NEvent } from "Nostr/Event";
|
||||
import useFileUpload from "Feed/FileUpload";
|
||||
import useFileUpload from "Upload";
|
||||
|
||||
export interface NoteCreatorProps {
|
||||
show: boolean
|
||||
|
@ -105,6 +105,7 @@ const PreferencesPage = () => {
|
||||
<select value={perf.fileUploader} onChange={e => dispatch(setPreferences({ ...perf, fileUploader: e.target.value } as UserPreferences))}>
|
||||
<option value="void.cat">void.cat (Default)</option>
|
||||
<option value="nostr.build">nostr.build</option>
|
||||
<option value="nostrimg.com">nostrimg.com</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -14,7 +14,7 @@ import { hexToBech32, openFile } from "Util";
|
||||
import Copy from "Element/Copy";
|
||||
import { RootState } from "State/Store";
|
||||
import { HexKey } from "Nostr";
|
||||
import useFileUpload from "Feed/FileUpload";
|
||||
import useFileUpload from "Upload";
|
||||
|
||||
export default function ProfileSettings() {
|
||||
const navigate = useNavigate();
|
||||
|
@ -54,7 +54,7 @@ export interface UserPreferences {
|
||||
/**
|
||||
* File uploading service to upload attachments to
|
||||
*/
|
||||
fileUploader: "void.cat" | "nostr.build",
|
||||
fileUploader: "void.cat" | "nostr.build" | "nostrimg.com",
|
||||
|
||||
/**
|
||||
* Use imgproxy to optimize images
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { UploadResult } from "./FileUpload";
|
||||
import { UploadResult } from "Upload";
|
||||
|
||||
export default async function NostrBuildUpload(file: File | Blob): Promise<UploadResult> {
|
||||
export default async function NostrBuild(file: File | Blob): Promise<UploadResult> {
|
||||
let fd = new FormData();
|
||||
fd.append("fileToUpload", file);
|
||||
fd.append("submit", "Upload Image");
|
41
src/Upload/NostrImg.ts
Normal file
41
src/Upload/NostrImg.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { UploadResult } from "Upload";
|
||||
|
||||
export default async function NostrImg(file: File | Blob): Promise<UploadResult> {
|
||||
let fd = new FormData();
|
||||
fd.append("image", file);
|
||||
|
||||
let rsp = await fetch("https://nostrimg.com/api/upload", {
|
||||
body: fd,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"accept": "application/json"
|
||||
}
|
||||
});
|
||||
if (rsp.ok) {
|
||||
let data: UploadResponse = await rsp.json();
|
||||
if (typeof data?.imageUrl === "string" && data.success) {
|
||||
return {
|
||||
url: new URL(data.imageUrl).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
error: "Upload failed"
|
||||
}
|
||||
}
|
||||
|
||||
interface UploadResponse {
|
||||
fileID?: string,
|
||||
fileName?: string,
|
||||
imageUrl?: string,
|
||||
lightningDestination?: string,
|
||||
lightningPaymentLink?: string,
|
||||
message?: string,
|
||||
route?: string,
|
||||
status: number,
|
||||
success: boolean,
|
||||
url?: string,
|
||||
data?: {
|
||||
url?: string
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
import * as secp from "@noble/secp256k1";
|
||||
import { FileExtensionRegex, VoidCatHost } from "Const";
|
||||
import { UploadResult } from "./FileUpload";
|
||||
import { UploadResult } from "Upload";
|
||||
|
||||
/**
|
||||
* Upload file to void.cat
|
||||
* https://void.cat/swagger/index.html
|
||||
*/
|
||||
export default async function VoidUpload(file: File | Blob, filename: string): Promise<UploadResult> {
|
||||
export default async function VoidCat(file: File | Blob, filename: string): Promise<UploadResult> {
|
||||
const buf = await file.arrayBuffer();
|
||||
const digest = await crypto.subtle.digest("SHA-256", buf);
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "State/Store";
|
||||
import NostrBuildUpload from "./NostrBuildUpload";
|
||||
import VoidUpload from "./VoidUpload";
|
||||
import NostrBuild from "Upload/NostrBuild";
|
||||
import VoidCat from "Upload/VoidCat";
|
||||
import NostrImg from "./NostrImg";
|
||||
|
||||
export interface UploadResult {
|
||||
url?: string,
|
||||
@ -18,12 +19,17 @@ export default function useFileUpload(): Uploader {
|
||||
switch (fileUploader) {
|
||||
case "nostr.build": {
|
||||
return {
|
||||
upload: NostrBuildUpload
|
||||
upload: NostrBuild
|
||||
} as Uploader;
|
||||
}
|
||||
case "nostrimg.com": {
|
||||
return {
|
||||
upload: NostrImg
|
||||
} as Uploader;
|
||||
}
|
||||
default: {
|
||||
return {
|
||||
upload: VoidUpload
|
||||
upload: VoidCat
|
||||
} as Uploader;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user