MCPcopy
hub / github.com/midrender/revideo / renderWithoutCallback

Function renderWithoutCallback

packages/cli/src/server/render.ts:77–150  ·  view source on GitHub ↗
(req: Request, res: Response)

Source from the content-addressed store, hash-verified

75}
76
77async function renderWithoutCallback(req: Request, res: Response) {
78 // TODO: validate request body
79 const {variables, streamProgress, settings} = req.body;
80 const tempProjectName: `${string}.mp4` = `${uuidv4()}.mp4`;
81 const resultFilePath = path.join(process.cwd(), `output/${tempProjectName}`);
82
83 if (streamProgress) {
84 res.writeHead(200, {
85 // eslint-disable-next-line
86 'Content-Type': 'text/event-stream',
87 // eslint-disable-next-line
88 'Cache-Control': 'no-cache',
89 // eslint-disable-next-line
90 Connection: 'keep-alive',
91 });
92
93 const sendProgress = (worker: number, progress: number) => {
94 res.write(`event: progress\n`);
95 res.write(`data: ${JSON.stringify({worker, progress})}\n\n`);
96 };
97
98 try {
99 await renderVideo({
100 projectFile: process.env.PROJECT_FILE || '',
101 variables,
102 settings: {
103 ...settings,
104 outFile: tempProjectName,
105 progressCallback: sendProgress,
106 },
107 });
108
109 const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}`;
110 res.write(`event: completed\n`);
111 res.write(
112 `data: ${JSON.stringify({status: 'success', downloadLink})}\n\n`,
113 );
114 res.end();
115 scheduleCleanup(resultFilePath);
116 } catch (error: any) {
117 console.error(error);
118 res.write(`event: error\n`);
119 res.write(
120 `data: ${JSON.stringify({status: 'error', message: error.message})}\n\n`,
121 );
122 res.end();
123 }
124 } else {
125 try {
126 await renderVideo({
127 projectFile: process.env.PROJECT_FILE || '',
128 variables,
129 settings: {
130 ...settings,
131 outFile: tempProjectName,
132 },
133 });
134

Callers 1

renderFunction · 0.85

Calls 6

renderVideoFunction · 0.90
scheduleCleanupFunction · 0.90
writeMethod · 0.80
endMethod · 0.80
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected