Skip to content

armgit / ente

Public Imported from GitHub
0

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

Inline

Manav Rathid98c3686c582
diff --git a/desktop/src/services/ffmpeg.ts b/desktop/src/services/ffmpeg.ts
index 0a19272323..a79b5c4e11 100644
--- a/desktop/src/services/ffmpeg.ts
+++ b/desktop/src/services/ffmpeg.ts
@@ -3,15 +3,13 @@ import pathToFfmpeg from "ffmpeg-static";
import { existsSync } from "fs";
import { readFile, rmSync, writeFile } from "promise-fs";
import util from "util";
-import { promiseWithTimeout } from "../utils/common";
+import { CustomErrors } from "../constants/errors";
import { generateTempFilePath, getTempDirPath } from "../utils/temp";
import { logErrorSentry } from "./sentry";
const shellescape = require("any-shell-escape");
const execAsync = util.promisify(require("child_process").exec);
-const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000;
-
const INPUT_PATH_PLACEHOLDER = "INPUT";
const FFMPEG_PLACEHOLDER = "FFMPEG";
const OUTPUT_PATH_PLACEHOLDER = "OUTPUT";
@@ -70,10 +68,7 @@ export async function runFFmpegCmd(
if (dontTimeout) {
await execAsync(escapedCmd);
} else {
- await promiseWithTimeout(
- execAsync(escapedCmd),
- FFMPEG_EXECUTION_WAIT_TIME,
- );
+ await promiseWithTimeout(execAsync(escapedCmd), 30 * 1000);
}
if (!existsSync(tempOutputFilePath)) {
throw new Error("ffmpeg output file not found");
@@ -128,3 +123,27 @@ export async function deleteTempFile(tempFilePath: string) {
}
rmSync(tempFilePath, { force: true });
}
+
+export const promiseWithTimeout = async <T>(
+ request: Promise<T>,
+ timeout: number,
+): Promise<T> => {
+ const timeoutRef: {
+ current: NodeJS.Timeout;
+ } = { current: null };
+ const rejectOnTimeout = new Promise<null>((_, reject) => {
+ timeoutRef.current = setTimeout(
+ () => reject(Error(CustomErrors.WAIT_TIME_EXCEEDED)),
+ timeout,
+ );
+ });
+ const requestWithTimeOutCancellation = async () => {
+ const resp = await request;
+ clearTimeout(timeoutRef.current);
+ return resp;
+ };
+ return await Promise.race([
+ requestWithTimeOutCancellation(),
+ rejectOnTimeout,
+ ]);
+};
diff --git a/desktop/src/utils/common/index.ts b/desktop/src/utils/common/index.ts
index e970dfec41..592e7c3738 100644
--- a/desktop/src/utils/common/index.ts
+++ b/desktop/src/utils/common/index.ts
@@ -1,27 +1,2 @@
import { app } from "electron";
-import { CustomErrors } from "../../constants/errors";
export const isDev = !app.isPackaged;
-
-export const promiseWithTimeout = async <T>(
- request: Promise<T>,
- timeout: number,
-): Promise<T> => {
- const timeoutRef: {
- current: NodeJS.Timeout;
- } = { current: null };
- const rejectOnTimeout = new Promise<null>((_, reject) => {
- timeoutRef.current = setTimeout(
- () => reject(Error(CustomErrors.WAIT_TIME_EXCEEDED)),
- timeout,
- );
- });
- const requestWithTimeOutCancellation = async () => {
- const resp = await request;
- clearTimeout(timeoutRef.current);
- return resp;
- };
- return await Promise.race([
- requestWithTimeOutCancellation(),
- rejectOnTimeout,
- ]);
-};