From f80a9edf4f2e5e085070e3f2894a262206b61786 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Tue, 18 Apr 2023 14:54:43 -0500 Subject: [PATCH] quick hacky image proxy url --- src/components/embed-types/common.tsx | 3 +- src/services/user-app-settings.ts | 2 ++ src/views/settings/performance-settings.tsx | 37 ++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/components/embed-types/common.tsx b/src/components/embed-types/common.tsx index 7482c592f..173ebea9d 100644 --- a/src/components/embed-types/common.tsx +++ b/src/components/embed-types/common.tsx @@ -18,7 +18,8 @@ export function embedImages(content: EmbedableContent, trusted = false) { /https?:\/\/([\dA-z\.-]+\.[A-z\.]{2,6})((?:\/[\+~%\/\.\w\-_]*)?\.(?:svg|gif|png|jpg|jpeg|webp|avif))(\??(?:[\?#\-\+=&;%@\.\w_]*)#?(?:[\-\.\!\/\\\w]*))?/i, render: (match) => { const ImageComponent = trusted || !appSettings.value.blurImages ? Image : BlurredImage; - return ; + const src = appSettings.value.imageProxy ? `${appSettings.value.imageProxy}${match[0]}` : match[0]; + return ; }, name: "Image", }); diff --git a/src/services/user-app-settings.ts b/src/services/user-app-settings.ts index 688b2eac4..bd6f769b4 100644 --- a/src/services/user-app-settings.ts +++ b/src/services/user-app-settings.ts @@ -25,6 +25,7 @@ export type AppSettings = { lightningPayMode: LightningPayMode; zapAmounts: number[]; primaryColor: string; + imageProxy: string; }; export const defaultSettings: AppSettings = { @@ -37,6 +38,7 @@ export const defaultSettings: AppSettings = { lightningPayMode: LightningPayMode.Prompt, zapAmounts: [50, 200, 500, 1000], primaryColor: "#8DB600", + imageProxy: "", }; function parseAppSettings(event: NostrEvent): AppSettings { diff --git a/src/views/settings/performance-settings.tsx b/src/views/settings/performance-settings.tsx index 20c918fd7..3f6c4dd0f 100644 --- a/src/views/settings/performance-settings.tsx +++ b/src/views/settings/performance-settings.tsx @@ -9,13 +9,20 @@ import { Box, AccordionIcon, FormHelperText, + Input, + Link, } from "@chakra-ui/react"; import appSettings, { replaceSettings } from "../../services/app-settings"; import useSubject from "../../hooks/use-subject"; import useAppSettings from "../../hooks/use-app-settings"; +import { useEffect, useState } from "react"; export default function PerformanceSettings() { - const { autoShowMedia, proxyUserMedia, showReactions, showSignatureVerification, updateSettings } = useAppSettings(); + const { autoShowMedia, proxyUserMedia, showReactions, showSignatureVerification, updateSettings, imageProxy } = + useAppSettings(); + + const [proxyInput, setProxyInput] = useState(imageProxy); + useEffect(() => setProxyInput(imageProxy), [imageProxy]); return ( @@ -46,6 +53,34 @@ export default function PerformanceSettings() { Side Effect: Some user pictures may not load or may be outdated + + + Image proxy service + + setProxyInput(e.target.value)} + onBlur={() => { + try { + const url = proxyInput ? new URL(proxyInput).toString() : ""; + if (url !== imageProxy) { + updateSettings({ imageProxy: url }); + setProxyInput(url); + } + } catch (e) {} + }} + /> + + + A URL to an instance of{" "} + + willnorris/imageproxy + + + +