Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

POSIX paths

Manav Rathi0c4da8c86aea
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 589b17fab2..407e541ff7 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -217,7 +217,25 @@ const watchReset = async () => {
// - Upload
-const pathForFile = (file: File) => webUtils.getPathForFile(file);
+const pathForFile = (file: File) => {
+ const path = webUtils.getPathForFile(file);
+ // The path that we get back from `webUtils.getPathForFile` on Windows uses
+ // "/" as the path separator. Convert them to POSIX separators.
+ //
+ // Note that we do not have access to the path or the os module in the
+ // preload script, thus this hand rolled transformation.
+
+ // However that makes TypeScript fidgety since we it cannot find navigator,
+ // as we haven't included "lib": ["dom"] in our tsconfig to avoid making DOM
+ // APIs available to our main Node.js code. We could create a separate
+ // tsconfig just for the preload script, but for now let's go with a cast.
+ //
+ // @ts-expect-error navigator is not defined.
+ const platform = (navigator as { platform: string }).platform;
+ return platform.toLowerCase().includes("win")
+ ? path.split("\\").join("/")
+ : path;
+};
const listZipItems = (zipPath: string) =>
ipcRenderer.invoke("listZipItems", zipPath);