|
@@ -3,7 +3,8 @@ const UserModel = require('../model/user');
|
|
|
const MessageModel = require('../model/message');
|
|
|
const fs = require('fs').promises;
|
|
|
const path = require('path');
|
|
|
-const DIR_STATIC = process.env.DIR_STATIC;
|
|
|
+const s3 = require('../helpers/aws');
|
|
|
+const AWS_BUCKET_NAME = process.env.AWS_BUCKET_NAME;
|
|
|
require('dotenv').config();
|
|
|
|
|
|
const listChats = async (req, res, next) => {
|
|
@@ -114,7 +115,15 @@ const removeChatForBoth = async (req, res, next) => {
|
|
|
const isCompanionChat = await ChatModel.getByField(userId, companionId);
|
|
|
if (isUserChat && isCompanionChat) {
|
|
|
const deleteFile = async (type, message) => {
|
|
|
- if (type !== 'text') await fs.unlink(path.join(DIR_STATIC, message));
|
|
|
+ if (type !== 'text') {
|
|
|
+ const params = {
|
|
|
+ Bucket: AWS_BUCKET_NAME,
|
|
|
+ Key: `${message}`,
|
|
|
+ };
|
|
|
+ s3.deleteObject(params, async function (err, _data) {
|
|
|
+ if (err) throw err;
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
const { messages } = await MessageModel.getList(
|
|
|
{ owner: userId, companionId },
|