Skip to content

armgit / ente

Public Imported from GitHub
0

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

strict

Manav Rathi612d8682b515
diff --git a/desktop/src/main/services/watch.ts b/desktop/src/main/services/watch.ts
index 4d7b89e460..e8e3803902 100644
--- a/desktop/src/main/services/watch.ts
+++ b/desktop/src/main/services/watch.ts
@@ -47,16 +47,15 @@ const eventData = (path: string): [string, FolderWatch] => {
return [path, watch];
};
-export const watchGet = (watcher: FSWatcher) => {
- const [valid, deleted] = folderWatches().reduce(
- ([valid, deleted], watch) => {
- (fsIsDir(watch.folderPath) ? valid : deleted).push(watch);
- return [valid, deleted];
- },
- [[], []],
- );
- if (deleted.length) {
- for (const watch of deleted) watchRemove(watcher, watch.folderPath);
+export const watchGet = async (watcher: FSWatcher): Promise<FolderWatch[]> => {
+ const valid: FolderWatch[] = [];
+ const deletedPaths: string[] = [];
+ for (const watch of folderWatches()) {
+ if (await fsIsDir(watch.folderPath)) valid.push(watch);
+ else deletedPaths.push(watch.folderPath);
+ }
+ if (deletedPaths.length) {
+ await Promise.all(deletedPaths.map((p) => watchRemove(watcher, p)));
setFolderWatches(valid);
}
return valid;
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.ts
index be84c022f5..26021fdf1f 100644
--- a/desktop/src/main/stream.ts
+++ b/desktop/src/main/stream.ts
@@ -8,6 +8,7 @@ import fs from "node:fs/promises";
import { Readable } from "node:stream";
import { pathToFileURL } from "node:url";
import log from "./log";
+import { ensure } from "./utils/common";
/**
* Register a protocol handler that we use for streaming large files between the
@@ -89,7 +90,7 @@ const handleRead = async (path: string) => {
return res;
} catch (e) {
log.error(`Failed to read stream at ${path}`, e);
- return new Response(`Failed to read stream: ${e.message}`, {
+ return new Response(`Failed to read stream: ${String(e)}`, {
status: 500,
});
}
@@ -133,11 +134,11 @@ const handleReadZip = async (zipPath: string, entryName: string) => {
const handleWrite = async (path: string, request: Request) => {
try {
- await writeStream(path, request.body);
+ await writeStream(path, ensure(request.body));
return new Response("", { status: 200 });
} catch (e) {
log.error(`Failed to write stream to ${path}`, e);
- return new Response(`Failed to write stream: ${e.message}`, {
+ return new Response(`Failed to write stream: ${String(e)}`, {
status: 500,
});
}