π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Let fs.readFile throw on non-existent files
Manav Rathi1830a1b931c5
diff --git a/desktop/src/services/imageProcessor.ts b/desktop/src/services/imageProcessor.tsindex cb6c7416d6..299bf64d33 100644--- a/desktop/src/services/imageProcessor.ts+++ b/desktop/src/services/imageProcessor.ts@@ -2,9 +2,8 @@ import { exec } from "child_process";import util from "util";import log from "electron-log";-import { existsSync, rmSync } from "fs";+import * as fs from "node:fs/promises";import path from "path";-import { readFile, writeFile } from "promise-fs";import { CustomErrors } from "../constants/errors";import { isDev } from "../utils/common";import { isPlatform } from "../utils/common/platform";@@ -88,28 +87,22 @@ export async function convertToJPEG(tempInputFilePath = await generateTempFilePath(filename);tempOutputFilePath = await generateTempFilePath("output.jpeg");- await writeFile(tempInputFilePath, fileData);+ await fs.writeFile(tempInputFilePath, fileData);await runConvertCommand(tempInputFilePath, tempOutputFilePath);- if (!existsSync(tempOutputFilePath)) {- throw new Error("heic convert output file not found");- }- const convertedFileData = new Uint8Array(- await readFile(tempOutputFilePath),- );- return convertedFileData;+ return new Uint8Array(await fs.readFile(tempOutputFilePath));} catch (e) {logErrorSentry(e, "failed to convert heic");throw e;} finally {try {- rmSync(tempInputFilePath, { force: true });+ await fs.rm(tempInputFilePath, { force: true });} catch (e) {logErrorSentry(e, "failed to remove tempInputFile");}try {- rmSync(tempOutputFilePath, { force: true });+ await fs.rm(tempOutputFilePath, { force: true });} catch (e) {logErrorSentry(e, "failed to remove tempOutputFile");}@@ -183,10 +176,7 @@ export async function generateImageThumbnail(quality,);- if (!existsSync(tempOutputFilePath)) {- throw new Error("output thumbnail file not found");- }- thumbnail = new Uint8Array(await readFile(tempOutputFilePath));+ thumbnail = new Uint8Array(await fs.readFile(tempOutputFilePath));quality -= 10;} while (thumbnail.length > maxSize && quality > MIN_QUALITY);return thumbnail;@@ -195,7 +185,7 @@ export async function generateImageThumbnail(throw e;} finally {try {- rmSync(tempOutputFilePath, { force: true });+ await fs.rm(tempOutputFilePath, { force: true });} catch (e) {logErrorSentry(e, "failed to remove tempOutputFile");}diff --git a/desktop/src/utils/main.ts b/desktop/src/utils/main.tsindex 569752326e..9041a6d158 100644--- a/desktop/src/utils/main.ts+++ b/desktop/src/utils/main.ts@@ -1,8 +1,8 @@import { app, BrowserWindow, Menu, nativeImage, Tray } from "electron";import ElectronLog from "electron-log";+import { existsSync } from "node:fs";import os from "os";import path from "path";-import { existsSync } from "promise-fs";import util from "util";import { rendererURL } from "../main";import { setupAutoUpdater } from "../services/appUpdater";