π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle runFFMPEGCmd in preload
Manav Rathi2522da2b5e5e
diff --git a/desktop/src/api/ffmpeg.ts b/desktop/src/api/ffmpeg.tsdeleted file mode 100644index 4b077519ad..0000000000--- a/desktop/src/api/ffmpeg.ts+++ /dev/null@@ -1,44 +0,0 @@-import { ipcRenderer } from "electron";-import { existsSync } from "fs";-import { writeStream } from "../services/fs";-import { logError } from "../main/log";-import { ElectronFile } from "../types";--export async function runFFmpegCmd(- cmd: string[],- inputFile: File | ElectronFile,- outputFileName: string,- dontTimeout?: boolean,-) {- let inputFilePath = null;- let createdTempInputFile = null;- try {- if (!existsSync(inputFile.path)) {- const tempFilePath = await ipcRenderer.invoke(- "get-temp-file-path",- inputFile.name,- );- await writeStream(tempFilePath, await inputFile.stream());- inputFilePath = tempFilePath;- createdTempInputFile = true;- } else {- inputFilePath = inputFile.path;- }- const outputFileData = await ipcRenderer.invoke(- "run-ffmpeg-cmd",- cmd,- inputFilePath,- outputFileName,- dontTimeout,- );- return new File([outputFileData], outputFileName);- } finally {- if (createdTempInputFile) {- try {- await ipcRenderer.invoke("remove-temp-file", inputFilePath);- } catch (e) {- logError(e, "failed to deleteTempFile");- }- }- }-}diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex 5173198c0d..6f56fb6209 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -8,6 +8,7 @@import { ipcMain } from "electron/main";import { clearElectronStore } from "../api/electronStore";+import { runFFmpegCmd } from "../api/ffmpeg";import { getEncryptionKey, setEncryptionKey } from "../api/safeStorage";import {appVersion,@@ -62,17 +63,24 @@ export const attachIPCHandlers = () => {ipcMain.handle("getEncryptionKey", (_) => getEncryptionKey());- ipcMain.on("update-and-restart", (_) => {- updateAndRestart();- });+ ipcMain.on("update-and-restart", (_) => updateAndRestart());- ipcMain.on("skip-app-update", (_, version) => {- skipAppUpdate(version);- });+ ipcMain.on("skip-app-update", (_, version) => skipAppUpdate(version));- ipcMain.on("mute-update-notification", (_, version) => {- muteUpdateNotification(version);- });+ ipcMain.on("mute-update-notification", (_, version) =>+ muteUpdateNotification(version),+ );++ ipcMain.handle(+ "runFFmpegCmd",+ (+ _,+ cmd: string[],+ inputFile: File | ElectronFile,+ outputFileName: string,+ dontTimeout?: boolean,+ ) => runFFmpegCmd(cmd, inputFile, outputFileName, dontTimeout),+ );ipcMain.handle("computeImageEmbedding",diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex a0f0f4308f..04e476c37d 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -31,7 +31,6 @@ import { createWriteStream, existsSync } from "node:fs";import * as fs from "node:fs/promises";import { Readable } from "node:stream";import path from "path";-import { runFFmpegCmd } from "./api/ffmpeg";import { getDirFiles } from "./api/fs";import { convertToJPEG, generateImageThumbnail } from "./api/imageProcessor";import {@@ -141,6 +140,22 @@ const muteUpdateNotification = (version: string) => {ipcRenderer.send("mute-update-notification", version);};+// - Conversion++const runFFmpegCmd = (+ cmd: string[],+ inputFile: File | ElectronFile,+ outputFileName: string,+ dontTimeout?: boolean,+): Promise<File> =>+ ipcRenderer.invoke(+ "runFFmpegCmd",+ cmd,+ inputFile,+ outputFileName,+ dontTimeout,+ );+// - MLconst computeImageEmbedding = (@@ -382,6 +397,9 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {muteUpdateNotification,registerUpdateEventListener,+ // - Conversion+ runFFmpegCmd,+// - MLcomputeImageEmbedding,computeTextEmbedding,@@ -418,7 +436,6 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {updateWatchMappingIgnoredFiles,convertToJPEG,- runFFmpegCmd,generateImageThumbnail,moveFile,deleteFolder,diff --git a/desktop/src/services/clipService.ts b/desktop/src/services/clipService.tsindex 3b46f8b517..7067e2cba6 100644--- a/desktop/src/services/clipService.ts+++ b/desktop/src/services/clipService.ts@@ -4,13 +4,13 @@ import { existsSync } from "fs";import * as fs from "node:fs/promises";import * as path from "node:path";import util from "util";-import { generateTempFilePath } from "utils/temp";import { CustomErrors } from "../constants/errors";import { isDev } from "../main/general";import { logErrorSentry } from "../main/log";import { Model } from "../types";import Tokenizer from "../utils/clip-bpe-ts/mod";import { getPlatform } from "../utils/common/platform";+import { generateTempFilePath } from "../utils/temp";import { deleteTempFile } from "./ffmpeg";import { writeStream } from "./fs";const shellescape = require("any-shell-escape");diff --git a/desktop/src/services/ffmpeg.ts b/desktop/src/services/ffmpeg.tsindex 74158e92cb..7b1564764a 100644--- a/desktop/src/services/ffmpeg.ts+++ b/desktop/src/services/ffmpeg.ts@@ -4,8 +4,11 @@ import { existsSync } from "node:fs";import * as fs from "node:fs/promises";import util from "util";import { CustomErrors } from "../constants/errors";+import { logError, logErrorSentry } from "../main/log";+import { writeStream } from "../services/fs";+import { ElectronFile } from "../types";import { generateTempFilePath, getTempDirPath } from "../utils/temp";-import { logErrorSentry } from "../main/log";+const shellescape = require("any-shell-escape");const execAsync = util.promisify(require("child_process").exec);@@ -42,6 +45,41 @@ const OUTPUT_PATH_PLACEHOLDER = "OUTPUT";* I'm not sure if our code is supposed to be able to use it, and how.*/export async function runFFmpegCmd(+ cmd: string[],+ inputFile: File | ElectronFile,+ outputFileName: string,+ dontTimeout?: boolean,+) {+ let inputFilePath = null;+ let createdTempInputFile = null;+ try {+ if (!existsSync(inputFile.path)) {+ const tempFilePath = await generateTempFilePath(inputFile.name);+ await writeStream(tempFilePath, await inputFile.stream());+ inputFilePath = tempFilePath;+ createdTempInputFile = true;+ } else {+ inputFilePath = inputFile.path;+ }+ const outputFileData = await runFFmpegCmd_(+ cmd,+ inputFilePath,+ outputFileName,+ dontTimeout,+ );+ return new File([outputFileData], outputFileName);+ } finally {+ if (createdTempInputFile) {+ try {+ await deleteTempFile(inputFilePath);+ } catch (e) {+ logError(e, "failed to deleteTempFile");+ }+ }+ }+}++export async function runFFmpegCmd_(cmd: string[],inputFilePath: string,outputFileName: string,diff --git a/desktop/src/utils/ipcComms.ts b/desktop/src/utils/ipcComms.tsindex 3c64f0e40a..a6a1adfabd 100644--- a/desktop/src/utils/ipcComms.ts+++ b/desktop/src/utils/ipcComms.ts@@ -6,7 +6,7 @@ import {computeImageEmbedding,computeTextEmbedding,} from "../services/clipService";-import { deleteTempFile, runFFmpegCmd } from "../services/ffmpeg";+import { deleteTempFile } from "../services/ffmpeg";import { getDirFilePaths } from "../services/fs";import {convertToJPEG,@@ -70,17 +70,6 @@ export default function setupIpcComs(return convertToJPEG(fileData, filename);});- ipcMain.handle(- "run-ffmpeg-cmd",- (_, cmd, inputFilePath, outputFileName, dontTimeout) => {- return runFFmpegCmd(- cmd,- inputFilePath,- outputFileName,- dontTimeout,- );- },- );ipcMain.handle("get-temp-file-path", (_, formatSuffix) => {return generateTempFilePath(formatSuffix);});diff --git a/web/packages/shared/electron/types.ts b/web/packages/shared/electron/types.tsindex b751ae40f2..d469746dab 100644--- a/web/packages/shared/electron/types.ts+++ b/web/packages/shared/electron/types.ts@@ -86,9 +86,6 @@ export interface ElectronAPIsType {setEncryptionKey: (encryptionKey: string) => Promise<void>;getEncryptionKey: () => Promise<string>;- // - FS legacy- checkExistsAndCreateDir: (dirPath: string) => Promise<void>;-// - App updateupdateAndRestart: () => void;skipAppUpdate: (version: string) => void;@@ -98,6 +95,15 @@ export interface ElectronAPIsType {showUpdateDialog: (updateInfo: AppUpdateInfo) => void,) => void;+ // - Conversion++ runFFmpegCmd: (+ cmd: string[],+ inputFile: File | ElectronFile,+ outputFileName: string,+ dontTimeout?: boolean,+ ) => Promise<File>;+// - MLcomputeImageEmbedding: (model: Model,@@ -105,6 +111,8 @@ export interface ElectronAPIsType {) => Promise<Float32Array>;computeTextEmbedding: (model: Model, text: string) => Promise<Float32Array>;+ // - FS legacy+ checkExistsAndCreateDir: (dirPath: string) => Promise<void>;/** TODO: FIXME or migrate below this */saveStreamToDisk: (@@ -156,12 +164,6 @@ export interface ElectronAPIsType {fileData: Uint8Array,filename: string,) => Promise<Uint8Array>;- runFFmpegCmd: (- cmd: string[],- inputFile: File | ElectronFile,- outputFileName: string,- dontTimeout?: boolean,- ) => Promise<File>;generateImageThumbnail: (inputFile: File | ElectronFile,