generated from lucien/api-template
add: added image attachments to messages
This commit is contained in:
parent
8f77a271e1
commit
fb90f1ef4f
10 changed files with 169 additions and 10 deletions
|
@ -8,11 +8,14 @@ const {
|
|||
getMentions,
|
||||
getUserByUsername,
|
||||
addReply,
|
||||
getMessageReplies
|
||||
getMessageReplies,
|
||||
getUnusedAttachments,
|
||||
deleteUnusedAttachments
|
||||
} = require('../libs/mysql');
|
||||
const rateLimit = require("express-rate-limit");
|
||||
const slowDown = require("express-slow-down");
|
||||
const { checkAuth } = require('../libs/middlewares');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const limiter = rateLimit({
|
||||
windowMs: 1 * 1000,
|
||||
|
@ -132,6 +135,15 @@ router.post('/:message_id/delete', checkAuth, async (req, res) => {
|
|||
}
|
||||
|
||||
await deleteMessage(connection, message_id);
|
||||
|
||||
const attachments = await getUnusedAttachments(connection);
|
||||
for (const attachment of attachments) {
|
||||
if (fs.existsSync(`data/attachments/${attachment.file_name}`)) {
|
||||
fs.unlinkSync(`data/attachments/${attachment.file_name}`);
|
||||
}
|
||||
}
|
||||
await deleteUnusedAttachments(connection);
|
||||
|
||||
connection.end();
|
||||
|
||||
req.sockets.emit({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue