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