|
@@ -249,6 +249,18 @@ const fileMessage = async (req, res, next) => {
|
|
|
const DIR_FILES = process.env.DIR_FILES;
|
|
|
const pathToFile = req.file.path;
|
|
|
const newNameFile = req.file.originalname;
|
|
|
+ let type;
|
|
|
+ switch (req.file.mimetype) {
|
|
|
+ case 'application/pdf':
|
|
|
+ type = 'pdf';
|
|
|
+ break;
|
|
|
+ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
|
|
+ type = 'docx';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ console.log(req.file, req.file.mimetype);
|
|
|
await createFolderIsExist(path.join(DIR_FILES, userId));
|
|
|
await fs.rename(pathToFile, path.join(DIR_FILES, userId, newNameFile));
|
|
|
const fileUrl = path.normalize(path.join(userId, newNameFile));
|
|
@@ -261,7 +273,7 @@ const fileMessage = async (req, res, next) => {
|
|
|
avatarUrl,
|
|
|
color,
|
|
|
number,
|
|
|
- type: 'file',
|
|
|
+ type,
|
|
|
companionId: id,
|
|
|
owner: userId,
|
|
|
});
|
|
@@ -272,7 +284,7 @@ const fileMessage = async (req, res, next) => {
|
|
|
avatarUrl,
|
|
|
color,
|
|
|
number,
|
|
|
- type: 'file',
|
|
|
+ type,
|
|
|
companionId: userId,
|
|
|
owner: id,
|
|
|
});
|