improvement: better media filename handle

This commit is contained in:
canove
2020-08-04 10:07:03 -03:00
parent c0817e99d1
commit 7a99abe543
3 changed files with 8 additions and 8 deletions

View File

@@ -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);
});

View File

@@ -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 {

View File

@@ -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 });