mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-10-27 23:30:55 +01:00
feat: add DjVu conversion support (#612)
* feat: add DjVu conversion support * fix: support DjVu aliases and prioritize converter * fix: restore DjVu converter priority * [autofix.ci] apply automated fixes --------- Co-authored-by: Alex N <alex@alex-n.net> Co-authored-by: Emrik Östling <emrik.ostling@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -56,6 +56,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
calibre \
|
calibre \
|
||||||
dasel \
|
dasel \
|
||||||
dcraw \
|
dcraw \
|
||||||
|
djvulibre-bin \
|
||||||
dvisvgm \
|
dvisvgm \
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
ghostscript \
|
ghostscript \
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ A self-hosted online file converter. Supports over a thousand different formats.
|
|||||||
| [Calibre](https://calibre-ebook.com/) | E-books | 26 | 19 |
|
| [Calibre](https://calibre-ebook.com/) | E-books | 26 | 19 |
|
||||||
| [LibreOffice](https://www.libreoffice.org/) | Documents | 41 | 22 |
|
| [LibreOffice](https://www.libreoffice.org/) | Documents | 41 | 22 |
|
||||||
| [Dasel](https://github.com/TomWright/dasel) | Data Files | 5 | 4 |
|
| [Dasel](https://github.com/TomWright/dasel) | Data Files | 5 | 4 |
|
||||||
|
| [DjVuLibre](https://djvu.sourceforge.net/) | Documents | 2 | 2 |
|
||||||
| [Pandoc](https://pandoc.org/) | Documents | 43 | 65 |
|
| [Pandoc](https://pandoc.org/) | Documents | 43 | 65 |
|
||||||
| [msgconvert](https://github.com/mvz/email-outlook-message-perl) | Outlook | 1 | 1 |
|
| [msgconvert](https://github.com/mvz/email-outlook-message-perl) | Outlook | 1 | 1 |
|
||||||
| VCF to CSV | Contacts | 1 | 1 |
|
| VCF to CSV | Contacts | 1 | 1 |
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { execFile as execFileOriginal } from "node:child_process";
|
||||||
|
import type { ExecFileFn } from "./types";
|
||||||
|
|
||||||
|
export const properties = {
|
||||||
|
from: {
|
||||||
|
document: ["djvu", "djv"],
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
document: ["pdf", "tiff"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function convert(
|
||||||
|
filePath: string,
|
||||||
|
_fileType: string,
|
||||||
|
convertTo: string,
|
||||||
|
targetPath: string,
|
||||||
|
_options?: unknown,
|
||||||
|
execFile: ExecFileFn = execFileOriginal,
|
||||||
|
): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile("ddjvu", [`-format=${convertTo}`, filePath, targetPath], (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ""}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout) {
|
||||||
|
console.log(`stdout: ${stdout}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`stderr: ${stderr}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve("Done");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalize
|
|||||||
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
|
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
|
||||||
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
|
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
|
||||||
import { convert as convertDasel, properties as propertiesDasel } from "./dasel";
|
import { convert as convertDasel, properties as propertiesDasel } from "./dasel";
|
||||||
|
import { convert as convertDjvu, properties as propertiesDjvu } from "./djvu";
|
||||||
import { convert as convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm";
|
import { convert as convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm";
|
||||||
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
|
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
|
||||||
import {
|
import {
|
||||||
@@ -92,6 +93,10 @@ const properties: Record<
|
|||||||
properties: propertiesDasel,
|
properties: propertiesDasel,
|
||||||
converter: convertDasel,
|
converter: convertDasel,
|
||||||
},
|
},
|
||||||
|
djvu: {
|
||||||
|
properties: propertiesDjvu,
|
||||||
|
converter: convertDjvu,
|
||||||
|
},
|
||||||
libreoffice: {
|
libreoffice: {
|
||||||
properties: propertiesLibreOffice,
|
properties: propertiesLibreOffice,
|
||||||
converter: convertLibreOffice,
|
converter: convertLibreOffice,
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import type { ExecFileException } from "node:child_process";
|
||||||
|
import { expect, test } from "bun:test";
|
||||||
|
import { convert, properties } from "../../src/converters/djvu";
|
||||||
|
import type { ExecFileFn } from "../../src/converters/types";
|
||||||
|
import { runCommonTests } from "./helpers/commonTests";
|
||||||
|
|
||||||
|
runCommonTests(convert);
|
||||||
|
|
||||||
|
test("advertises DjVu to PDF and TIFF conversions", () => {
|
||||||
|
expect(properties).toEqual({
|
||||||
|
from: { document: ["djvu", "djv"] },
|
||||||
|
to: { document: ["pdf", "tiff"] },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const format of ["pdf", "tiff"]) {
|
||||||
|
test(`calls ddjvu with the ${format} output format`, async () => {
|
||||||
|
let command = "";
|
||||||
|
let args: string[] = [];
|
||||||
|
const mockExecFile: ExecFileFn = (
|
||||||
|
cmd: string,
|
||||||
|
commandArgs: string[],
|
||||||
|
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||||
|
) => {
|
||||||
|
command = cmd;
|
||||||
|
args = commandArgs;
|
||||||
|
callback(null, "", "");
|
||||||
|
};
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
convert("input.djvu", "djvu", format, `output.${format}`, undefined, mockExecFile),
|
||||||
|
).resolves.toBe("Done");
|
||||||
|
expect(command).toBe("ddjvu");
|
||||||
|
expect(args).toEqual([`-format=${format}`, "input.djvu", `output.${format}`]);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user