gen => make
This commit is contained in:
@@ -4,8 +4,8 @@ import path from "path";
|
||||
import { CustomErrorMessage, ElectronFile } from "../../types/ipc";
|
||||
import log from "../log";
|
||||
import { writeStream } from "../stream";
|
||||
import { deleteTempFile, generateTempFilePath } from "../temp";
|
||||
import { execAsync, isDev } from "../utils-electron";
|
||||
import { deleteTempFile, makeTempFilePath } from "../utils-temp";
|
||||
|
||||
const IMAGE_MAGICK_PLACEHOLDER = "IMAGE_MAGICK";
|
||||
const MAX_DIMENSION_PLACEHOLDER = "MAX_DIMENSION";
|
||||
@@ -78,8 +78,8 @@ export const convertToJPEG = async (
|
||||
let tempInputFilePath: string;
|
||||
let tempOutputFilePath: string;
|
||||
try {
|
||||
tempInputFilePath = await generateTempFilePath(fileName);
|
||||
tempOutputFilePath = await generateTempFilePath("output.jpeg");
|
||||
tempInputFilePath = await makeTempFilePath(fileName);
|
||||
tempOutputFilePath = await makeTempFilePath("output.jpeg");
|
||||
|
||||
await fs.writeFile(tempInputFilePath, imageData);
|
||||
|
||||
@@ -157,7 +157,7 @@ export async function generateImageThumbnail(
|
||||
CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED,
|
||||
);
|
||||
if (!existsSync(inputFile.path)) {
|
||||
const tempFilePath = await generateTempFilePath(inputFile.name);
|
||||
const tempFilePath = await makeTempFilePath(inputFile.name);
|
||||
await writeStream(tempFilePath, await inputFile.stream());
|
||||
inputFilePath = tempFilePath;
|
||||
createdTempInputFile = true;
|
||||
@@ -189,7 +189,7 @@ async function generateImageThumbnail_(
|
||||
let tempOutputFilePath: string;
|
||||
let quality = MAX_QUALITY;
|
||||
try {
|
||||
tempOutputFilePath = await generateTempFilePath("thumb.jpeg");
|
||||
tempOutputFilePath = await makeTempFilePath("thumb.jpeg");
|
||||
let thumbnail: Uint8Array;
|
||||
do {
|
||||
await execAsync(
|
||||
|
||||
@@ -6,7 +6,7 @@ import log from "../log";
|
||||
import { writeStream } from "../stream";
|
||||
import { withTimeout } from "../utils";
|
||||
import { execAsync } from "../utils-electron";
|
||||
import { deleteTempFile, generateTempFilePath } from "../utils-temp";
|
||||
import { deleteTempFile, makeTempFilePath } from "../utils-temp";
|
||||
|
||||
const INPUT_PATH_PLACEHOLDER = "INPUT";
|
||||
const FFMPEG_PLACEHOLDER = "FFMPEG";
|
||||
@@ -49,7 +49,7 @@ export async function runFFmpegCmd(
|
||||
let createdTempInputFile = null;
|
||||
try {
|
||||
if (!existsSync(inputFile.path)) {
|
||||
const tempFilePath = await generateTempFilePath(inputFile.name);
|
||||
const tempFilePath = await makeTempFilePath(inputFile.name);
|
||||
await writeStream(tempFilePath, await inputFile.stream());
|
||||
inputFilePath = tempFilePath;
|
||||
createdTempInputFile = true;
|
||||
@@ -78,7 +78,7 @@ export async function runFFmpegCmd_(
|
||||
) {
|
||||
let tempOutputFilePath: string;
|
||||
try {
|
||||
tempOutputFilePath = await generateTempFilePath(outputFileName);
|
||||
tempOutputFilePath = await makeTempFilePath(outputFileName);
|
||||
|
||||
cmd = cmd.map((cmdPart) => {
|
||||
if (cmdPart === FFMPEG_PLACEHOLDER) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as ort from "onnxruntime-node";
|
||||
import Tokenizer from "../../thirdparty/clip-bpe-ts/mod";
|
||||
import log from "../log";
|
||||
import { writeStream } from "../stream";
|
||||
import { deleteTempFile, generateTempFilePath } from "../utils-temp";
|
||||
import { deleteTempFile, makeTempFilePath } from "../utils-temp";
|
||||
import { makeCachedInferenceSession } from "./ml";
|
||||
|
||||
const cachedCLIPImageSession = makeCachedInferenceSession(
|
||||
@@ -20,7 +20,7 @@ const cachedCLIPImageSession = makeCachedInferenceSession(
|
||||
);
|
||||
|
||||
export const clipImageEmbedding = async (jpegImageData: Uint8Array) => {
|
||||
const tempFilePath = await generateTempFilePath("");
|
||||
const tempFilePath = await makeTempFilePath("");
|
||||
const imageStream = new Response(jpegImageData.buffer).body;
|
||||
await writeStream(tempFilePath, imageStream);
|
||||
try {
|
||||
|
||||
@@ -37,7 +37,7 @@ const randomPrefix = (length: number) => {
|
||||
*
|
||||
* 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();
|
||||
let result: string;
|
||||
do {
|
||||
@@ -54,7 +54,7 @@ export const generateTempFilePath = async (formatSuffix: string) => {
|
||||
* directory. This acts as an additional safety check.
|
||||
*
|
||||
* @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) => {
|
||||
const tempDir = await enteTempDirPath();
|
||||
|
||||
Reference in New Issue
Block a user