Skip to content

armgit / ente

Public Imported from GitHub
0

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

List files alternate

Manav Rathi2051ccee46a1
diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.ts
index 2428d3a80c..ebf53487c9 100644
--- a/desktop/src/main/fs.ts
+++ b/desktop/src/main/fs.ts
@@ -27,3 +27,8 @@ export const fsIsDir = async (dirPath: string) => {
const stat = await fs.stat(dirPath);
return stat.isDirectory();
};
+
+export const fsLsFiles = async (dirPath: string) =>
+ (await fs.readdir(dirPath, { withFileTypes: true }))
+ .filter((e) => e.isFile())
+ .map((e) => e.name);
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index e307ad167d..2e01b4a106 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -20,6 +20,7 @@ import {
import {
fsExists,
fsIsDir,
+ fsLsFiles,
fsMkdirIfNeeded,
fsReadTextFile,
fsRename,
@@ -134,6 +135,8 @@ export const attachIPCHandlers = () => {
ipcMain.handle("fsIsDir", (_, dirPath: string) => fsIsDir(dirPath));
+ ipcMain.handle("fsLsFiles", (_, dirPath: string) => fsLsFiles(dirPath));
+
// - Conversion
ipcMain.handle("convertToJPEG", (_, fileData, filename) =>
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 9341f02f23..2c2677cf1f 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -121,6 +121,9 @@ const fsWriteFile = (path: string, contents: string): Promise<void> =>
const fsIsDir = (dirPath: string): Promise<boolean> =>
ipcRenderer.invoke("fsIsDir", dirPath);
+const fsLsFiles = (dirPath: string): Promise<boolean> =>
+ ipcRenderer.invoke("fsLsFiles", dirPath);
+
// - AUDIT below this
// - Conversion
@@ -322,6 +325,7 @@ contextBridge.exposeInMainWorld("electron", {
readTextFile: fsReadTextFile,
writeFile: fsWriteFile,
isDir: fsIsDir,
+ lsFiles: fsLsFiles,
},
// - Conversion
diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts
index 348f815bb9..55e7fca3fc 100644
--- a/web/packages/next/types/ipc.ts
+++ b/web/packages/next/types/ipc.ts
@@ -205,6 +205,18 @@ export interface Electron {
* directory.
*/
isDir: (dirPath: string) => Promise<boolean>;
+
+ /**
+ * Return a list of the names of the files in the given directory.
+ *
+ * Note:
+ *
+ * - This is not recursive, it will only return the names of direct
+ * children.
+ *
+ * - It will return only the names of files, not directories.
+ */
+ lsFiles: (dirPath: string) => Promise<string>;
};
/*