(req: Request, res: Response)
| 15 | } |
| 16 | |
| 17 | async function renderWithCallback(req: Request, res: Response) { |
| 18 | // TODO: validate request body |
| 19 | const {variables, callbackUrl, settings} = req.body; |
| 20 | const tempProjectName = uuidv4(); |
| 21 | const outputFileName = `${tempProjectName}.mp4`; |
| 22 | res.json({tempProjectName}); |
| 23 | |
| 24 | try { |
| 25 | await renderVideo({ |
| 26 | projectFile: process.env.PROJECT_FILE || '', |
| 27 | variables, |
| 28 | settings: { |
| 29 | ...settings, |
| 30 | outFile: outputFileName, |
| 31 | }, |
| 32 | }); |
| 33 | |
| 34 | const resultFilePath = path.join(process.cwd(), `output/${outputFileName}`); |
| 35 | |
| 36 | const downloadLink = `${req.protocol}://${req.get('host')}/download/${outputFileName}`; |
| 37 | |
| 38 | const response = await axios.post( |
| 39 | callbackUrl, |
| 40 | { |
| 41 | tempProjectName, |
| 42 | status: 'success', |
| 43 | downloadLink, |
| 44 | }, |
| 45 | { |
| 46 | headers: { |
| 47 | // eslint-disable-next-line |
| 48 | 'Content-Type': 'application/json', |
| 49 | }, |
| 50 | }, |
| 51 | ); |
| 52 | |
| 53 | if (response.status !== 200) { |
| 54 | throw new Error('Callback URL responded with an error'); |
| 55 | } |
| 56 | |
| 57 | scheduleCleanup(resultFilePath); |
| 58 | } catch (error: any) { |
| 59 | console.error(error); |
| 60 | await axios.post( |
| 61 | callbackUrl, |
| 62 | { |
| 63 | tempProjectName, |
| 64 | status: 'error', |
| 65 | error: error.message, |
| 66 | }, |
| 67 | { |
| 68 | headers: { |
| 69 | // eslint-disable-next-line |
| 70 | 'Content-Type': 'application/json', |
| 71 | }, |
| 72 | }, |
| 73 | ); |
| 74 | } |
no test coverage detected