Skip to content

Commit

Permalink
feat: add calibre
Browse files Browse the repository at this point in the history
issue #191
  • Loading branch information
C4illin committed Dec 7, 2024
1 parent 447b4c5 commit 03d3edf
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 22 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ RUN apk --no-cache add \
vips-jxl \
libjxl-tools \
assimp \
inkscape
inkscape \
poppler-utils

RUN apk --no-cache add calibre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/

# this might be needed for some latex use cases, will add it if needed.
# texmf-dist-fontsextra \
Expand Down
32 changes: 16 additions & 16 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
services:
convertx:
build:
context: .
# dockerfile: Debian.Dockerfile
volumes:
- ./data:/app/data
environment: # Defaults are listed below. All are optional.
- ACCOUNT_REGISTRATION=true # true or false, doesn't matter for the first account (e.g. keep this to false if you only want one account)
- JWT_SECRET=aLongAndSecretStringUsedToSignTheJSONWebToken1234 # will use randomUUID() by default
- HTTP_ALLOWED=true # setting this to true is unsafe, only set this to true locally
- ALLOW_UNAUTHENTICATED=true # allows anyone to use the service without logging in, only set this to true locally
- AUTO_DELETE_EVERY_N_HOURS=1 # checks every n hours for files older then n hours and deletes them, set to 0 to disable
- WEBROOT=/convertx # the root path of the web interface, leave empty to disable
ports:
- 3000:3000
services:
convertx:
build:
context: .
# dockerfile: Debian.Dockerfile
volumes:
- ./data:/app/data
environment: # Defaults are listed below. All are optional.
- ACCOUNT_REGISTRATION=true # true or false, doesn't matter for the first account (e.g. keep this to false if you only want one account)
- JWT_SECRET=aLongAndSecretStringUsedToSignTheJSONWebToken1234 # will use randomUUID() by default
- HTTP_ALLOWED=true # setting this to true is unsafe, only set this to true locally
- ALLOW_UNAUTHENTICATED=true # allows anyone to use the service without logging in, only set this to true locally
- AUTO_DELETE_EVERY_N_HOURS=1 # checks every n hours for files older then n hours and deletes them, set to 0 to disable
# - WEBROOT=/convertx # the root path of the web interface, leave empty to disable
ports:
- 3000:3000
7 changes: 2 additions & 5 deletions src/converters/assimp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { exec } from "node:child_process";

// This could be done dynamically by running `ffmpeg -formats` and parsing the output
export const properties = {
from: {
muxer: [
object: [
"3d",
"3ds",
"3mf",
Expand Down Expand Up @@ -84,7 +83,7 @@ export const properties = {
],
},
to: {
muxer: [
object: [
"3ds",
"3mf",
"assbin",
Expand Down Expand Up @@ -120,8 +119,6 @@ export async function convert(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown,
): Promise<string> {
// let command = "ffmpeg";

const command = `assimp export "${filePath}" "${targetPath}"`;

return new Promise((resolve, reject) => {
Expand Down
86 changes: 86 additions & 0 deletions src/converters/calibre.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { exec } from "node:child_process";

export const properties = {
from: {
document: [
"azw4",
"chm",
"cbr",
"cbz",
"cbt",
"cba",
"cb7",
"djvu",
"docx",
"epub",
"fb2",
"htlz",
"html",
"lit",
"lrf",
"mobi",
"odt",
"pdb",
"pdf",
"pml",
"rb",
"rtf",
"recipe",
"snb",
"tcr",
"txt",
],
},
to: {
document: [
"azw3",
"docx",
"epub",
"fb2",
"html",
"htmlz",
"lit",
"lrf",
"mobi",
"oeb",
"pdb",
"pdf",
"pml",
"rb",
"rtf",
"snb",
"tcr",
"txt",
"txtz",
],
},
};

export async function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: unknown,
): Promise<string> {
const command = `ebook-convert "${filePath}" "${targetPath}"`;

return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}

if (stdout) {
console.log(`stdout: ${stdout}`);
}

if (stderr) {
console.error(`stderr: ${stderr}`);
}

resolve("Done");
});
});
}
5 changes: 5 additions & 0 deletions src/converters/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { convert as convertPandoc, properties as propertiesPandoc } from "./pand
import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
import { convert as convertImage, properties as propertiesImage } from "./vips";
import { convert as convertxelatex, properties as propertiesxelatex } from "./xelatex";
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";


// This should probably be reconstructed so that the functions are not imported instead the functions hook into this to make the converters more modular
Expand Down Expand Up @@ -56,6 +57,10 @@ const properties: Record<
properties: propertiesxelatex,
converter: convertxelatex,
},
calibre: {
properties: propertiesCalibre,
converter: convertCalibre,
},
pandoc: {
properties: propertiesPandoc,
converter: convertPandoc,
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/printVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ if (process.env.NODE_ENV === "production") {
}
});

exec("ebook-convert --version", (error, stdout) => {
if (error) {
console.error("ebook-convert (calibre) is not installed");
}

if (stdout) {
console.log(stdout.split("\n")[0]);
}
});

exec("bun -v", (error, stdout) => {
if (error) {
console.error("Bun is not installed. wait what");
Expand Down

0 comments on commit 03d3edf

Please sign in to comment.