This commit is contained in:
Gregoire Parant 2020-09-23 18:28:12 +02:00
parent d5fdb9d857
commit 4beeb62c6f
4 changed files with 2254 additions and 21 deletions

View file

@ -1,12 +1,23 @@
const multer = require('multer');
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/' });
class FileUpload{
path: string
constructor(path : string) {
this.path = path;
}
}
interface RequestFileHandlerInterface extends Request{
file: FileUpload
}
export class FileController {
App : Application;
@ -22,8 +33,8 @@ export class FileController {
//TODO upload audio message
const audioMessageId = uuid();
fs.copyFileSync(req.file.path, `dist/files/${audioMessageId}`);
fs.unlinkSync(req.file.path);
fs.copyFileSync((req as RequestFileHandlerInterface).file.path, `dist/files/${audioMessageId}`);
fs.unlinkSync((req as RequestFileHandlerInterface).file.path);
return res.status(OK).send({
id: audioMessageId,