feat: add ebook converter wrapping Calibre's ebook-convert CLI

This commit is contained in:
2026-07-31 13:23:01 +02:00
parent 0cef6842de
commit b95e371989
2 changed files with 105 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { register } from './registry.js';
const execFileAsync = promisify(execFile);
export const EBOOK_FORMATS = ['epub', 'fb2', 'lrf', 'mobi', 'pdb', 'rb', 'snb', 'tcr', 'azw3', 'pdf'];
export function registerEbookConverter() {
for (const sourceFormat of EBOOK_FORMATS) {
for (const targetFormat of EBOOK_FORMATS) {
if (sourceFormat === targetFormat) continue;
register({
family: 'ebook',
sourceFormat,
targetFormat,
convert: async (inputPath, outputPath, options = {}) => {
const calibrePath = process.env.CALIBRE_PATH || 'ebook-convert';
await execFileAsync(calibrePath, [inputPath, outputPath], { timeout: options.timeoutMs });
},
});
}
}
}