wrap converters in promises
This commit is contained in:
parent
7a9def556d
commit
a41e5d8c99
8 changed files with 70 additions and 57 deletions
|
|
@ -772,7 +772,7 @@ export async function convert(
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||||
options?: any,
|
options?: any,
|
||||||
) {
|
): Promise<string> {
|
||||||
// let command = "ffmpeg";
|
// let command = "ffmpeg";
|
||||||
|
|
||||||
// these are containers that can contain multiple formats
|
// these are containers that can contain multiple formats
|
||||||
|
|
@ -807,9 +807,10 @@ export async function convert(
|
||||||
|
|
||||||
const command = `ffmpeg -i "${filePath}" "${targetPath}"`;
|
const command = `ffmpeg -i "${filePath}" "${targetPath}"`;
|
||||||
|
|
||||||
return exec(command, (error, stdout, stderr) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdout) {
|
if (stdout) {
|
||||||
|
|
@ -819,5 +820,8 @@ export async function convert(
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve("success");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -315,12 +315,13 @@ export function convert(
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||||
options?: any,
|
options?: any,
|
||||||
) {
|
): Promise<string> {
|
||||||
return exec(
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(
|
||||||
`gm convert "${filePath}" "${targetPath}"`,
|
`gm convert "${filePath}" "${targetPath}"`,
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdout) {
|
if (stdout) {
|
||||||
|
|
@ -330,6 +331,9 @@ export function convert(
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve("success");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,12 +126,13 @@ export function convert(
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||||
options?: any,
|
options?: any,
|
||||||
) {
|
): Promise<string> {
|
||||||
return exec(
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(
|
||||||
`pandoc "${filePath}" -f ${fileType} -t ${convertTo} -o "${targetPath}"`,
|
`pandoc "${filePath}" -f ${fileType} -t ${convertTo} -o "${targetPath}"`,
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdout) {
|
if (stdout) {
|
||||||
|
|
@ -141,6 +142,9 @@ export function convert(
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve("success");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ export function convert(
|
||||||
targetPath: string,
|
targetPath: string,
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||||
options?: any,
|
options?: any,
|
||||||
) {
|
): Promise<string> {
|
||||||
// if (fileType === "svg") {
|
// if (fileType === "svg") {
|
||||||
// const scale = options.scale || 1;
|
// const scale = options.scale || 1;
|
||||||
// const metadata = await sharp(filePath).metadata();
|
// const metadata = await sharp(filePath).metadata();
|
||||||
|
|
@ -114,11 +114,10 @@ export function convert(
|
||||||
// .toFile(targetPath);
|
// .toFile(targetPath);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return exec(
|
return new Promise((resolve, reject) => {
|
||||||
`vips copy ${filePath} ${targetPath}`,
|
exec(`vips copy ${filePath} ${targetPath}`, (error, stdout, stderr) => {
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdout) {
|
if (stdout) {
|
||||||
|
|
@ -128,6 +127,8 @@ export function convert(
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error(`stderr: ${stderr}`);
|
console.error(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
);
|
resolve("success");
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -824,7 +824,7 @@ const app = new Elysia()
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.get(
|
.post(
|
||||||
"/progress/:jobId",
|
"/progress/:jobId",
|
||||||
async ({ jwt, set, params, redirect, cookie: { auth, job_id } }) => {
|
async ({ jwt, set, params, redirect, cookie: { auth, job_id } }) => {
|
||||||
if (!auth?.value) {
|
if (!auth?.value) {
|
||||||
|
|
@ -877,6 +877,7 @@ const app = new Elysia()
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Converted File Name</th>
|
<th>Converted File Name</th>
|
||||||
|
<th>Status</th>
|
||||||
<th>View</th>
|
<th>View</th>
|
||||||
<th>Download</th>
|
<th>Download</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -886,6 +887,7 @@ const app = new Elysia()
|
||||||
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
|
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{file.output_file_name}</td>
|
<td>{file.output_file_name}</td>
|
||||||
|
<td>{file.status}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href={`/download/${outputPath}${file.output_file_name}`}>
|
<a href={`/download/${outputPath}${file.output_file_name}`}>
|
||||||
View
|
View
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,10 @@ const main = document.querySelector("main");
|
||||||
const progressElem = document.querySelector("progress");
|
const progressElem = document.querySelector("progress");
|
||||||
|
|
||||||
const refreshData = () => {
|
const refreshData = () => {
|
||||||
console.log("Refreshing data...");
|
|
||||||
console.log(progressElem.value);
|
|
||||||
console.log(progressElem.max);
|
|
||||||
|
|
||||||
if (progressElem.value !== progressElem.max) {
|
if (progressElem.value !== progressElem.max) {
|
||||||
fetch(`/progress/${jobId}`)
|
fetch(`/progress/${jobId}`, {
|
||||||
|
method: "POST",
|
||||||
|
})
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
main.innerHTML = html;
|
main.innerHTML = html;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ const fileInput = document.querySelector('input[type="file"]');
|
||||||
const fileNames = [];
|
const fileNames = [];
|
||||||
let fileType;
|
let fileType;
|
||||||
|
|
||||||
const selectElem = document.querySelector("select[name='convert_to']");
|
const selectContainer = document.querySelector("form > article");
|
||||||
|
|
||||||
// const convertFromSelect = document.querySelector("select[name='convert_from']");
|
// const convertFromSelect = document.querySelector("select[name='convert_from']");
|
||||||
|
|
||||||
|
|
@ -46,9 +46,9 @@ fileInput.addEventListener("change", (e) => {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => res.text()) // Convert the response to text
|
.then((res) => res.text())
|
||||||
.then((html) => {
|
.then((html) => {
|
||||||
selectElem.outerHTML = html; // Set the HTML
|
selectContainer.innerHTML = html;
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err));
|
.catch((err) => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue