diff --git a/desktop/src/main/fs.ts b/desktop/src/main/fs.ts index a870a7ab5f8a118682f9cb55c0c713266ba55092..36de710c347d845acee008565d1637f535b19eca 100644 --- a/desktop/src/main/fs.ts +++ b/desktop/src/main/fs.ts @@ -3,7 +3,6 @@ */ import { existsSync } from "node:fs"; import fs from "node:fs/promises"; -import { writeStream } from "./stream"; export const fsExists = (path: string) => existsSync(path); @@ -25,8 +24,6 @@ export const fsWriteFile = (path: string, contents: string) => /* TODO: Audit below this */ -export const saveStreamToDisk = writeStream; - export const isFolder = async (dirPath: string) => { if (!existsSync(dirPath)) return false; const stats = await fs.stat(dirPath); diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts index 2a74803020e2205d5c5c2f383a5aa0facf51f8f7..bd29057da0d490de692ff256c23efe56a80f076c 100644 --- a/desktop/src/main/ipc.ts +++ b/desktop/src/main/ipc.ts @@ -26,7 +26,6 @@ import { fsRmdir, fsWriteFile, isFolder, - saveStreamToDisk, } from "./fs"; import { logToDisk } from "./log"; import { @@ -186,12 +185,6 @@ export const attachIPCHandlers = () => { // - FS Legacy - ipcMain.handle( - "saveStreamToDisk", - (_, path: string, fileStream: ReadableStream) => - saveStreamToDisk(path, fileStream), - ); - ipcMain.handle("isFolder", (_, dirPath: string) => isFolder(dirPath)); // - Upload diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts index 5603d49a4fd0aba3916199ebac74941724a5ea99..ff2cf505af422bfd6c27cb90cf8645135f5ba957 100644 --- a/desktop/src/preload.ts +++ b/desktop/src/preload.ts @@ -237,11 +237,6 @@ const updateWatchMappingIgnoredFiles = ( // - FS Legacy -const saveStreamToDisk = ( - path: string, - fileStream: ReadableStream, -): Promise => ipcRenderer.invoke("saveStreamToDisk", path, fileStream); - const isFolder = (dirPath: string): Promise => ipcRenderer.invoke("isFolder", dirPath); @@ -357,7 +352,6 @@ contextBridge.exposeInMainWorld("electron", { // - FS legacy // TODO: Move these into fs + document + rename if needed - saveStreamToDisk, isFolder, // - Upload diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index 8f72cb4508b308df863939b0d6fd36b932b368b7..785921cc91ab9e6b00d23f2cd8ccb48a72dde78b 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -53,6 +53,7 @@ import { VISIBILITY_STATE } from "types/magicMetadata"; import { FileTypeInfo } from "types/upload"; import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata"; import { safeFileName } from "utils/native-fs"; +import { writeStream } from "utils/native-stream"; const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000; @@ -798,55 +799,47 @@ async function downloadFileDesktop( electron: Electron, fileReader: FileReader, file: EnteFile, - downloadPath: string, + downloadDir: string, ) { - const fileStream = (await DownloadManager.getFile( + const fs = electron.fs; + const stream = (await DownloadManager.getFile( file, )) as ReadableStream; - const updatedFileStream = await getUpdatedEXIFFileForDownload( + const updatedStream = await getUpdatedEXIFFileForDownload( fileReader, file, - fileStream, + stream, ); if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) { - const fileBlob = await new Response(updatedFileStream).blob(); + const fileBlob = await new Response(updatedStream).blob(); const livePhoto = await decodeLivePhoto(file, fileBlob); const imageExportName = await safeFileName( - downloadPath, + downloadDir, livePhoto.imageNameTitle, - electron.fs.exists, + fs.exists, ); const imageStream = generateStreamFromArrayBuffer(livePhoto.image); - await electron.saveStreamToDisk( - `${downloadPath}/${imageExportName}`, - imageStream, - ); + await writeStream(`${downloadDir}/${imageExportName}`, imageStream); try { const videoExportName = await safeFileName( - downloadPath, + downloadDir, livePhoto.videoNameTitle, - electron.fs.exists, + fs.exists, ); const videoStream = generateStreamFromArrayBuffer(livePhoto.video); - await electron.saveStreamToDisk( - `${downloadPath}/${videoExportName}`, - videoStream, - ); + await writeStream(`${downloadDir}/${videoExportName}`, videoStream); } catch (e) { - await electron.fs.rm(`${downloadPath}/${imageExportName}`); + await fs.rm(`${downloadDir}/${imageExportName}`); throw e; } } else { const fileExportName = await safeFileName( - downloadPath, + downloadDir, file.metadata.title, - electron.fs.exists, - ); - await electron.saveStreamToDisk( - `${downloadPath}/${fileExportName}`, - updatedFileStream, + fs.exists, ); + await writeStream(`${downloadDir}/${fileExportName}`, updatedStream); } } diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts index 60bbb39f8fafc6dd9c0d42217335c1aa7c2a233c..3477d745e49108856cd49e9a88da0babfda59363 100644 --- a/web/packages/next/types/ipc.ts +++ b/web/packages/next/types/ipc.ts @@ -311,10 +311,6 @@ export interface Electron { ) => Promise; // - FS legacy - saveStreamToDisk: ( - path: string, - fileStream: ReadableStream, - ) => Promise; isFolder: (dirPath: string) => Promise; // - Upload