quick hacky image proxy url

This commit is contained in:
hzrd149
2023-04-18 14:54:43 -05:00
parent 444ba5febc
commit f80a9edf4f
3 changed files with 40 additions and 2 deletions

View File

@@ -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, /https?:\/\/([\dA-z\.-]+\.[A-z\.]{2,6})((?:\/[\+~%\/\.\w\-_]*)?\.(?:svg|gif|png|jpg|jpeg|webp|avif))(\??(?:[\?#\-\+=&;%@\.\w_]*)#?(?:[\-\.\!\/\\\w]*))?/i,
render: (match) => { render: (match) => {
const ImageComponent = trusted || !appSettings.value.blurImages ? Image : BlurredImage; const ImageComponent = trusted || !appSettings.value.blurImages ? Image : BlurredImage;
return <ImageComponent src={match[0]} width="100%" maxWidth="30rem" />; const src = appSettings.value.imageProxy ? `${appSettings.value.imageProxy}${match[0]}` : match[0];
return <ImageComponent src={src} width="100%" maxWidth="30rem" />;
}, },
name: "Image", name: "Image",
}); });

View File

@@ -25,6 +25,7 @@ export type AppSettings = {
lightningPayMode: LightningPayMode; lightningPayMode: LightningPayMode;
zapAmounts: number[]; zapAmounts: number[];
primaryColor: string; primaryColor: string;
imageProxy: string;
}; };
export const defaultSettings: AppSettings = { export const defaultSettings: AppSettings = {
@@ -37,6 +38,7 @@ export const defaultSettings: AppSettings = {
lightningPayMode: LightningPayMode.Prompt, lightningPayMode: LightningPayMode.Prompt,
zapAmounts: [50, 200, 500, 1000], zapAmounts: [50, 200, 500, 1000],
primaryColor: "#8DB600", primaryColor: "#8DB600",
imageProxy: "",
}; };
function parseAppSettings(event: NostrEvent): AppSettings { function parseAppSettings(event: NostrEvent): AppSettings {

View File

@@ -9,13 +9,20 @@ import {
Box, Box,
AccordionIcon, AccordionIcon,
FormHelperText, FormHelperText,
Input,
Link,
} from "@chakra-ui/react"; } from "@chakra-ui/react";
import appSettings, { replaceSettings } from "../../services/app-settings"; import appSettings, { replaceSettings } from "../../services/app-settings";
import useSubject from "../../hooks/use-subject"; import useSubject from "../../hooks/use-subject";
import useAppSettings from "../../hooks/use-app-settings"; import useAppSettings from "../../hooks/use-app-settings";
import { useEffect, useState } from "react";
export default function PerformanceSettings() { 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 ( return (
<AccordionItem> <AccordionItem>
@@ -46,6 +53,34 @@ export default function PerformanceSettings() {
<span>Side Effect: Some user pictures may not load or may be outdated</span> <span>Side Effect: Some user pictures may not load or may be outdated</span>
</FormHelperText> </FormHelperText>
</FormControl> </FormControl>
<FormControl>
<FormLabel htmlFor="image-proxy" mb="0">
Image proxy service
</FormLabel>
<Input
id="image-proxy"
type="url"
value={proxyInput}
onChange={(e) => setProxyInput(e.target.value)}
onBlur={() => {
try {
const url = proxyInput ? new URL(proxyInput).toString() : "";
if (url !== imageProxy) {
updateSettings({ imageProxy: url });
setProxyInput(url);
}
} catch (e) {}
}}
/>
<FormHelperText>
<span>
A URL to an instance of{" "}
<Link href="https://github.com/willnorris/imageproxy" isExternal target="_blank">
willnorris/imageproxy
</Link>
</span>
</FormHelperText>
</FormControl>
<FormControl> <FormControl>
<Flex alignItems="center"> <Flex alignItems="center">
<FormLabel htmlFor="auto-show-embeds" mb="0"> <FormLabel htmlFor="auto-show-embeds" mb="0">