|
@@ -1,7 +1,6 @@
|
|
|
const MessageModel = require('../model/message');
|
|
|
const UserModel = require('../model/user');
|
|
|
const ChatModel = require('../model/chat');
|
|
|
-const Jimp = require('jimp');
|
|
|
const fs = require('fs').promises;
|
|
|
const path = require('path');
|
|
|
const createFolderIsExist = require('../helpers/create-directory');
|
|
@@ -183,7 +182,7 @@ const imageMessage = async (req, res, next) => {
|
|
|
const originalName = req.file.originalname;
|
|
|
const newNameImg = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
- await Jimp.read(pathToFile);
|
|
|
+ await fs.readFile(pathToFile);
|
|
|
await createFolderIsExist(path.join(DIR_IMAGES, userId));
|
|
|
await fs.rename(pathToFile, path.join(DIR_IMAGES, userId, newNameImg));
|
|
|
const imgUrl = path.normalize(path.join(userId, newNameImg));
|
|
@@ -260,6 +259,7 @@ const audioMessage = async (req, res, next) => {
|
|
|
const originalName = req.file.originalname;
|
|
|
const newNameAudio = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
+ await fs.readFile(pathToFile);
|
|
|
await createFolderIsExist(path.join(DIR_AUDIOS, userId));
|
|
|
await fs.rename(pathToFile, path.join(DIR_AUDIOS, userId, newNameAudio));
|
|
|
const audioUrl = path.normalize(path.join(userId, newNameAudio));
|
|
@@ -336,6 +336,7 @@ const videoMessage = async (req, res, next) => {
|
|
|
const originalName = req.file.originalname;
|
|
|
const newNameVideo = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
+ await fs.readFile(pathToFile);
|
|
|
await createFolderIsExist(path.join(DIR_VIDEOS, userId));
|
|
|
await fs.rename(pathToFile, path.join(DIR_VIDEOS, userId, newNameVideo));
|
|
|
const videoUrl = path.normalize(path.join(userId, newNameVideo));
|
|
@@ -425,6 +426,7 @@ const fileMessage = async (req, res, next) => {
|
|
|
break;
|
|
|
}
|
|
|
const newNameFile = `${Math.round(Date.now() / 1000)}file.${type}`;
|
|
|
+ await fs.readFile(pathToFile);
|
|
|
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));
|