migrate to vips

This commit is contained in:
C4illin 2024-05-25 15:52:04 +02:00
parent d6b38c6866
commit d81a3a6ab4
11 changed files with 277 additions and 59 deletions

View file

@ -1,23 +1,22 @@
import {
properties as propertiesImage,
convert as convertImage,
} from "./sharp";
import { convert as convertImage, properties as propertiesImage } from "./vips";
import {
properties as propertiesPandoc,
convert as convertPandoc,
properties as propertiesPandoc,
} from "./pandoc";
import {
properties as propertiesFFmpeg,
convert as convertFFmpeg,
properties as propertiesFFmpeg,
} from "./ffmpeg";
import {
properties as propertiesGraphicsmagick,
convert as convertGraphicsmagick,
properties as propertiesGraphicsmagick,
} from "./graphicsmagick";
import { normalizeFiletype } from "../helpers/normalizeFiletype";
// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
const properties: {
@ -38,8 +37,7 @@ const properties: {
converter: (
filePath: string,
fileType: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
convertTo: any,
convertTo: string,
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
@ -47,7 +45,7 @@ const properties: {
) => any;
};
} = {
sharp: {
vips: {
properties: propertiesImage,
converter: convertImage,
},
@ -65,8 +63,6 @@ const properties: {
},
};
import { normalizeFiletype } from "../helpers/normalizeFiletype";
export async function mainConverter(
inputFilePath: string,
fileTypeOriginal: string,
@ -112,7 +108,7 @@ export async function mainConverter(
console.log(
`No available converter supports converting from ${fileType} to ${convertTo}.`,
);
return;
return "File type not supported"
}
try {
@ -123,14 +119,17 @@ export async function mainConverter(
targetPath,
options,
);
console.log(
`Converted ${inputFilePath} from ${fileType} to ${convertTo} successfully using ${converterName}.`,
);
return "Done"
} catch (error) {
console.error(
`Failed to convert ${inputFilePath} from ${fileType} to ${convertTo} using ${converterName}.`,
error,
);
return "Failed, check logs"
}
}
@ -256,4 +255,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}`);