diff --git a/Dockerfile b/Dockerfile index 3c264ad..295017c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,15 +40,17 @@ RUN apt-get update && apt-get install -y \ assimp-utils \ calibre \ dcraw \ + dvisvgm \ ffmpeg \ ghostscript \ graphicsmagick \ + imagemagick-7.q16 \ inkscape \ libheif-examples \ libjxl-tools \ libva2 \ libvips-tools \ - imagemagick-7.q16 \ + mupdf-tools \ pandoc \ poppler-utils \ potrace \ diff --git a/README.md b/README.md index c3036bc..8920cea 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ A self-hosted online file converter. Supports over a thousand different formats. | [XeLaTeX](https://tug.org/xetex/) | LaTeX | 1 | 1 | | [Calibre](https://calibre-ebook.com/) | E-books | 26 | 19 | | [Pandoc](https://pandoc.org/) | Documents | 43 | 65 | +| [dvisvgm](https://dvisvgm.de/) | Vector images | 4 | 2 | | [ImageMagick](https://imagemagick.org/) | Images | 245 | 183 | | [GraphicsMagick](http://www.graphicsmagick.org/) | Images | 167 | 130 | | [Inkscape](https://inkscape.org/) | Vector images | 7 | 17 | @@ -88,7 +89,7 @@ All are optional, JWT_SECRET is recommended to be set. | AUTO_DELETE_EVERY_N_HOURS | 24 | Checks every n hours for files older then n hours and deletes them, set to 0 to disable | | WEBROOT | | The address to the root path setting this to "/convert" will serve the website on "example.com/convert/" | | FFMPEG_ARGS | | Arguments to pass to ffmpeg, e.g. `-preset veryfast` | -| HIDE_HISTORY | false | Hide the history page | +| HIDE_HISTORY | false | Hide the history page | ### Docker images @@ -133,17 +134,12 @@ Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summar ## Todo -- [x] Add messages for errors in converters -- [x] Add searchable list of formats - [ ] Add options for converters -- [ ] Divide index.tsx into smaller components - [ ] Add tests -- [ ] Make the upload button nicer and more easy to drop files on. Support copy paste as well if possible. - [ ] Make errors logs visible from the web ui - [ ] Add more converters: - [ ] [deark](https://github.com/jsummers/deark) - [ ] LibreOffice - - [ ] [dvisvgm](https://github.com/mgieseki/dvisvgm) ## Contributors diff --git a/compose.yaml b/compose.yaml index 36ef9ae..183fd6b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -14,5 +14,6 @@ services: # - FFMPEG_ARGS=-hwaccel vulkan # additional arguments to pass to ffmpeg # - WEBROOT=/convertx # the root path of the web interface, leave empty to disable # - HIDE_HISTORY=true # hides the history tab in the web interface, defaults to false + - TZ=Europe/Stockholm # set your timezone, defaults to UTC ports: - 3000:3000 diff --git a/src/converters/dvisvgm.ts b/src/converters/dvisvgm.ts new file mode 100644 index 0000000..ef58c81 --- /dev/null +++ b/src/converters/dvisvgm.ts @@ -0,0 +1,52 @@ +import { execFile } from "node:child_process"; + +export const properties = { + from: { + images: ["dvi", "xdv", "pdf", "eps"], + }, + to: { + images: ["svg", "svgz"], + }, +}; + +export function convert( + filePath: string, + fileType: string, + convertTo: string, + targetPath: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + options?: unknown, +): Promise { + const inputArgs: string[] = []; + if (fileType === "eps") { + inputArgs.push("--eps"); + } + if (fileType === "pdf") { + inputArgs.push("--pdf"); + } + if (convertTo === "svgz") { + inputArgs.push("-z"); + } + + return new Promise((resolve, reject) => { + execFile( + "dvisvgm", + [...inputArgs, filePath, "-o", targetPath], + (error, stdout, stderr) => { + if (error) { + reject(`error: ${error}`); + } + + if (stdout) { + console.log(`stdout: ${stdout}`); + } + + if (stderr) { + console.error(`stderr: ${stderr}`); + } + + resolve("Done"); + }, + ); + }); +} diff --git a/src/converters/main.ts b/src/converters/main.ts index d544c0a..3d89e6a 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -12,6 +12,7 @@ import { convert as convertCalibre, properties as propertiesCalibre } from "./ca import { convert as convertLibheif, properties as propertiesLibheif } from "./libheif"; import { convert as convertPotrace, properties as propertiesPotrace } from "./potrace"; import { convert as convertImagemagick, properties as propertiesImagemagick } from "./imagemagick"; +import { convert as convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm"; // This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular @@ -72,6 +73,10 @@ const properties: Record< properties: propertiesPandoc, converter: convertPandoc, }, + dvisvgm: { + properties: propertiesDvisvgm, + converter: convertDvisvgm, + }, imagemagick: { properties: propertiesImagemagick, converter: convertImagemagick,