Create file controller to upload audio document
This commit is contained in:
parent
45ad4bbb36
commit
844bffa988
6 changed files with 171 additions and 19 deletions
|
@ -7,12 +7,14 @@ import bodyParser = require('body-parser');
|
|||
import * as http from "http";
|
||||
import {MapController} from "./Controller/MapController";
|
||||
import {PrometheusController} from "./Controller/PrometheusController";
|
||||
import {FileController} from "./Controller/FileController";
|
||||
|
||||
class App {
|
||||
public app: Application;
|
||||
public server: http.Server;
|
||||
public ioSocketController: IoSocketController;
|
||||
public authenticateController: AuthenticateController;
|
||||
public fileController: FileController;
|
||||
public mapController: MapController;
|
||||
public prometheusController: PrometheusController;
|
||||
|
||||
|
@ -30,6 +32,7 @@ class App {
|
|||
//create socket controllers
|
||||
this.ioSocketController = new IoSocketController(this.server);
|
||||
this.authenticateController = new AuthenticateController(this.app);
|
||||
this.fileController = new FileController(this.app);
|
||||
this.mapController = new MapController(this.app);
|
||||
this.prometheusController = new PrometheusController(this.app, this.ioSocketController);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import {Application, Request, Response} from "express";
|
||||
import {Application, Request, RequestHandler, Response} from "express";
|
||||
import {OK} from "http-status-codes";
|
||||
import {URL_ROOM_STARTED} from "_Enum/EnvironmentVariable";
|
||||
import {uuid} from "uuidv4";
|
||||
import multer from 'multer';
|
||||
import fs from "fs";
|
||||
|
||||
const upload = multer({ dest: 'dist/files/' });
|
||||
|
||||
export class FileController {
|
||||
App : Application;
|
||||
|
@ -13,26 +17,30 @@ export class FileController {
|
|||
}
|
||||
|
||||
uploadAudioMessage(){
|
||||
this.App.post("/upload-audio-message", (req: Request, res: Response) => {
|
||||
this.App.post("/upload-audio-message", (upload.single('file') as RequestHandler), (req: Request, res: Response) => {
|
||||
//TODO check user connected and admin role
|
||||
//TODO upload audio message
|
||||
const audioMessageId = uuid();
|
||||
|
||||
fs.copyFileSync(req.file.path, `dist/files/${audioMessageId}`);
|
||||
fs.unlinkSync(req.file.path);
|
||||
|
||||
return res.status(OK).send({
|
||||
id: audioMessageId,
|
||||
audioMessageUrl: `/audi-message/${audioMessageId}`,
|
||||
path: `/download-audio-message/${audioMessageId}`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
downloadAudioMessage(){
|
||||
this.App.post("/download-audio-message/:id", (req: Request, res: Response) => {
|
||||
this.App.get("/download-audio-message/:id", (req: Request, res: Response) => {
|
||||
//TODO check user connected and admin role
|
||||
//TODO upload audio message
|
||||
let audiMessageId = req.params.id;
|
||||
const audiMessageId = req.params.id;
|
||||
|
||||
let fs = require('fs');
|
||||
let path = `/dist/files/${audiMessageId}`;
|
||||
let file = fs.createReadStream(path);
|
||||
const fs = require('fs');
|
||||
const path = `dist/files/${audiMessageId}`;
|
||||
const file = fs.createReadStream(path);
|
||||
res.writeHead(200);
|
||||
file.pipe(res);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue