-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
58 lines (49 loc) · 1.6 KB
/
app.ts
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
import { KitesFactory, KitesInstance } from '@kites/core';
import Express from '@kites/express';
import Rest from '@kites/rest';
import { AudioService, TextService } from './api';
import { static as st } from 'express';
import * as multer from 'multer';
import * as mkdirp from 'mkdirp';
async function bootstrap() {
const app = await KitesFactory
.create({
loadConfig: true,
providers: [
AudioService,
TextService,
],
})
.use(Express)
.use(Rest)
.ready((kites: KitesInstance) => {
kites.logger.info('Extra config app when ready!');
const storage = multer.diskStorage({
destination(req, file, cb) {
const speaker = req.param('speaker', 'wav');
const uploadDir = kites.appDirectory + '/data/' + speaker;
mkdirp(uploadDir, err => {
cb(null, uploadDir);
});
},
filename(req, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({ storage });
kites.express.app.post('/upload/:speaker', upload.single('audio_file'), (req, res, next) => {
const speaker = req.param('speaker');
const filename = req.file.filename;
res.ok({ speaker, filename });
});
// extra static folder
kites.express.app.use(st(kites.appDirectory + '/data'));
kites.express.app.use((err, req, res, next) => {
console.error('Error: ', err);
res.status(500).json(err.message);
});
})
.init();
app.logger.info(`Server started! Let's browse http://localhost:3000/api/todo`);
}
bootstrap();