feat: add ebook converter wrapping Calibre's ebook-convert CLI
This commit is contained in:
@@ -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 });
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user