From 3872cd87b6923e3e0ff42cfb276681ba7e8a8b55 Mon Sep 17 00:00:00 2001 From: C4illin Date: Wed, 29 May 2024 11:59:52 +0200 Subject: [PATCH] add pdflatex --- Dockerfile | 6 ++++++ src/converters/main.ts | 9 ++++++++ src/converters/pdflatex.ts | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/converters/pdflatex.ts diff --git a/Dockerfile b/Dockerfile index 2bf2751..104a3c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,11 +26,17 @@ RUN cd /temp/prod && bun install --frozen-lockfile --production # copy production dependencies and source code into final image FROM base AS release +LABEL maintainer="Emrik Östling (C4illin)" +LABEL description="ConvertX: self-hosted online file converter supporting 700+ file formats." +LABEL repo="https://github.com/C4illin/ConvertX" + # install additional dependencies RUN rm -rf /var/lib/apt/lists/partial && apt-get update -o Acquire::CompressionTypes::Order::=gz \ && apt-get install -y \ pandoc \ texlive-latex-recommended \ + texlive-fonts-recommended \ + texlive-latex-extra \ ffmpeg \ graphicsmagick \ ghostscript \ diff --git a/src/converters/main.ts b/src/converters/main.ts index 766a97f..0807b97 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -15,6 +15,11 @@ import { properties as propertiesGraphicsmagick, } from "./graphicsmagick"; +import { + convert as convertPdflatex, + properties as propertiesPdflatex, +} from "./pdflatex"; + 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 @@ -49,6 +54,10 @@ const properties: { properties: propertiesImage, converter: convertImage, }, + pdflatex: { + properties: propertiesPdflatex, + converter: convertPdflatex, + }, pandoc: { properties: propertiesPandoc, converter: convertPandoc, diff --git a/src/converters/pdflatex.ts b/src/converters/pdflatex.ts new file mode 100644 index 0000000..36fba57 --- /dev/null +++ b/src/converters/pdflatex.ts @@ -0,0 +1,42 @@ +import { exec } from "node:child_process"; + +export const properties = { + from: { + text: ["tex", "latex"], + }, + to: { + text: ["pdf"], + }, +}; + +export function convert( + filePath: string, + fileType: string, + convertTo: string, + targetPath: string, + // biome-ignore lint/suspicious/noExplicitAny: + options?: any, +): Promise { + return new Promise((resolve, reject) => { + // const fileName: string = (targetPath.split("/").pop() as string).replace(".pdf", "") + const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "") + exec( + `pdflatex -interaction=nonstopmode -output-directory="${outputPath}" "${filePath}"`, + (error, stdout, stderr) => { + if (error) { + reject(`error: ${error}`); + } + + if (stdout) { + console.log(`stdout: ${stdout}`); + } + + if (stderr) { + console.error(`stderr: ${stderr}`); + } + + resolve("success"); + }, + ); + }); +}