2018-12-13 01:10:51 +00:00
|
|
|
class GestorDeTareas {
|
|
|
|
tareas: boolean[] = [];
|
|
|
|
alCompletar: (() => void);
|
|
|
|
|
|
|
|
constructor(alCompletar: (() => void)) {
|
|
|
|
this.alCompletar = alCompletar;
|
|
|
|
}
|
|
|
|
|
|
|
|
agregarTarea() {
|
|
|
|
return (this.tareas.push(false) - 1);
|
|
|
|
}
|
|
|
|
|
2018-12-17 14:35:07 +00:00
|
|
|
terminarTarea() {
|
|
|
|
this.tareas.pop();
|
2018-12-13 01:10:51 +00:00
|
|
|
this.verificarTareas();
|
|
|
|
}
|
|
|
|
|
|
|
|
verificarTareas() {
|
2018-12-17 14:35:07 +00:00
|
|
|
if (this.tareas.length === 0)
|
|
|
|
this.alCompletar();
|
2018-12-13 01:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const YAML = require('yaml');
|
|
|
|
|
|
|
|
interface links {
|
|
|
|
links_ID: number,
|
|
|
|
anime_ID: number,
|
|
|
|
aviso: string,
|
|
|
|
sigEp: string
|
|
|
|
}
|
|
|
|
interface links_opciones {
|
|
|
|
opcion_ID: number,
|
|
|
|
links_ID: number,
|
|
|
|
num_opcion: number,
|
|
|
|
formato: string,
|
|
|
|
res: string,
|
|
|
|
servidor: string,
|
|
|
|
color: string
|
|
|
|
}
|
|
|
|
interface eps {
|
|
|
|
ep_ID: number,
|
|
|
|
opcion_ID: number,
|
|
|
|
num_ep: number,
|
|
|
|
visitas: number,
|
|
|
|
link: string,
|
|
|
|
peso: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface LinksEps {
|
|
|
|
ep_ID: number,
|
|
|
|
visitas: number,
|
|
|
|
peso: string,
|
|
|
|
link: string
|
|
|
|
}
|
|
|
|
interface Links {
|
|
|
|
aviso: string,
|
|
|
|
sigEp: string
|
|
|
|
opciones: {
|
|
|
|
[num: number]: {
|
|
|
|
formato: string,
|
|
|
|
res: string,
|
|
|
|
servidor: string,
|
|
|
|
color: string,
|
|
|
|
eps: {
|
|
|
|
[num: number]: LinksEps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 21:52:25 +00:00
|
|
|
const obtenerLinks = (req: any, res: any) => {
|
|
|
|
|
|
|
|
const con = require('../mysql').obtenerConexionMySql();
|
2018-12-13 01:10:51 +00:00
|
|
|
const animeID = req.body.animeID;
|
2018-11-20 21:52:25 +00:00
|
|
|
|
|
|
|
con.connect((err: any) => {
|
2018-12-13 01:10:51 +00:00
|
|
|
if (!err && animeID !== undefined) {
|
|
|
|
|
|
|
|
const data: Links = {aviso: '', sigEp: '', opciones: {}};
|
|
|
|
|
2018-11-20 21:52:25 +00:00
|
|
|
con.query(
|
2018-12-13 01:10:51 +00:00
|
|
|
`SELECT * FROM links WHERE anime_ID=${animeID} `,
|
|
|
|
(err: Error, response: links[]) => {
|
2018-11-20 21:52:25 +00:00
|
|
|
if (!err && response[0] ) {
|
|
|
|
|
2018-12-13 01:10:51 +00:00
|
|
|
const subData: links = response[0];
|
|
|
|
data.aviso = subData.aviso;
|
|
|
|
data.sigEp = subData.sigEp;
|
|
|
|
|
2018-11-20 21:52:25 +00:00
|
|
|
|
2018-12-13 01:10:51 +00:00
|
|
|
const gestorOpciones = new GestorDeTareas(() => {
|
|
|
|
res.send(YAML.stringify(data));
|
|
|
|
});
|
|
|
|
|
|
|
|
con.query(
|
|
|
|
`SELECT * FROM links_opciones WHERE links_ID=${subData.links_ID}`,
|
|
|
|
(err: Error, response: links_opciones[]) => {
|
|
|
|
if (!err && response[0]) {
|
|
|
|
|
|
|
|
for (const opcionID in response) {
|
|
|
|
const opcion = response[opcionID];
|
|
|
|
|
2018-12-17 14:35:07 +00:00
|
|
|
gestorOpciones.agregarTarea();
|
2018-12-13 01:10:51 +00:00
|
|
|
|
|
|
|
data.opciones[opcion.num_opcion] = {
|
|
|
|
formato: opcion.formato,
|
|
|
|
res: opcion.res,
|
|
|
|
servidor: opcion.servidor,
|
|
|
|
color: opcion.color,
|
|
|
|
eps: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
con.query(
|
|
|
|
`SELECT * FROM eps WHERE opcion_ID=${opcion.opcion_ID}`,
|
|
|
|
(err: Error, response: eps[]) => {
|
|
|
|
if (!err && response[0]) {
|
|
|
|
|
|
|
|
for (const epID in response) {
|
|
|
|
const ep = response[epID];
|
|
|
|
|
2018-12-17 14:35:07 +00:00
|
|
|
data.opciones[opcion.num_opcion].eps[ep.num_ep] = {
|
2018-12-13 01:10:51 +00:00
|
|
|
ep_ID: ep.ep_ID,
|
|
|
|
visitas: ep.visitas,
|
|
|
|
peso: ep.peso,
|
|
|
|
link: ep.link
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-17 14:35:07 +00:00
|
|
|
gestorOpciones.terminarTarea();
|
2018-12-13 01:10:51 +00:00
|
|
|
} else if (!err) {
|
|
|
|
console.log("No existen episodios para esta variante");
|
|
|
|
|
|
|
|
res.send(`{ "exito": false }`);
|
|
|
|
} else {
|
|
|
|
console.log("Error al obtener eps:\n" + err);
|
|
|
|
res.send(`{ "exito": false }`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (!err) {
|
|
|
|
console.log("No existen links_opciones ");
|
|
|
|
res.send(`{ "exito": false }`);
|
|
|
|
} else {
|
|
|
|
console.log("Error al obtener links opciones:\n" + err);
|
|
|
|
res.send(`{ "exito": false }`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-11-20 21:52:25 +00:00
|
|
|
|
2018-11-21 17:58:16 +00:00
|
|
|
} else if (!err) {
|
|
|
|
console.log("Error: La consulta no dio ningun resultado en obtenerLinks");
|
2018-12-13 02:30:11 +00:00
|
|
|
res.send('{ "exito": false }');
|
2018-11-20 21:52:25 +00:00
|
|
|
} else {
|
2018-11-21 17:58:16 +00:00
|
|
|
console.log("Error al ejecutar Query en obtenerLinks.\n" + err);
|
2018-12-13 02:30:11 +00:00
|
|
|
res.send('{ "exito": false }');
|
2018-11-20 21:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-12-13 01:10:51 +00:00
|
|
|
|
2018-11-20 21:52:25 +00:00
|
|
|
} else {
|
|
|
|
console.log("Hubo un error al conectarse a la base de datos :c");
|
|
|
|
res.send(`{ "exito": false }`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.obtenerLinks = obtenerLinks;
|