|
@@ -3,6 +3,7 @@ const UserModel = require('../model/user');
|
|
|
const MessageModel = require('../model/message');
|
|
|
const fs = require('fs').promises;
|
|
|
const path = require('path');
|
|
|
+const DIR_FILES = process.env.DIR_FILES;
|
|
|
require('dotenv').config();
|
|
|
|
|
|
const listChats = async (req, res, next) => {
|
|
@@ -126,30 +127,11 @@ const removeChatForBoth = async (req, res, next) => {
|
|
|
try {
|
|
|
const companionId = req.params.id;
|
|
|
const userId = req.user.id;
|
|
|
- const DIR_IMAGES = process.env.DIR_IMAGES;
|
|
|
- const DIR_AUDIOS = process.env.DIR_AUDIOS;
|
|
|
- const DIR_VIDEOS = process.env.DIR_VIDEOS;
|
|
|
- const DIR_FILES = process.env.DIR_FILES;
|
|
|
const isUserChat = await ChatModel.getByField(companionId, userId);
|
|
|
const isCompanionChat = await ChatModel.getByField(userId, companionId);
|
|
|
if (isUserChat && isCompanionChat) {
|
|
|
const deleteFile = async (type, message) => {
|
|
|
- if (type !== 'text') {
|
|
|
- switch (type) {
|
|
|
- case 'image':
|
|
|
- await fs.unlink(path.join(DIR_IMAGES, message));
|
|
|
- break;
|
|
|
- case 'audio':
|
|
|
- await fs.unlink(path.join(DIR_AUDIOS, message));
|
|
|
- break;
|
|
|
- case 'video':
|
|
|
- await fs.unlink(path.join(DIR_VIDEOS, message));
|
|
|
- break;
|
|
|
- default:
|
|
|
- await fs.unlink(path.join(DIR_FILES, message));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (type !== 'text') await fs.unlink(path.join(DIR_FILES, message));
|
|
|
};
|
|
|
const { messages } = await MessageModel.getList(
|
|
|
{ owner: userId, companionId },
|