unknown 2 سال پیش
والد
کامیت
16aa7d7366

BIN
audios/6270fce097abc354984962b7/1651573761audio.mp3


BIN
audios/6270fce097abc354984962b7/1651574224audio.mp3


+ 7 - 5
controllers/messages.js

@@ -1,6 +1,7 @@
 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');
@@ -182,7 +183,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 fs.readFile(pathToFile);
+		await Jimp.read(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));
@@ -255,13 +256,16 @@ const audioMessage = async (req, res, next) => {
 		const isChat = await ChatModel.getByField(id, userId);
 		const isCompanionChat = await ChatModel.getByField(userId, id);
 		const DIR_AUDIOS = process.env.DIR_AUDIOS;
+		const DIR_UPLOAD = process.env.DIR_UPLOAD;
 		const pathToFile = req.file.path;
 		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));
+		await fs.rename(
+			path.join(DIR_UPLOAD, originalName),
+			path.join(DIR_AUDIOS, userId, newNameAudio)
+		);
 		const audioUrl = path.normalize(path.join(userId, newNameAudio));
 		if (isChat && isCompanionChat && audioUrl) {
 			const { name, lastName, avatarUrl, color, number } = req.user;
@@ -336,7 +340,6 @@ 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));
@@ -426,7 +429,6 @@ 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));

BIN
images/6270fce097abc354984962b7/1651571961we.jpg


BIN
images/6270fce097abc354984962b7/1651572744we.jpg


BIN
images/6270fe363c9767458820d73d/1651572289monkey.png


BIN
images/6270ff7f3c9767458820d741/1651572627we.jpg