mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
improvement: better media filename handle
This commit is contained in:
@@ -17,12 +17,13 @@ const TicketsRoutes = require("./routes/tickets");
|
||||
const WhatsRoutes = require("./routes/whatsapp");
|
||||
|
||||
const app = express();
|
||||
|
||||
const fileStorage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, path.resolve(__dirname, "..", "public"));
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
cb(null, new Date().getTime() + "-" + file.originalname.replace(/\s/g, ""));
|
||||
cb(null, new Date().getTime() + path.extname(file.originalname));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -55,7 +56,7 @@ const io = require("./libs/socket").init(server);
|
||||
io.on("connection", socket => {
|
||||
console.log("Client Connected");
|
||||
socket.on("joinChatBox", ticketId => {
|
||||
console.log("A client joined in a ticket channel");
|
||||
console.log("A client joined a ticket channel");
|
||||
socket.join(ticketId);
|
||||
});
|
||||
|
||||
|
||||
@@ -110,9 +110,10 @@ exports.store = async (req, res, next) => {
|
||||
});
|
||||
|
||||
if (media) {
|
||||
console.log(media);
|
||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||
|
||||
message.mediaUrl = req.file.filename.replace(/\s/g, "");
|
||||
message.mediaUrl = req.file.filename;
|
||||
if (newMedia.mimetype) {
|
||||
message.mediaType = newMedia.mimetype.split("/")[0];
|
||||
} else {
|
||||
|
||||
@@ -161,11 +161,9 @@ const wbotMessageListener = () => {
|
||||
where: { id: msg.id.id },
|
||||
});
|
||||
if (!messageToUpdate) {
|
||||
// will throw an error in frist ack if msg wast sent from cellphone
|
||||
const error = new Error(
|
||||
"Erro ao alterar o ack da mensagem no banco de dados"
|
||||
);
|
||||
error.statusCode = 501;
|
||||
// will throw an error if msg was sent from cellphone
|
||||
const error = new Error("No message with this ID found in database");
|
||||
error.statusCode = 404;
|
||||
throw error;
|
||||
}
|
||||
await messageToUpdate.update({ ack: ack });
|
||||
|
||||
Reference in New Issue
Block a user