(req, res)
| 1137 | } |
| 1138 | |
| 1139 | async function handleRequest(req, res) { |
| 1140 | const url = new URL(req.url, `http://${req.headers.host}`); |
| 1141 | if (req.method === "POST" && url.pathname === "/api/analyze") return handleAnalyze(req, res); |
| 1142 | if (req.method === "POST" && url.pathname === "/api/export") return handleExport(req, res); |
| 1143 | if (req.method === "POST" && url.pathname === "/api/export-collage") return handleExportCollage(req, res); |
| 1144 | if (req.method === "GET" && url.pathname === "/api/export-status") return handleExportStatus(req, res, url); |
| 1145 | if (req.method === "GET" && url.pathname === "/api/frame") return handleFrame(req, res, url); |
| 1146 | if (req.method === "GET" && url.pathname.startsWith("/media/")) { |
| 1147 | const [, , id, clip] = url.pathname.split("/"); |
| 1148 | const session = sessions.get(id); |
| 1149 | if (!session) return text(res, 404, "Session not found"); |
| 1150 | return serveFile(res, clip === "2" ? session.video2 : session.video1); |
| 1151 | } |
| 1152 | if (req.method === "GET" && url.pathname.startsWith("/outputs/")) { |
| 1153 | return serveFile(res, path.join(OUTPUTS, path.basename(url.pathname))); |
| 1154 | } |
| 1155 | const target = url.pathname === "/" ? path.join(PUBLIC, "index.html") : path.join(PUBLIC, path.normalize(url.pathname)); |
| 1156 | if (!target.startsWith(PUBLIC)) return text(res, 403, "Forbidden"); |
| 1157 | return serveFile(res, target); |
| 1158 | } |
| 1159 | |
| 1160 | ensureDirs().then(() => { |
| 1161 | const port = Number(process.env.PORT || 4177); |
nothing calls this directly
no test coverage detected