Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,027 Bytes
2cae2a9 be866be 1fc1c4d be866be 2cae2a9 be866be 2cae2a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import express from "express"
import { Blob } from "buffer"
import { parseClap } from "./core/clap/parseClap.mts"
import { ClapProject } from "./core/clap/types.mts"
const app = express()
const port = 7860
process.on('unhandledRejection', (reason: string, p: Promise<any>) => {
console.error('Unhandled Rejection at:', p, 'reason:', reason);
})
process.on('uncaughtException', (error: Error) => {
console.error(`Caught exception: ${error}\n` + `Exception origin: ${error.stack}`);
})
// fix this error: "PayloadTooLargeError: request entity too large"
// there are multiple version because.. yeah well, it's Express!
// app.use(bodyParser.json({limit: '50mb'}));
//app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(express.json({ limit: '200mb' }));
app.use(express.urlencoded({ limit: '200mb', extended: true }));
app.get("/", async (req, res) => {
res.status(200)
res.write(`<html>
<head></head>
<body>
<p style="color: black; font-family: monospace;">
This API is a component of the Clap-to-MP4 rendering service provided by AiTube.<br/>
It is used for instance by the Stories Factory.
</p>
</body>
<html>`)
res.end()
})
// the export robot has only one job: to export .clap files
app.post("/", async (req, res) => {
let data: Uint8Array[] = [];
req.on("data", (chunk) => {
data.push(chunk);
});
req.on("end", async () => {
let clapProject: ClapProject
try {
let fileData = Buffer.concat(data);
const clapBlob = new Blob([fileData]);
clapProject = await parseClap(clapBlob);
console.log("got a clap project!:", clapProject)
} catch (err) {
console.error(`failed to parse the request: ${err}`)
res.status(500)
res.write(JSON.stringify({ "error": `${err}` }))
res.end()
return
}
// TODO read the mp4 file and convert it to
res.status(200)
res.write("TODO")
res.end()
});
})
app.listen(port, () => {
console.log(`Open http://localhost:${port}`)
}) |