setup
This commit is contained in:
parent
bd36314f00
commit
dcb15aee0e
3 changed files with 60 additions and 0 deletions
45
src/converters/libreoffice.ts
Normal file
45
src/converters/libreoffice.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
|
export const properties = {
|
||||||
|
from: {
|
||||||
|
text: ["docx", "txt"],
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
text: ["pdf", "txt"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function convert(
|
||||||
|
filePath: string,
|
||||||
|
fileType: string,
|
||||||
|
convertTo: string,
|
||||||
|
targetPath: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
options?: unknown,
|
||||||
|
): Promise<string> {
|
||||||
|
const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "");
|
||||||
|
// Build arguments array
|
||||||
|
const args: string[] = [];
|
||||||
|
|
||||||
|
args.push("--headless");
|
||||||
|
args.push("--convert-to", convertTo, filePath);
|
||||||
|
args.push("--outdir", outputPath);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
execFile("soffice", args, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(`error: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout) {
|
||||||
|
console.log(`stdout: ${stdout}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`stderr: ${stderr}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve("Done");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,7 @@ import { convert as convertImagemagick, properties as propertiesImagemagick } fr
|
||||||
import { convert as convertInkscape, properties as propertiesInkscape } from "./inkscape";
|
import { convert as convertInkscape, properties as propertiesInkscape } from "./inkscape";
|
||||||
import { convert as convertLibheif, properties as propertiesLibheif } from "./libheif";
|
import { convert as convertLibheif, properties as propertiesLibheif } from "./libheif";
|
||||||
import { convert as convertLibjxl, properties as propertiesLibjxl } from "./libjxl";
|
import { convert as convertLibjxl, properties as propertiesLibjxl } from "./libjxl";
|
||||||
|
import { convert as convertLibreOffice, properties as propertiesLibreOffice } from "./libreoffice";
|
||||||
import { convert as convertPandoc, properties as propertiesPandoc } from "./pandoc";
|
import { convert as convertPandoc, properties as propertiesPandoc } from "./pandoc";
|
||||||
import { convert as convertPotrace, properties as propertiesPotrace } from "./potrace";
|
import { convert as convertPotrace, properties as propertiesPotrace } from "./potrace";
|
||||||
import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
|
import { convert as convertresvg, properties as propertiesresvg } from "./resvg";
|
||||||
|
|
@ -71,6 +72,10 @@ const properties: Record<
|
||||||
properties: propertiesCalibre,
|
properties: propertiesCalibre,
|
||||||
converter: convertCalibre,
|
converter: convertCalibre,
|
||||||
},
|
},
|
||||||
|
libreoffice: {
|
||||||
|
properties: propertiesLibreOffice,
|
||||||
|
converter: convertLibreOffice,
|
||||||
|
},
|
||||||
pandoc: {
|
pandoc: {
|
||||||
properties: propertiesPandoc,
|
properties: propertiesPandoc,
|
||||||
converter: convertPandoc,
|
converter: convertPandoc,
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,16 @@ if (process.env.NODE_ENV === "production") {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exec("soffice --version", (error, stdout) => {
|
||||||
|
if (error) {
|
||||||
|
console.error("libreoffice is not installed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout) {
|
||||||
|
console.log(stdout.split("\n")[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
exec("bun -v", (error, stdout) => {
|
exec("bun -v", (error, stdout) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Bun is not installed. wait what");
|
console.error("Bun is not installed. wait what");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue