-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
146 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
PORT=1800 | ||
PORT=1900 | ||
DDOSSTATUS=0 | ||
DDOSINTENTOS=3 | ||
DDOSTIMOUT=600000 | ||
DDOSINTENTOS=10 | ||
DDOSTIMOUT=10000 # 86400000 es un dia |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,93 @@ | ||
const mysql = require("mysql2"); | ||
const mysqlSy = require('sync-mysql') | ||
const dbconect = require("../db/datastores.json").datastore | ||
const mysql = require('mysql2/promise'); | ||
|
||
function executeSQL(database, sql) { | ||
let dataconnection; | ||
const selectedDB = dbconect.find(item => item.name === database); | ||
async function executeSQLS(database, sql) { | ||
try { | ||
const selectedDB = dbconect.find(item => item.name === database); | ||
|
||
if (!selectedDB) { | ||
log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); | ||
return { status: 0 }; | ||
} | ||
|
||
if (selectedDB) { | ||
dataconnection = mysql.createConnection({ | ||
const pool = mysql.createPool({ | ||
connectionLimit: selectedDB.conn.connectionLimit, | ||
host: selectedDB.conn.server, | ||
user: selectedDB.conn.user, | ||
password: selectedDB.conn.password, | ||
connectTimeout: selectedDB.conn.connectTimeout, | ||
database: selectedDB.conn.database, | ||
multipleStatements: true | ||
waitForConnections: true, | ||
queueLimit: 0 | ||
}); | ||
} else { | ||
log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); | ||
return Promise.resolve({ status: 0 }); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
try { | ||
dataconnection.query(sql, (error, results) => { | ||
if (error) { | ||
log("error", `Existe un error en la consulta :: ${error}`, "SQL"); | ||
resolve({ status: 0 }); | ||
} | ||
resolve(results); | ||
}); | ||
} catch (error) { | ||
log("error", `Existe un error en la consulta :: ${error}`, "SQL"); | ||
resolve({ status: 0 }); | ||
} | ||
}); | ||
} | ||
|
||
function executeSQLS (database, sql) { | ||
try{ | ||
|
||
let connection; | ||
let response; | ||
|
||
const selectedDB = dbconect.find(item => item.name === database); | ||
const [rows, fields] = await pool.execute(sql); | ||
|
||
if (selectedDB) { | ||
await pool.end(); | ||
|
||
connection = new mysqlSy({ | ||
host: selectedDB.conn.server, | ||
user: selectedDB.conn.user, | ||
password: selectedDB.conn.password, | ||
connectTimeout: selectedDB.conn.connectTimeout, | ||
database: selectedDB.conn.database | ||
}); | ||
return rows; | ||
} catch (error) { | ||
log("error", `Existe un error en la consulta :: ${error}`, "SQL"); | ||
|
||
if (error.code === 'PROTOCOL_CONNECTION_LOST') { | ||
// Si la conexión se pierde, se vuelve a intentar una vez | ||
log("warning", `Se perdió la conexión con la base de datos. Reintentando la consulta...`, "SQL"); | ||
return executeSQLS(database, sql); | ||
} else if (error.code === 'POOL_ENQUEUELIMIT') { | ||
// Si se alcanza el límite de la pool, se muestra una advertencia y se espera antes de reintentar | ||
log("warning", `Se alcanzó el límite de conexiones permitido. Esperando antes de reintentar...`, "SQL"); | ||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
return executeSQLS(database, sql); | ||
} else { | ||
// Cualquier otro error se maneja como una falla | ||
return { status: 0 }; | ||
} | ||
} | ||
} | ||
|
||
async function executeSQL(database, sql, values) { | ||
try { | ||
const selectedDB = dbconect.find(item => item.name === database); | ||
|
||
if (!selectedDB) { | ||
log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); | ||
return { status: 0 }; | ||
|
||
} | ||
|
||
response = connection.query(sql) | ||
connection.finishAll() | ||
const pool = mysql.createPool({ | ||
connectionLimit: selectedDB.conn.connectionLimit, | ||
host: selectedDB.conn.server, | ||
user: selectedDB.conn.user, | ||
password: selectedDB.conn.password, | ||
database: selectedDB.conn.database, | ||
waitForConnections: true, | ||
queueLimit: 0 | ||
}); | ||
|
||
const [rows, fields] = await pool.execute(sql, values); | ||
|
||
return response; | ||
await pool.end(); | ||
|
||
return rows; | ||
} catch (error) { | ||
log("error", `Existe un error en la consulta :: ${error}`, "SQL") | ||
return { status: 0 }; | ||
log("error", `Existe un error en la consulta :: ${error}`, "SQL"); | ||
|
||
if (error.code === 'PROTOCOL_CONNECTION_LOST') { | ||
// Si la conexión se pierde, se vuelve a intentar una vez | ||
log("warning", `Se perdió la conexión con la base de datos. Reintentando la consulta...`, "SQL"); | ||
return executeSQLS(database, sql, values); | ||
} else if (error.code === 'POOL_ENQUEUELIMIT') { | ||
// Si se alcanza el límite de la pool, se muestra una advertencia y se espera antes de reintentar | ||
log("warning", `Se alcanzó el límite de conexiones permitido. Esperando antes de reintentar...`, "SQL"); | ||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
return executeSQLS(database, sql, values); | ||
} else { | ||
// Cualquier otro error se maneja como una falla | ||
return { status: 0 }; | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
executeSQL, | ||
executeSQLS | ||
}; | ||
|
||
exports.executeSQLS = executeSQLS; | ||
|
||
exports.executeSQL = executeSQL |
Oops, something went wrong.