chore: add message when resizing image

This commit is contained in:
C4illin 2024-10-06 00:40:34 +02:00
parent 64e4a271e1
commit 4f98f778f0
9 changed files with 29 additions and 44 deletions

View file

@ -137,7 +137,7 @@ export async function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}); });
}); });
} }

View file

@ -1,6 +1,5 @@
import { exec } from "node:child_process"; import { exec } from "node:child_process";
// This could be done dynamically by running `ffmpeg -formats` and parsing the output // This could be done dynamically by running `ffmpeg -formats` and parsing the output
export const properties = { export const properties = {
from: { from: {
@ -692,12 +691,13 @@ export async function convert(
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown, options?: unknown,
): Promise<string> { ): Promise<string> {
let extra = ""; let extra = "";
let message = "Done";
if (convertTo === "ico") { if (convertTo === "ico") {
// make sure image is 256x256 or smaller // make sure image is 256x256 or smaller
extra = `-filter:v "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease"` extra = `-filter:v "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease"`;
message = "Done: resized to 256x256";
} }
const command = `ffmpeg -i "${filePath}" ${extra} "${targetPath}"`; const command = `ffmpeg -i "${filePath}" ${extra} "${targetPath}"`;
@ -716,7 +716,7 @@ export async function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve(message);
}); });
}); });
} }

View file

@ -332,7 +332,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}, },
); );
}); });

View file

@ -65,7 +65,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}); });
}); });
} }

View file

@ -1,33 +1,13 @@
import { normalizeFiletype } from "../helpers/normalizeFiletype"; import { normalizeFiletype } from "../helpers/normalizeFiletype";
import { import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
convert as convertassimp, import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
properties as propertiesassimp, import { convert as convertGraphicsmagick, properties as propertiesGraphicsmagick } from "./graphicsmagick";
} from "./assimp"; import { convert as convertLibjxl, properties as propertiesLibjxl } from "./libjxl";
import { import { convert as convertPandoc, properties as propertiesPandoc } from "./pandoc";
convert as convertFFmpeg, import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
properties as propertiesFFmpeg,
} from "./ffmpeg";
import {
convert as convertGraphicsmagick,
properties as propertiesGraphicsmagick,
} from "./graphicsmagick";
import {
convert as convertLibjxl,
properties as propertiesLibjxl,
} from "./libjxl";
import {
convert as convertPandoc,
properties as propertiesPandoc,
} from "./pandoc";
import {
convert as convertresvg,
properties as propertiesresvg,
} from "./resvg";
import { convert as convertImage, properties as propertiesImage } from "./vips"; import { convert as convertImage, properties as propertiesImage } from "./vips";
import { import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
convert as convertxelatex,
properties as propertiesxelatex,
} from "./xelatex";
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular // This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
@ -103,8 +83,7 @@ export async function mainConverter(
) { ) {
const fileType = normalizeFiletype(fileTypeOriginal); const fileType = normalizeFiletype(fileTypeOriginal);
let converterFunc: ((filePath: string, fileType: string, convertTo: string, targetPath: string, options?: unknown) => unknown) | undefined; let converterFunc: typeof properties["libjxl"]["converter"] | undefined;
// let converterName = converterName;
if (converterName) { if (converterName) {
converterFunc = properties[converterName]?.converter; converterFunc = properties[converterName]?.converter;
@ -137,7 +116,7 @@ export async function mainConverter(
} }
try { try {
await converterFunc( const result = await converterFunc(
inputFilePath, inputFilePath,
fileType, fileType,
convertTo, convertTo,
@ -147,7 +126,13 @@ export async function mainConverter(
console.log( console.log(
`Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`, `Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`,
result,
); );
if (typeof result === "string") {
return result;
}
return "Done"; return "Done";
} catch (error) { } catch (error) {
console.error( console.error(

View file

@ -149,7 +149,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}, },
); );
}); });

View file

@ -31,7 +31,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}); });
}); });
} }

View file

@ -134,7 +134,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}, },
); );
}); });

View file

@ -39,7 +39,7 @@ export function convert(
console.error(`stderr: ${stderr}`); console.error(`stderr: ${stderr}`);
} }
resolve("success"); resolve("Done");
}, },
); );
}); });