-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (44 loc) · 1.64 KB
/
app.js
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
const express = require('express');
const redis = require('redis');
const fs = require('fs');
const bodyParser = require('body-parser');
var jsonParser = bodyParser.json()
var webmParser = bodyParser.raw({type: "audio/webm", limit: '50mb'})
const redisClient = redis.createClient();
redisClient.on('error', err => console.log('Redis Client Error', err));
const app = express()
const port = 3000
app.use(express.static(__dirname + '/public'));
app.get('/', async (req, res) => {
// const samples = await fs.promises.readdir(process.cwd() + '/../audiogen/samples');
res.sendFile('index.html', { root: __dirname });
})
app.get('/getsamplenames', async (req, res) => {
const samples = await fs.promises.readdir(process.cwd() + '/../audiogen/samples');
res.send(samples);
})
app.get('/getsample/:sample', async (req, res) => {
const sample = await fs.promises.readFile(process.cwd() + '/../audiogen/samples/' + req.params.sample);
res.send(sample);
})
app.post('/generateaudio', jsonParser, async (req, res) => {
await redisClient.connect();
const sample = req.body.sample;
if(!sample) {
res.status(400).send('No sample provided');
} else {
await redisClient.set(sample, "audiogen");
res.status(200).send('Enqueued task to generate audio')
}
await redisClient.disconnect();
})
app.post('/saverecording', webmParser, async (req, res) => {
const recording = req.body;
// console.log(recording);
filePath = process.cwd() + '/../audiogen/samples/recording.webm';
await fs.promises.writeFile(filePath, recording);
res.status(200).send('Recording saved')
});
app.listen(port, () => {
console.log(`jamjam listening on port ${port}`)
})