Answer the question
In order to leave comments, you need to log in
Why is a function in node executed multiple times?
Good afternoon!
I am writing a node callback service that receives photos in the dialog, takes their link and sends it to the mysql database.
Faced such a problem that with some periodicity, the service sends links to the database several times.
What could be the problem?
const easyvk = require('easyvk');
const express = require('express');
const bodyParser = require('body-parser');
const api = require('vk-easy');
const send = require('./send');
const { PORT, CONFIRMATION, TOKEN } = require('./config');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const proc = require('./messageProceed')
app.get('/renaissance/api', (req, res) => res.send('Hello World!'));
app.post('/renaissance/api', (req, res) => {
const { body } = req;
switch (body.type) {
case 'confirmation':
res.end(CONFIRMATION);
break;
default:
return proc(body.object);
break;
}
});
const send = require('./send.js');
const photoAPI = require('./actions/photo.js');
module.exports = async function( {from_id: userId, text, attachments: files, payload} ) {
if (files != null) {
for (i = 0; i < files.length; i++) {
//send(userId, 'Getting object...');
if (files[i].type == 'photo') {
photoAPI(files[i]);
}
}
}
return;
};
const easyVK = require('easyvk');
const send = require('../send');
const api = require('vk-easy');
const mysql = require('mysql');
module.exports = function ({ photo: item }) {
// на стиль решения не обращайте внимания, пока что я просто тестирую эти методы
if (item.photo_2560 != null) return client.query('INSERT INTO testtab (test, field, number) VALUES ("node",\"'+ item.photo_2560 +'\", 322)');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question