From 66138d5ba9fd60d38a3f4301e2e89d1f01b7862c Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 3 Oct 2023 15:31:18 +0200 Subject: [PATCH 1/8] Remove outdated comments about srcSet value We no longer distinguish between `undefined` and `null` for `srcSet`. --- components/image.js | 4 ++-- components/text.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/image.js b/components/image.js index e543da812..5b675079f 100644 --- a/components/image.js +++ b/components/image.js @@ -89,8 +89,8 @@ function ImageProxy ({ src, srcSet: srcSetObj, onClick, topLevel, onError, ...pr export function ZoomableImage ({ src, srcSet, ...props }) { const showModal = useShowModal() - // if `srcSet` is undefined, it means the image was not processed by worker yet - const [imgproxy, setImgproxy] = useState(srcSet || IMGPROXY_URL_REGEXP.test(src)) + // if `srcSet` is falsy, it means the image was not processed by worker yet + const [imgproxy, setImgproxy] = useState(!!srcSet || IMGPROXY_URL_REGEXP.test(src)) // backwards compatibility: // src may already be imgproxy url since we used to replace image urls with imgproxy urls diff --git a/components/text.js b/components/text.js index f1a01a711..6e0ce9b08 100644 --- a/components/text.js +++ b/components/text.js @@ -101,8 +101,6 @@ export default memo(function Text ({ nofollow, imgproxyUrls, children, tab, ...o const Img = useCallback(({ node, src, ...props }) => { const url = IMGPROXY_URL_REGEXP.test(src) ? decodeOriginalUrl(src) : src - // if `srcSet` is undefined, it means the image was not processed by worker yet - // if `srcSet` is null, image was processed but this specific url was not detected as an image by the worker const srcSet = imgproxyUrls?.[url] return }, [imgproxyUrls, outerProps, tab]) From 3fa890a6496ee55b1948615b90b3e88686b9ad83 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 3 Oct 2023 15:33:30 +0200 Subject: [PATCH 2/8] Fix misleading URL shown --- components/image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/image.js b/components/image.js index 5b675079f..4c806c525 100644 --- a/components/image.js +++ b/components/image.js @@ -48,7 +48,7 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr target='_blank' rel={`noreferrer ${nofollow ? 'nofollow' : ''} noopener`} href={src} - >{children || src} + >{src} ) } From 281eaa359d9db747d9f9a4b4d12136788c20d07d Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 3 Oct 2023 15:38:59 +0200 Subject: [PATCH 3/8] Update/fix comments in --- components/image.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/image.js b/components/image.js index 4c806c525..90d0334cf 100644 --- a/components/image.js +++ b/components/image.js @@ -32,7 +32,6 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr }, [src, showImage]) if (showImage && (tab === 'preview' || !me?.clickToLoadImg)) { - // image is still processing and user is okay with loading original url automatically return ( ) } else { - // image is still processing or user is not okay with loading original url automatically + // user is not okay with loading original url automatically or there was an error loading the image return ( Date: Tue, 3 Oct 2023 15:41:50 +0200 Subject: [PATCH 4/8] Simplify condition when to show image I think this is not required since `showImage` will always stay false if tab !== 'preview' or me?.clickToLoadImg are true. --- components/image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/image.js b/components/image.js index 90d0334cf..25ff766c6 100644 --- a/components/image.js +++ b/components/image.js @@ -31,7 +31,7 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr } }, [src, showImage]) - if (showImage && (tab === 'preview' || !me?.clickToLoadImg)) { + if (showImage) { return ( Date: Tue, 3 Oct 2023 15:58:50 +0200 Subject: [PATCH 5/8] Rename to imgproxyOnly --- api/typeDefs/user.js | 4 ++-- components/image.js | 2 +- fragments/users.js | 8 ++++---- pages/settings.js | 6 +++--- .../20231003134505_rename_to_imgproxy_only/migration.sql | 2 ++ prisma/schema.prisma | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 prisma/migrations/20231003134505_rename_to_imgproxy_only/migration.sql diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 26574d876..43d31c541 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -23,7 +23,7 @@ export default gql` setSettings(tipDefault: Int!, turboTipping: Boolean!, fiatCurrency: String!, noteItemSats: Boolean!, noteEarning: Boolean!, noteAllDescendants: Boolean!, noteMentions: Boolean!, noteDeposits: Boolean!, noteInvites: Boolean!, noteJobIndicator: Boolean!, noteCowboyHat: Boolean!, hideInvoiceDesc: Boolean!, - hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, clickToLoadImg: Boolean!, + hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, imgproxyOnly: Boolean!, wildWestMode: Boolean!, greeterMode: Boolean!, nostrPubkey: String, nostrRelays: [String!], hideBookmarks: Boolean!, noteForwardedSats: Boolean!, hideWalletBalance: Boolean!, hideIsContributor: Boolean!, diagnostics: Boolean!): User setPhoto(photoId: ID!): Int! @@ -89,7 +89,7 @@ export default gql` hideWelcomeBanner: Boolean! hideWalletBalance: Boolean! diagnostics: Boolean! - clickToLoadImg: Boolean! + imgproxyOnly: Boolean! wildWestMode: Boolean! greeterMode: Boolean! lastCheckedJobs: String diff --git a/components/image.js b/components/image.js index 25ff766c6..a25762df1 100644 --- a/components/image.js +++ b/components/image.js @@ -19,7 +19,7 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr const [showImage, setShowImage] = useState(false) useEffect(() => { - if (me?.clickToLoadImg && tab !== 'preview') return + if (me?.imgproxyOnly && tab !== 'preview') return // make sure it's not a false negative by trying to load URL as const img = new window.Image() img.onload = () => setShowImage(true) diff --git a/fragments/users.js b/fragments/users.js index bbf900790..0fdd5791d 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -30,7 +30,7 @@ export const ME = gql` hideInvoiceDesc hideFromTopUsers hideCowboyHat - clickToLoadImg + imgproxyOnly diagnostics wildWestMode greeterMode @@ -61,7 +61,7 @@ export const SETTINGS_FIELDS = gql` hideCowboyHat hideBookmarks hideIsContributor - clickToLoadImg + imgproxyOnly hideWalletBalance diagnostics nostrPubkey @@ -91,14 +91,14 @@ ${SETTINGS_FIELDS} mutation setSettings($tipDefault: Int!, $turboTipping: Boolean!, $fiatCurrency: String!, $noteItemSats: Boolean!, $noteEarning: Boolean!, $noteAllDescendants: Boolean!, $noteMentions: Boolean!, $noteDeposits: Boolean!, $noteInvites: Boolean!, $noteJobIndicator: Boolean!, $noteCowboyHat: Boolean!, $hideInvoiceDesc: Boolean!, - $hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $clickToLoadImg: Boolean!, + $hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $imgproxyOnly: Boolean!, $wildWestMode: Boolean!, $greeterMode: Boolean!, $nostrPubkey: String, $nostrRelays: [String!], $hideBookmarks: Boolean!, $noteForwardedSats: Boolean!, $hideWalletBalance: Boolean!, $hideIsContributor: Boolean!, $diagnostics: Boolean!) { setSettings(tipDefault: $tipDefault, turboTipping: $turboTipping, fiatCurrency: $fiatCurrency, noteItemSats: $noteItemSats, noteEarning: $noteEarning, noteAllDescendants: $noteAllDescendants, noteMentions: $noteMentions, noteDeposits: $noteDeposits, noteInvites: $noteInvites, noteJobIndicator: $noteJobIndicator, noteCowboyHat: $noteCowboyHat, hideInvoiceDesc: $hideInvoiceDesc, - hideFromTopUsers: $hideFromTopUsers, hideCowboyHat: $hideCowboyHat, clickToLoadImg: $clickToLoadImg, + hideFromTopUsers: $hideFromTopUsers, hideCowboyHat: $hideCowboyHat, imgproxyOnly: $imgproxyOnly, wildWestMode: $wildWestMode, greeterMode: $greeterMode, nostrPubkey: $nostrPubkey, nostrRelays: $nostrRelays, hideBookmarks: $hideBookmarks, noteForwardedSats: $noteForwardedSats, hideWalletBalance: $hideWalletBalance, hideIsContributor: $hideIsContributor, diagnostics: $diagnostics) { ...SettingsFields diff --git a/pages/settings.js b/pages/settings.js index 0f96bfd1e..cb0a614dc 100644 --- a/pages/settings.js +++ b/pages/settings.js @@ -75,7 +75,7 @@ export default function Settings ({ ssrData }) { hideInvoiceDesc: settings?.hideInvoiceDesc, hideFromTopUsers: settings?.hideFromTopUsers, hideCowboyHat: settings?.hideCowboyHat, - clickToLoadImg: settings?.clickToLoadImg, + imgproxyOnly: settings?.imgproxyOnly, wildWestMode: settings?.wildWestMode, greeterMode: settings?.greeterMode, nostrPubkey: settings?.nostrPubkey ? bech32encode(settings.nostrPubkey) : '', @@ -254,8 +254,8 @@ export default function Settings ({ ssrData }) { groupClassName='mb-0' />} click to load external images} - name='clickToLoadImg' + label={<>only load images from proxy} + name='imgproxyOnly' groupClassName='mb-0' /> Date: Tue, 3 Oct 2023 16:00:18 +0200 Subject: [PATCH 6/8] Add info to imgproxyOnly setting --- pages/settings.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pages/settings.js b/pages/settings.js index cb0a614dc..cbfee4e02 100644 --- a/pages/settings.js +++ b/pages/settings.js @@ -254,7 +254,17 @@ export default function Settings ({ ssrData }) { groupClassName='mb-0' />} only load images from proxy} + label={ +
only load images from proxy + +
    +
  • only load images from our image proxy automatically
  • +
  • this prevents IP address leaks to arbitrary sites
  • +
  • if we fail to load an image, the raw link will be shown
  • +
+
+
+ } name='imgproxyOnly' groupClassName='mb-0' /> From 9b204aee4089271df6f6bd93de5f894913ede773 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 3 Oct 2023 16:56:20 +0200 Subject: [PATCH 7/8] Fix text of markdown links not used on imgproxy errors --- components/image.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/image.js b/components/image.js index a25762df1..560d5c584 100644 --- a/components/image.js +++ b/components/image.js @@ -42,12 +42,16 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr ) } else { // user is not okay with loading original url automatically or there was an error loading the image + + // If element parsed by markdown is a raw URL, we use src as the text to not mislead users. + // This will not be the case if [text](url) format is used. Then we will show what was chosen as text. + const isRawURL = /^https?:\/\//.test(children?.[0]) return (
{src} + >{isRawURL ? src : children} ) } From 967651bc22a7e0a2e266d3e7f20955cc2ac460c5 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 3 Oct 2023 17:51:00 +0200 Subject: [PATCH 8/8] Fix rendering markdown links with text as images --- components/text.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/text.js b/components/text.js index 6e0ce9b08..930d4bffd 100644 --- a/components/text.js +++ b/components/text.js @@ -124,6 +124,13 @@ export default memo(function Text ({ nofollow, imgproxyUrls, children, tab, ...o return <>{children} } + // If [text](url) was parsed as and text is not empty and not a link itself, + // we don't render it as an image since it was probably a concious choice to include text. + const text = children?.[0] + if (!!text && !/^https?:\/\//.test(text)) { + return {text} + } + // assume the link is an image which will fallback to link if it's not return {children} },