diff --git a/src/converters/assimp.ts b/src/converters/assimp.ts index 1ef7c6a..b0c9241 100644 --- a/src/converters/assimp.ts +++ b/src/converters/assimp.ts @@ -137,7 +137,7 @@ export async function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }); }); } diff --git a/src/converters/ffmpeg.ts b/src/converters/ffmpeg.ts index 7a3ab66..52b776d 100644 --- a/src/converters/ffmpeg.ts +++ b/src/converters/ffmpeg.ts @@ -1,6 +1,5 @@ import { exec } from "node:child_process"; - // This could be done dynamically by running `ffmpeg -formats` and parsing the output export const properties = { from: { @@ -692,7 +691,16 @@ export async function convert( // eslint-disable-next-line @typescript-eslint/no-unused-vars options?: unknown, ): Promise { - const command = `ffmpeg -i "${filePath}" "${targetPath}"`; + let extra = ""; + let message = "Done"; + + if (convertTo === "ico") { + // make sure image is 256x256 or smaller + 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}"`; return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { @@ -708,7 +716,7 @@ export async function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve(message); }); }); -} \ No newline at end of file +} diff --git a/src/converters/graphicsmagick.ts b/src/converters/graphicsmagick.ts index cde4a4a..78a951d 100644 --- a/src/converters/graphicsmagick.ts +++ b/src/converters/graphicsmagick.ts @@ -332,7 +332,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }, ); }); diff --git a/src/converters/libjxl.ts b/src/converters/libjxl.ts index cb828f2..fbf61bd 100644 --- a/src/converters/libjxl.ts +++ b/src/converters/libjxl.ts @@ -65,7 +65,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }); }); } diff --git a/src/converters/main.ts b/src/converters/main.ts index 6a68e85..39ba442 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -1,33 +1,13 @@ import { normalizeFiletype } from "../helpers/normalizeFiletype"; -import { - convert as convertassimp, - properties as propertiesassimp, -} from "./assimp"; -import { - convert as convertFFmpeg, - 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 convertassimp, properties as propertiesassimp } from "./assimp"; +import { convert as convertFFmpeg, 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 convertxelatex, - properties as propertiesxelatex, -} from "./xelatex"; +import { 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 @@ -103,8 +83,7 @@ export async function mainConverter( ) { const fileType = normalizeFiletype(fileTypeOriginal); - let converterFunc: ((filePath: string, fileType: string, convertTo: string, targetPath: string, options?: unknown) => unknown) | undefined; - // let converterName = converterName; + let converterFunc: typeof properties["libjxl"]["converter"] | undefined; if (converterName) { converterFunc = properties[converterName]?.converter; @@ -137,7 +116,7 @@ export async function mainConverter( } try { - await converterFunc( + const result = await converterFunc( inputFilePath, fileType, convertTo, @@ -147,7 +126,13 @@ export async function mainConverter( console.log( `Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`, + result, ); + + if (typeof result === "string") { + return result; + } + return "Done"; } catch (error) { console.error( @@ -279,4 +264,4 @@ export const getAllInputs = (converter: string) => { // } // // print the number of unique Inputs and Outputs -// console.log(`Unique Formats: ${uniqueFormats.size}`); +// console.log(`Unique Formats: ${uniqueFormats.size}`); \ No newline at end of file diff --git a/src/converters/pandoc.ts b/src/converters/pandoc.ts index e43dc5f..36053f1 100644 --- a/src/converters/pandoc.ts +++ b/src/converters/pandoc.ts @@ -149,7 +149,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }, ); }); diff --git a/src/converters/resvg.ts b/src/converters/resvg.ts index ebba700..0fb9ca5 100644 --- a/src/converters/resvg.ts +++ b/src/converters/resvg.ts @@ -31,7 +31,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }); }); } diff --git a/src/converters/vips.ts b/src/converters/vips.ts index 65f8acd..db2595d 100644 --- a/src/converters/vips.ts +++ b/src/converters/vips.ts @@ -134,7 +134,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }, ); }); diff --git a/src/converters/xelatex.ts b/src/converters/xelatex.ts index fda01f4..73cd8f5 100644 --- a/src/converters/xelatex.ts +++ b/src/converters/xelatex.ts @@ -39,7 +39,7 @@ export function convert( console.error(`stderr: ${stderr}`); } - resolve("success"); + resolve("Done"); }, ); });