|
@@ -4,7 +4,7 @@ const ChatModel = require('../model/chat');
|
|
|
const fs = require('fs').promises;
|
|
|
const path = require('path');
|
|
|
const createFolderIsExist = require('../helpers/create-directory');
|
|
|
-const DIR_FILES = process.env.DIR_FILES;
|
|
|
+const DIR_STATIC = process.env.DIR_STATIC;
|
|
|
require('dotenv').config();
|
|
|
|
|
|
const listMessages = async (req, res, next) => {
|
|
@@ -32,7 +32,7 @@ const removeMessage = async (req, res, next) => {
|
|
|
userMessage.companionId
|
|
|
);
|
|
|
if (userMessage.type !== 'text')
|
|
|
- await fs.unlink(path.join(DIR_FILES, userMessage.message));
|
|
|
+ await fs.unlink(path.join(DIR_STATIC, userMessage.message));
|
|
|
|
|
|
const isChat = await ChatModel.getByField(userMessage.companionId, userId);
|
|
|
const isCompanionChat = await ChatModel.getByField(
|
|
@@ -165,8 +165,8 @@ const imageMessage = async (req, res, next) => {
|
|
|
const pathToFile = req.file.path;
|
|
|
const newNameImg = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
- await createFolderIsExist(path.join(DIR_FILES, userId));
|
|
|
- await fs.rename(pathToFile, path.join(DIR_FILES, userId, newNameImg));
|
|
|
+ await createFolderIsExist(path.join(DIR_STATIC, userId));
|
|
|
+ await fs.rename(pathToFile, path.join(DIR_STATIC, userId, newNameImg));
|
|
|
const imgUrl = path.normalize(path.join(userId, newNameImg));
|
|
|
if (isChat && isCompanionChat && imgUrl) {
|
|
|
const { name, lastName, avatarUrl, color, number } = req.user;
|
|
@@ -240,8 +240,8 @@ const audioMessage = async (req, res, next) => {
|
|
|
const pathToFile = req.file.path;
|
|
|
const newNameAudio = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
- await createFolderIsExist(path.join(DIR_FILES, userId));
|
|
|
- await fs.rename(pathToFile, path.join(DIR_FILES, userId, newNameAudio));
|
|
|
+ await createFolderIsExist(path.join(DIR_STATIC, userId));
|
|
|
+ await fs.rename(pathToFile, path.join(DIR_STATIC, userId, newNameAudio));
|
|
|
const audioUrl = path.normalize(path.join(userId, newNameAudio));
|
|
|
if (isChat && isCompanionChat && audioUrl) {
|
|
|
const { name, lastName, avatarUrl, color, number } = req.user;
|
|
@@ -315,8 +315,8 @@ const videoMessage = async (req, res, next) => {
|
|
|
const pathToFile = req.file.path;
|
|
|
const newNameVideo = `${Math.round(Date.now() / 1000)}${originalName}`;
|
|
|
const fullType = req.file.mimetype;
|
|
|
- await createFolderIsExist(path.join(DIR_FILES, userId));
|
|
|
- await fs.rename(pathToFile, path.join(DIR_FILES, userId, newNameVideo));
|
|
|
+ await createFolderIsExist(path.join(DIR_STATIC, userId));
|
|
|
+ await fs.rename(pathToFile, path.join(DIR_STATIC, userId, newNameVideo));
|
|
|
const videoUrl = path.normalize(path.join(userId, newNameVideo));
|
|
|
if (isChat && isCompanionChat && videoUrl) {
|
|
|
const { name, lastName, avatarUrl, color, number } = req.user;
|
|
@@ -404,8 +404,8 @@ const fileMessage = async (req, res, next) => {
|
|
|
break;
|
|
|
}
|
|
|
const newNameFile = `${Math.round(Date.now() / 1000)}file.${type}`;
|
|
|
- await createFolderIsExist(path.join(DIR_FILES, userId));
|
|
|
- await fs.rename(pathToFile, path.join(DIR_FILES, userId, newNameFile));
|
|
|
+ await createFolderIsExist(path.join(DIR_STATIC, userId));
|
|
|
+ await fs.rename(pathToFile, path.join(DIR_STATIC, userId, newNameFile));
|
|
|
const fileUrl = path.normalize(path.join(userId, newNameFile));
|
|
|
if (isChat && isCompanionChat && fileUrl) {
|
|
|
const { name, lastName, avatarUrl, color, number } = req.user;
|