Also fixes a Windows-specific bug in worker.js and cleanup.js: the
"run only if executed directly" guard compared import.meta.url against
`file://${process.argv[1]}`, which never matches on Windows (backslash
path separators, missing extra slash before the drive letter). main()
silently never ran, so the worker process started and exited
immediately without ever polling. Caught during this task's manual
verification of the full upload-convert-download flow. Fixed with
node:url's pathToFileURL, which builds a correct file:// URL cross-platform.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
35 lines
1.2 KiB
React
35 lines
1.2 KiB
React
import { useEffect, useState } from 'react';
|
|
import { fetchJobStatus, downloadUrl } from './api.js';
|
|
|
|
export function FileCard({ fileName, jobId, initialError }) {
|
|
const [status, setStatus] = useState(initialError ? 'failed' : 'pending');
|
|
const [errorMessage, setErrorMessage] = useState(initialError ?? null);
|
|
|
|
useEffect(() => {
|
|
if (!jobId || initialError) return undefined;
|
|
|
|
let cancelled = false;
|
|
const interval = setInterval(async () => {
|
|
const job = await fetchJobStatus(jobId);
|
|
if (cancelled) return;
|
|
setStatus(job.status);
|
|
if (job.status === 'failed') setErrorMessage(job.errorMessage);
|
|
if (job.status === 'done' || job.status === 'failed') clearInterval(interval);
|
|
}, 1500);
|
|
|
|
return () => {
|
|
cancelled = true;
|
|
clearInterval(interval);
|
|
};
|
|
}, [jobId, initialError]);
|
|
|
|
return (
|
|
<li className="file-card">
|
|
<span className="file-name">{fileName}</span>
|
|
{(status === 'pending' || status === 'processing') && <span>Conversion en cours...</span>}
|
|
{status === 'done' && <a href={downloadUrl(jobId)}>Télécharger</a>}
|
|
{status === 'failed' && <span className="error">{errorMessage}</span>}
|
|
</li>
|
|
);
|
|
}
|