π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
API 1
Manav Rathicb0d25030ddf
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.tsindex 14447e7cb3..d6768069fb 100644--- a/desktop/src/main/stream.ts+++ b/desktop/src/main/stream.ts@@ -43,6 +43,16 @@ export const registerStreamProtocol = () => {// Convert e.g. "%20" to spaces.const path = decodeURIComponent(pathname);switch (host) {+ case "read":+ try {+ return net.fetch(pathToFileURL(path).toString());+ } catch (e) {+ log.error(`Failed to read stream for ${url}`, e);+ return new Response(`Failed to read stream: ${e.message}`, {+ status: 500,+ });+ }+case "write":try {await writeStream(path, request.body);@@ -55,16 +65,6 @@ export const registerStreamProtocol = () => {);}- case "read":- try {- return net.fetch(pathToFileURL(path).toString());- } catch (e) {- log.error(`Failed to read stream for ${url}`, e);- return new Response(`Failed to read stream: ${e.message}`, {- status: 500,- });- }-default:return new Response("", { status: 404 });}diff --git a/web/apps/photos/src/utils/native-stream.ts b/web/apps/photos/src/utils/native-stream.tsindex 7dba1acf9c..742c00a611 100644--- a/web/apps/photos/src/utils/native-stream.ts+++ b/web/apps/photos/src/utils/native-stream.ts@@ -4,6 +4,34 @@* NOTE: These functions only work when we're running in our desktop app.*/+/**+ * Stream the given file from the user's local filesystem.+ *+ * **This only works when we're running in our desktop app**. It uses the+ * "stream://" protocol handler exposed by our custom code in the Node.js layer.+ * See: [Note: IPC streams].+ *+ * @param path The path on the file on the user's local filesystem whose+ * contents we want to stream.+ *+ * @return A standard web {@link Response} object that contains the contents of+ * the file. In particular, `response.body` will be a {@link ReadableStream}+ * that can be used to read the files contents in a streaming, chunked, manner.+ */+export const readStream = async (path: string) => {+ const req = new Request(`stream://read${path}`, {+ method: "GET",+ });++ const res = await fetch(req);+ if (!res.ok)+ throw new Error(+ `Failed to read stream from ${path}: HTTP ${res.status}`,+ );++ return res;+};+/*** Write the given stream to a file on the local machine.*