A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: fix various crashes
Abdullah Attadac1441add5a
diff --git a/apps/web/src/common/attachments.ts b/apps/web/src/common/attachments.tsindex b855640ea..442662d8b 100644--- a/apps/web/src/common/attachments.ts+++ b/apps/web/src/common/attachments.ts@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { lazify } from "../utils/lazify";+import { showToast } from "../utils/toast";import { db } from "./db";async function download(hash: string, groupId?: string) {@@ -67,26 +68,33 @@ export async function downloadAttachment<type: TType,groupId?: string): Promise<TOutputType | undefined> {- console.log("DOWNLOADING FILE", hash);- const response = await download(hash, groupId);- if (!response) return;- const { attachment, key } = response;-- if (type === "base64" || type === "text")- return (await db.attachments.read(hash, type)) as TOutputType;-- const blob = await lazify(import("../interfaces/fs"), ({ decryptFile }) =>- decryptFile(attachment.hash, {- key,- iv: attachment.iv,- name: attachment.filename,- type: attachment.mimeType,- isUploaded: !!attachment.dateUploaded- })- );+ try {+ const response = await download(hash, groupId);+ if (!response) return;+ const { attachment, key } = response;++ if (type === "base64" || type === "text")+ return (await db.attachments.read(hash, type)) as TOutputType;++ const blob = await lazify(import("../interfaces/fs"), ({ decryptFile }) =>+ decryptFile(attachment.hash, {+ key,+ iv: attachment.iv,+ name: attachment.filename,+ type: attachment.mimeType,+ isUploaded: !!attachment.dateUploaded+ })+ );- if (!blob) return;- return blob as TOutputType;+ if (!blob) return;+ return blob as TOutputType;+ } catch (e) {+ console.error(e);+ showToast(+ "error",+ `Failed to download attachment: ${hash} (error: ${(e as Error).message})`+ );+ }}export async function checkAttachment(hash: string) {diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 99cdc69c8..768d1298a 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -26,7 +26,7 @@ import React, {useLayoutEffect} from "react";import ReactDOM from "react-dom";-import { Box, Flex, Progress, Text } from "@theme-ui/components";+import { Box, Button, Flex, Progress, Text } from "@theme-ui/components";import Properties from "../properties";import {useEditorStore,@@ -373,6 +373,17 @@ function DownloadAttachmentProgress(props: DownloadAttachmentProgressProps) {max={100}sx={{ width: ["90%", "35%"], mt: 1 }}/>+ <Button+ variant="secondary"+ mt={2}+ onClick={() => {+ const id = useEditorStore.getState().activeSessionId;+ useEditorStore.setState({ documentPreview: undefined });+ if (id) db.fs().cancel(id).catch(console.error);+ }}+ >+ Cancel+ </Button></Flex>);}@@ -455,11 +466,7 @@ export function Editor(props: EditorProps) {const container = document.getElementById("dialogContainer");if (!(container instanceof HTMLElement)) return;- const dataurl = await downloadAttachment(- hash,- "base64",- id?.toString()- );+ const dataurl = await downloadAttachment(hash, "base64", id);if (!dataurl)return showToast("error", "This image cannot be previewed.");@@ -476,8 +483,11 @@ export function Editor(props: EditorProps) {);} else if (attachment && onPreviewDocument) {onPreviewDocument({ hash });- const blob = await downloadAttachment(hash, "blob", id?.toString());- if (!blob) return;+ const blob = await downloadAttachment(hash, "blob", id);+ if (!blob) {+ useEditorStore.setState({ documentPreview: undefined });+ return;+ }onPreviewDocument({ url: URL.createObjectURL(blob), hash });}}}diff --git a/apps/web/src/components/editor/table-of-contents.tsx b/apps/web/src/components/editor/table-of-contents.tsxindex 543ad152d..08f5026ad 100644--- a/apps/web/src/components/editor/table-of-contents.tsx+++ b/apps/web/src/components/editor/table-of-contents.tsx@@ -101,7 +101,7 @@ function TableOfContents(props: TableOfContentsProps) {position: "absolute",right: 0,top: 0,- zIndex: 1,+ zIndex: 999,height: "100%",width: "300px",borderLeft: "1px solid",diff --git a/packages/core/src/api/token-manager.ts b/packages/core/src/api/token-manager.tsindex de612bda3..67eefc2b5 100644--- a/packages/core/src/api/token-manager.ts+++ b/packages/core/src/api/token-manager.ts@@ -38,9 +38,13 @@ const ENDPOINTS = {temporaryToken: "/account/token",logout: "/account/logout"};+const REFRESH_TOKEN_MUTEX = withTimeout(+ new Mutex(),+ 10 * 1000,+ new Error("Timed out while refreshing access token.")+);class TokenManager {- mutex = withTimeout(new Mutex(), 10 * 1000);logger = logger.scope("TokenManager");constructor(private readonly storage: KVStorageAccessor) {}@@ -84,7 +88,7 @@ class TokenManager {}async _refreshToken(forceRenew = false) {- await this.mutex.runExclusive(async () => {+ await REFRESH_TOKEN_MUTEX.runExclusive(async () => {this.logger.info("Refreshing access token");const token = await this.getToken(false, false);diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.cssindex 3fbcc3be4..f39ba1938 100644--- a/packages/editor/styles/styles.css+++ b/packages/editor/styles/styles.css@@ -1,8 +1,3 @@-.ProseMirror {- contain: content;- content-visibility: auto;-}-.ProseMirror p span {font-family: inherit;}