From 2ce30b71c7e418abdb471863096eab47387cd41e Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 9 Jan 2023 12:47:18 +0500 Subject: [PATCH] web: add setting to specify custom CORS proxy --- apps/web/src/components/editor/index.tsx | 4 +++ apps/web/src/components/editor/tiptap.tsx | 8 ++++-- apps/web/src/views/settings.js | 35 ++++++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx index 10e82d70b..ac634cb64 100644 --- a/apps/web/src/components/editor/index.tsx +++ b/apps/web/src/components/editor/index.tsx @@ -43,6 +43,7 @@ import { db } from "../../common/db"; import useMobile from "../../hooks/use-mobile"; import Titlebox from "./title-box"; import useTablet from "../../hooks/use-tablet"; +import Config from "../../utils/config"; type PreviewSession = { content: { data: string; type: string }; @@ -287,6 +288,9 @@ export function Editor(props: EditorProps) { readonly={readonly} toolbarContainerId={headless ? undefined : "editorToolbar"} content={content} + downloadOptions={{ + corsHost: Config.get("corsProxy", "https://cors.notesnook.com") + }} onLoad={() => { if (onLoadMedia) onLoadMedia(); }} diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsx index d52f9e95e..cc7a513f0 100644 --- a/apps/web/src/components/editor/tiptap.tsx +++ b/apps/web/src/components/editor/tiptap.tsx @@ -32,7 +32,8 @@ import { AttachmentType, usePermissionHandler, getHTMLFromFragment, - Fragment + Fragment, + type DownloadOptions } from "@notesnook/editor"; import { Box, Flex } from "@theme-ui/components"; import { PropsWithChildren, useEffect, useRef, useState } from "react"; @@ -67,6 +68,7 @@ type TipTapProps = { nonce?: number; theme: Theme; isMobile?: boolean; + downloadOptions?: DownloadOptions; }; const SAVE_INTERVAL = process.env.REACT_APP_TEST ? 100 : 300; @@ -110,7 +112,8 @@ function TipTap(props: TipTapProps) { readonly, nonce, theme, - isMobile + isMobile, + downloadOptions } = props; const isUserPremium = useIsUserPremium(); @@ -144,6 +147,7 @@ function TipTap(props: TipTapProps) { } } }, + downloadOptions, doubleSpacedLines, isKeyboardOpen: true, isMobile: isMobile || false, diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js index c5131408d..b30283fcc 100644 --- a/apps/web/src/views/settings.js +++ b/apps/web/src/views/settings.js @@ -40,7 +40,8 @@ import { showMultifactorDialog, showAttachmentsDialog, show2FARecoveryCodesDialog, - showToolbarConfigDialog + showToolbarConfigDialog, + showPromptDialog } from "../common/dialog-controller"; import { SUBSCRIPTION_STATUS } from "../common/constants"; import { createBackup, importBackup, verifyAccount } from "../common"; @@ -182,6 +183,10 @@ function Settings() { ); const [showReminderNotifications, setShowReminderNotifications] = usePersistentState("reminderNotifications", true); + const [corsProxy, setCorsProxy] = usePersistentState( + "corsProxy", + "https://cors.notesnook.com" + ); useEffect(() => { (async () => { @@ -756,6 +761,34 @@ function Settings() { /> )} +