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
refactor: remove unnecessary utils
thecodrrcf99979a54b8
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 65ec445d7..d661b163c 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -57,7 +57,6 @@"streamablefs": "file:packages/streamablefs","timeago.js": "^4.0.2","tinymce": "^5.10.2",- "uzip": "^0.20201231.0","web-streams-polyfill": "^3.1.1","wouter": "^2.7.3","zustand": "^3.3.1"diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.jsindex d0a1b5c1d..89feafe6a 100644--- a/apps/web/src/common/index.js+++ b/apps/web/src/common/index.js@@ -1,5 +1,4 @@import SelectionOptions from "./selectionoptions";-import download from "../utils/download";import {showFeatureDialog,showLoadingDialog,@@ -12,6 +11,7 @@ import { db } from "./db";import { sanitizeFilename } from "../utils/filename";import { isTesting } from "../utils/platform";import { store as userstore } from "../stores/user-store";+import FileSaver from "file-saver";export const COLORS = ["Red",@@ -115,7 +115,7 @@ export async function createBackup(save = true) {if (!save) {return { data, filename, ext };} else {- download(filename, data, ext);+ FileSaver.saveAs(data, `${filename}.${ext}`);}}diff --git a/apps/web/src/components/dialogs/exportdialog.js b/apps/web/src/components/dialogs/exportdialog.jsindex 0a85d74ac..0a81ff750 100644--- a/apps/web/src/components/dialogs/exportdialog.js+++ b/apps/web/src/components/dialogs/exportdialog.js@@ -2,9 +2,9 @@ import React, { useState } from "react";import { Flex, Button, Text } from "rebass";import * as Icon from "../icons";import Dialog from "./dialog";-import download from "../../utils/download";import { zip } from "../../utils/zip";import { db } from "../../common/db";+import FileSaver from "file-saver";const formats = [{@@ -92,10 +92,13 @@ function ExportDialog(props) {}if (!files.length) return false;if (files.length === 1) {- download(files[0].filename, files[0].content, format);+ FileSaver.saveAs(+ files[0].content,+ `${files[0].filename}.${format}`+ );} else {const zipped = await zip(files, format);- download("notes", zipped, "zip");+ FileSaver.saveAs(new Blob([zipped.buffer]), "notes.zip");}setProgress();diff --git a/apps/web/src/components/dialogs/recovery-key-dialog.js b/apps/web/src/components/dialogs/recovery-key-dialog.jsindex 74a8ca150..f7243d2f3 100644--- a/apps/web/src/components/dialogs/recovery-key-dialog.js+++ b/apps/web/src/components/dialogs/recovery-key-dialog.js@@ -3,10 +3,10 @@ import { Text, Flex, Button } from "rebass";import Dialog from "./dialog";import { db } from "../../common/db";import Logo from "../../assets/notesnook-logo.png";-import download from "../../utils/download";import * as clipboard from "clipboard-polyfill/text";import { Suspense } from "react";import Config from "../../utils/config";+import FileSaver from "file-saver";const QRCode = React.lazy(() => import("../../re-exports/react-qrcode-logo"));@@ -97,7 +97,10 @@ function RecoveryKeyDialog(props) {onClick={async () => {const qrcode = document.getElementById("react-qrcode-logo");qrcode.toBlob((blob) => {- download(`${email}-notesnook-recoverykey`, blob, "png");+ FileSaver.saveAs(+ blob,+ `${email}-notesnook-recoverykey.png`+ );});}}>@@ -108,7 +111,7 @@ function RecoveryKeyDialog(props) {mt={1}fontSize="body"onClick={() => {- download(`${email}-notesnook-recoverykey`, key, "txt");+ FileSaver.saveAs(key, `${email}-notesnook-recoverykey.txt`);}}>Download filediff --git a/apps/web/src/utils/download.js b/apps/web/src/utils/download.jsdeleted file mode 100644index 526f7faac..000000000--- a/apps/web/src/utils/download.js+++ /dev/null@@ -1,53 +0,0 @@-import { sanitizeFilename } from "./filename";--const map = {- md: "text/markdown",- html: "text/html",- txt: "text/plain",- pdf: "application/pdf",-};--export default function download(filename, text, type) {- downloadFile(text, sanitizeFilename(filename) + `.${type}`, map[type]);-}--function downloadFile(data, filename, mime, bom) {- var blobData = typeof bom !== "undefined" ? [bom, data] : [data];- var blob = new Blob(blobData, { type: mime || "application/octet-stream" });- if (data instanceof Blob) {- blob = data;- }- if (typeof window.navigator.msSaveBlob !== "undefined") {- // IE workaround for "HTML7007: One or more blob URLs were- // revoked by closing the blob for which they were created.- // These URLs will no longer resolve as the data backing- // the URL has been freed."- window.navigator.msSaveBlob(blob, filename);- } else {- var blobURL =- window.URL && window.URL.createObjectURL- ? window.URL.createObjectURL(blob)- : window.webkitURL.createObjectURL(blob);- var tempLink = document.createElement("a");- tempLink.style.display = "none";- tempLink.href = blobURL;- tempLink.setAttribute("download", filename);-- // Safari thinks _blank anchor are pop ups. We only want to set _blank- // target if the browser does not support the HTML5 download attribute.- // This allows you to download files in desktop safari if pop up blocking- // is enabled.- if (typeof tempLink.download === "undefined") {- tempLink.setAttribute("target", "_blank");- }-- document.body.appendChild(tempLink);- tempLink.click();-- // Fixes "webkit blob resource error 1"- setTimeout(function () {- document.body.removeChild(tempLink);- window.URL.revokeObjectURL(blobURL);- }, 200);- }-}diff --git a/apps/web/src/utils/observablearray.js b/apps/web/src/utils/observablearray.jsdeleted file mode 100644index 13d9cb665..000000000--- a/apps/web/src/utils/observablearray.js+++ /dev/null@@ -1,24 +0,0 @@-import EventManager from "notes-core/utils/eventmanager";--export const EventManagers = {- redo: new EventManager(),- undo: new EventManager(),-};-export default class ObservableArray extends Array {- constructor(type) {- super();- this.type = type;- }-- pop = () => {- const item = super.pop();- EventManagers[this.type].publish("pop", this.length);- return item;- };-- push = (item) => {- const n = super.push(item);- EventManagers[this.type].publish("push", this.length);- return n;- };-}diff --git a/apps/web/src/utils/validation.js b/apps/web/src/utils/validation.jsdeleted file mode 100644index cf8378367..000000000--- a/apps/web/src/utils/validation.js+++ /dev/null@@ -1,7 +0,0 @@-function isValidEmail(email) {- return /^([a-zA-Z0-9_\-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9-]+\.)+))([a-zA-Z0-9]{1,30})(\]?)$/.test(- );-}--export { isValidEmail };diff --git a/apps/web/src/utils/zip.js b/apps/web/src/utils/zip.jsindex 297bdf017..67cc0c0a0 100644--- a/apps/web/src/utils/zip.js+++ b/apps/web/src/utils/zip.js@@ -8,7 +8,7 @@ async function zip(files, format) {file.content);});- const uzip = await import("uzip");- return uzip.encode(obj);+ const { zipSync } = await import("fflate");+ return zipSync(obj);}export { zip };