Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: refactor

Ammar Ahmed50b7f9eb685d
diff --git a/apps/mobile/app/common/filesystem/utils.ts b/apps/mobile/app/common/filesystem/utils.ts
index 6575587cb..04db1a456 100644
--- a/apps/mobile/app/common/filesystem/utils.ts
+++ b/apps/mobile/app/common/filesystem/utils.ts
@@ -161,10 +161,10 @@ export async function checkUpload(
size === 0
? `File size is 0.`
: size === -1
- ? `File verification check failed.`
- : expectedSize !== decryptedLength
- ? `File size mismatch. Expected ${size} bytes but got ${decryptedLength} bytes.`
- : undefined;
+ ? `File verification check failed.`
+ : expectedSize !== decryptedLength
+ ? `File size mismatch. Expected ${size} bytes but got ${decryptedLength} bytes.`
+ : undefined;
if (error) throw new Error(error);
}
@@ -189,3 +189,7 @@ export async function checkAndCreateDir(path: string) {
}
return dir;
}
+
+export const santizeUri = (uri: string) => {
+ return Platform.OS === "ios" ? decodeURI(uri).replace("file:///", "/") : uri;
+};
diff --git a/apps/mobile/app/screens/editor/tiptap/picker.ts b/apps/mobile/app/screens/editor/tiptap/picker.ts
index 5767f4a8c..648c9d76e 100644
--- a/apps/mobile/app/screens/editor/tiptap/picker.ts
+++ b/apps/mobile/app/screens/editor/tiptap/picker.ts
@@ -41,12 +41,7 @@ import { useSettingStore } from "../../../stores/use-setting-store";
import { useUserStore } from "../../../stores/use-user-store";
import { useTabStore } from "./use-tab-store";
import { editorController, editorState } from "./utils";
-
-const santizeUri = (uri: string) => {
- uri = decodeURI(uri);
- uri = Platform.OS === "ios" ? uri.replace("file:///", "/") : uri;
- return uri;
-};
+import { santizeUri } from "../../../common/filesystem/utils";
type PickerOptions = {
noteId?: string;
@@ -107,8 +102,7 @@ const file = async (fileOptions: PickerOptions) => {
return;
}
- let uri = fileCopyUri.localUri;
- uri = Platform.OS === "ios" ? santizeUri(uri) : uri;
+ let uri = santizeUri(fileCopyUri.localUri);
const hash = await Sodium.hashFile({
uri: uri,
type: "url"
diff --git a/apps/mobile/app/screens/settings/theme-selector.tsx b/apps/mobile/app/screens/settings/theme-selector.tsx
index 2aed75334..a6e2a3076 100644
--- a/apps/mobile/app/screens/settings/theme-selector.tsx
+++ b/apps/mobile/app/screens/settings/theme-selector.tsx
@@ -16,6 +16,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { LegendList } from "@legendapp/list";
+import { strings } from "@notesnook/intl";
import {
THEME_COMPATIBILITY_VERSION,
ThemeDefinition,
@@ -29,7 +31,6 @@ import type {
ThemesRouter
} from "@notesnook/themes-server";
import { keepLocalCopy, pick } from "@react-native-documents/picker";
-import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import { createTRPCReact } from "@trpc/react-query";
@@ -40,24 +41,24 @@ import {
TouchableOpacity,
View
} from "react-native";
+import ReactNativeBlobUtil from "react-native-blob-util";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { DatabaseLogger, db } from "../../common/database";
+import { santizeUri } from "../../common/filesystem/utils";
import SheetProvider from "../../components/sheet-provider";
import { Button } from "../../components/ui/button";
+import { IconButton } from "../../components/ui/icon-button";
import Input from "../../components/ui/input";
+import { Pressable } from "../../components/ui/pressable";
import Heading from "../../components/ui/typography/heading";
import Paragraph from "../../components/ui/typography/paragraph";
import { ToastManager, presentSheet } from "../../services/event-manager";
import { useThemeStore } from "../../stores/use-theme-store";
-import { defaultBorderRadius, AppFontSize } from "../../utils/size";
+import { getColorLinearShade } from "../../utils/colors";
import { getElevationStyle } from "../../utils/elevation";
import { MenuItemsList } from "../../utils/menu-items";
-import { IconButton } from "../../components/ui/icon-button";
-import { Pressable } from "../../components/ui/pressable";
-import { getColorLinearShade } from "../../utils/colors";
-import { strings } from "@notesnook/intl";
+import { AppFontSize, defaultBorderRadius } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
-import { LegendList } from "@legendapp/list";
-import ReactNativeBlobUtil from "react-native-blob-util";
const THEME_SERVER_URL = "https://themes-api.notesnook.com";
//@ts-ignore
@@ -429,12 +430,16 @@ function ThemeSelector() {
});
if (copiedFile[0].status !== "success") return;
+ const themeJsonCopiedPath = santizeUri(
+ copiedFile[0].localUri
+ );
+
const themeJson = await ReactNativeBlobUtil.fs.readFile(
- copiedFile[0].localUri,
+ themeJsonCopiedPath,
"utf8"
);
ReactNativeBlobUtil.fs
- .unlink(copiedFile[0].localUri)
+ .unlink(themeJsonCopiedPath)
.catch(() => {});
const json = JSON.parse(themeJson);
const result = validateTheme(json);