Manav Rathi hace 1 año
padre
commit
86929c5d2d

+ 5 - 5
desktop/src/main/services/convert.ts

@@ -4,8 +4,8 @@ import path from "path";
 import { CustomErrorMessage, ElectronFile } from "../../types/ipc";
 import { CustomErrorMessage, ElectronFile } from "../../types/ipc";
 import log from "../log";
 import log from "../log";
 import { writeStream } from "../stream";
 import { writeStream } from "../stream";
-import { deleteTempFile, generateTempFilePath } from "../temp";
 import { execAsync, isDev } from "../utils-electron";
 import { execAsync, isDev } from "../utils-electron";
+import { deleteTempFile, makeTempFilePath } from "../utils-temp";
 
 
 const IMAGE_MAGICK_PLACEHOLDER = "IMAGE_MAGICK";
 const IMAGE_MAGICK_PLACEHOLDER = "IMAGE_MAGICK";
 const MAX_DIMENSION_PLACEHOLDER = "MAX_DIMENSION";
 const MAX_DIMENSION_PLACEHOLDER = "MAX_DIMENSION";
@@ -78,8 +78,8 @@ export const convertToJPEG = async (
     let tempInputFilePath: string;
     let tempInputFilePath: string;
     let tempOutputFilePath: string;
     let tempOutputFilePath: string;
     try {
     try {
-        tempInputFilePath = await generateTempFilePath(fileName);
-        tempOutputFilePath = await generateTempFilePath("output.jpeg");
+        tempInputFilePath = await makeTempFilePath(fileName);
+        tempOutputFilePath = await makeTempFilePath("output.jpeg");
 
 
         await fs.writeFile(tempInputFilePath, imageData);
         await fs.writeFile(tempInputFilePath, imageData);
 
 
@@ -157,7 +157,7 @@ export async function generateImageThumbnail(
                 CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED,
                 CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED,
             );
             );
         if (!existsSync(inputFile.path)) {
         if (!existsSync(inputFile.path)) {
-            const tempFilePath = await generateTempFilePath(inputFile.name);
+            const tempFilePath = await makeTempFilePath(inputFile.name);
             await writeStream(tempFilePath, await inputFile.stream());
             await writeStream(tempFilePath, await inputFile.stream());
             inputFilePath = tempFilePath;
             inputFilePath = tempFilePath;
             createdTempInputFile = true;
             createdTempInputFile = true;
@@ -189,7 +189,7 @@ async function generateImageThumbnail_(
     let tempOutputFilePath: string;
     let tempOutputFilePath: string;
     let quality = MAX_QUALITY;
     let quality = MAX_QUALITY;
     try {
     try {
-        tempOutputFilePath = await generateTempFilePath("thumb.jpeg");
+        tempOutputFilePath = await makeTempFilePath("thumb.jpeg");
         let thumbnail: Uint8Array;
         let thumbnail: Uint8Array;
         do {
         do {
             await execAsync(
             await execAsync(

+ 3 - 3
desktop/src/main/services/ffmpeg.ts

@@ -6,7 +6,7 @@ import log from "../log";
 import { writeStream } from "../stream";
 import { writeStream } from "../stream";
 import { withTimeout } from "../utils";
 import { withTimeout } from "../utils";
 import { execAsync } from "../utils-electron";
 import { execAsync } from "../utils-electron";
-import { deleteTempFile, generateTempFilePath } from "../utils-temp";
+import { deleteTempFile, makeTempFilePath } from "../utils-temp";
 
 
 const INPUT_PATH_PLACEHOLDER = "INPUT";
 const INPUT_PATH_PLACEHOLDER = "INPUT";
 const FFMPEG_PLACEHOLDER = "FFMPEG";
 const FFMPEG_PLACEHOLDER = "FFMPEG";
@@ -49,7 +49,7 @@ export async function runFFmpegCmd(
     let createdTempInputFile = null;
     let createdTempInputFile = null;
     try {
     try {
         if (!existsSync(inputFile.path)) {
         if (!existsSync(inputFile.path)) {
-            const tempFilePath = await generateTempFilePath(inputFile.name);
+            const tempFilePath = await makeTempFilePath(inputFile.name);
             await writeStream(tempFilePath, await inputFile.stream());
             await writeStream(tempFilePath, await inputFile.stream());
             inputFilePath = tempFilePath;
             inputFilePath = tempFilePath;
             createdTempInputFile = true;
             createdTempInputFile = true;
@@ -78,7 +78,7 @@ export async function runFFmpegCmd_(
 ) {
 ) {
     let tempOutputFilePath: string;
     let tempOutputFilePath: string;
     try {
     try {
-        tempOutputFilePath = await generateTempFilePath(outputFileName);
+        tempOutputFilePath = await makeTempFilePath(outputFileName);
 
 
         cmd = cmd.map((cmdPart) => {
         cmd = cmd.map((cmdPart) => {
             if (cmdPart === FFMPEG_PLACEHOLDER) {
             if (cmdPart === FFMPEG_PLACEHOLDER) {

+ 2 - 2
desktop/src/main/services/ml-clip.ts

@@ -11,7 +11,7 @@ import * as ort from "onnxruntime-node";
 import Tokenizer from "../../thirdparty/clip-bpe-ts/mod";
 import Tokenizer from "../../thirdparty/clip-bpe-ts/mod";
 import log from "../log";
 import log from "../log";
 import { writeStream } from "../stream";
 import { writeStream } from "../stream";
-import { deleteTempFile, generateTempFilePath } from "../utils-temp";
+import { deleteTempFile, makeTempFilePath } from "../utils-temp";
 import { makeCachedInferenceSession } from "./ml";
 import { makeCachedInferenceSession } from "./ml";
 
 
 const cachedCLIPImageSession = makeCachedInferenceSession(
 const cachedCLIPImageSession = makeCachedInferenceSession(
@@ -20,7 +20,7 @@ const cachedCLIPImageSession = makeCachedInferenceSession(
 );
 );
 
 
 export const clipImageEmbedding = async (jpegImageData: Uint8Array) => {
 export const clipImageEmbedding = async (jpegImageData: Uint8Array) => {
-    const tempFilePath = await generateTempFilePath("");
+    const tempFilePath = await makeTempFilePath("");
     const imageStream = new Response(jpegImageData.buffer).body;
     const imageStream = new Response(jpegImageData.buffer).body;
     await writeStream(tempFilePath, imageStream);
     await writeStream(tempFilePath, imageStream);
     try {
     try {

+ 2 - 2
desktop/src/main/utils-temp.ts

@@ -37,7 +37,7 @@ const randomPrefix = (length: number) => {
  *
  *
  * Use {@link deleteTempFile} to remove this file when you're done.
  * Use {@link deleteTempFile} to remove this file when you're done.
  */
  */
-export const generateTempFilePath = async (formatSuffix: string) => {
+export const makeTempFilePath = async (formatSuffix: string) => {
     const tempDir = await enteTempDirPath();
     const tempDir = await enteTempDirPath();
     let result: string;
     let result: string;
     do {
     do {
@@ -54,7 +54,7 @@ export const generateTempFilePath = async (formatSuffix: string) => {
  * directory. This acts as an additional safety check.
  * directory. This acts as an additional safety check.
  *
  *
  * @param tempFilePath The path to the temporary file to delete. This path
  * @param tempFilePath The path to the temporary file to delete. This path
- * should've been previously created using {@link generateTempFilePath}.
+ * should've been previously created using {@link makeTempFilePath}.
  */
  */
 export const deleteTempFile = async (tempFilePath: string) => {
 export const deleteTempFile = async (tempFilePath: string) => {
     const tempDir = await enteTempDirPath();
     const tempDir = await enteTempDirPath();