MCPcopy
hub / github.com/C4illin/ConvertX / convert

Function convert

src/converters/libreoffice.ts:137–179  ·  view source on GitHub ↗
(
  filePath: string,
  fileType: string,
  convertTo: string,
  targetPath: string,
  options?: unknown,
  execFile: ExecFileFn = execFileOriginal,
)

Source from the content-addressed store, hash-verified

135};
136
137export function convert(
138 filePath: string,
139 fileType: string,
140 convertTo: string,
141 targetPath: string,
142 options?: unknown,
143 execFile: ExecFileFn = execFileOriginal,
144): Promise<string> {
145 const outputPath = targetPath.split("/").slice(0, -1).join("/").replace("./", "") ?? targetPath;
146
147 // Build arguments array
148 const args: string[] = [];
149 args.push("--headless");
150 const [inFilter, outFilter] = getFilters(fileType, convertTo);
151
152 if (inFilter) {
153 args.push(`--infilter=${inFilter}`);
154 }
155
156 if (outFilter) {
157 args.push("--convert-to", `${convertTo}:${outFilter}`, "--outdir", outputPath, filePath);
158 } else {
159 args.push("--convert-to", convertTo, "--outdir", outputPath, filePath);
160 }
161
162 return new Promise((resolve, reject) => {
163 execFile("soffice", args, (error, stdout, stderr) => {
164 if (error) {
165 reject(`error: ${error}`);
166 }
167
168 if (stdout) {
169 console.log(`stdout: ${stdout}`);
170 }
171
172 if (stderr) {
173 console.error(`stderr: ${stderr}`);
174 }
175
176 resolve("Done");
177 });
178 });
179}

Callers 1

Calls 2

getFiltersFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected