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

Function handleConvert

src/converters/main.ts:151–195  ·  view source on GitHub ↗
(
  fileNames: string[],
  userUploadsDir: string,
  userOutputDir: string,
  convertTo: string,
  converterName: string,
  jobId: Cookie<string | undefined>,
)

Source from the content-addressed store, hash-verified

149}
150
151export async function handleConvert(
152 fileNames: string[],
153 userUploadsDir: string,
154 userOutputDir: string,
155 convertTo: string,
156 converterName: string,
157 jobId: Cookie<string | undefined>,
158) {
159 const query = db.query(
160 "INSERT INTO file_names (job_id, file_name, output_file_name, status) VALUES (?1, ?2, ?3, ?4)",
161 );
162
163 for (const chunk of chunks(fileNames, MAX_CONVERT_PROCESS)) {
164 const toProcess: Promise<string>[] = [];
165 for (const fileName of chunk) {
166 const filePath = `${userUploadsDir}${fileName}`;
167 const fileTypeOrig = fileName.includes(".") ? (fileName.split(".").pop() ?? "") : "";
168 const fileType = normalizeFiletype(fileTypeOrig);
169 const newFileExt = normalizeOutputFiletype(convertTo);
170 let newFileName: string;
171 if (fileTypeOrig === "") {
172 newFileName = `${fileName}.${newFileExt}`;
173 } else {
174 newFileName = fileName.replace(
175 new RegExp(`${fileTypeOrig}(?!.*${fileTypeOrig})`),
176 newFileExt,
177 );
178 }
179 const targetPath = `${userOutputDir}${newFileName}`;
180 toProcess.push(
181 new Promise((resolve, reject) => {
182 mainConverter(filePath, fileType, convertTo, targetPath, {}, converterName)
183 .then((r) => {
184 if (jobId.value) {
185 query.run(jobId.value, fileName, newFileName, r);
186 }
187 resolve(r);
188 })
189 .catch((c) => reject(c));
190 }),
191 );
192 }
193 await Promise.all(toProcess);
194 }
195}
196
197async function mainConverter(
198 inputFilePath: string,

Callers 1

convert.tsxFile · 0.90

Calls 5

normalizeFiletypeFunction · 0.90
normalizeOutputFiletypeFunction · 0.90
chunksFunction · 0.85
mainConverterFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected