Compare commits

..

2 Commits

Author SHA1 Message Date
28d20f7aca Use sqlite, ts modules 2024-02-29 08:15:31 -05:00
c74fac62dd Use Bun. Use hash mode in router 2024-02-28 20:21:49 -05:00
22 changed files with 184 additions and 1636 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
shamefully-hoist=true

BIN
bun.lockb Executable file

Binary file not shown.

View File

@ -9,20 +9,27 @@
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"sass": "^1.71.1",
"vue": "^2.7.7",
"vue-router": "^3.5.4",
"connect-history-api-fallback": "^1.6.0",
"express": "^4.18.2",
"mysql": "^2.18.1",
"mysql2": "^2.2.0",
"yaml": "^2.4.0"
},
"devDependencies": {
"@types/bun": "^1.0.8",
"@types/express": "^4.17.20",
"@types/mysql": "^2.15.23",
"@types/node": "^16.11.45",
"@vitejs/plugin-legacy": "^2.0.0",
"@vitejs/plugin-vue2": "^1.1.2",
"@vue/tsconfig": "^0.1.3",
"npm-run-all": "^4.1.5",
"sass": "^1.71.1",
"terser": "^5.14.2",
"typescript": "~4.7.4",
"vite": "^3.0.2",
"vue": "^2.7.7",
"vue-router": "^3.5.4",
"vue-tsc": "^0.38.8"
}
}

File diff suppressed because it is too large Load Diff

BIN
pseudosubs.sqlite Normal file

Binary file not shown.

View File

@ -9,7 +9,7 @@ import AnimeView from './views/AnimeView.vue'
Vue.use(Router);
const rutas = {
mode: 'history',
mode: 'hash',
base: "/",
routes: [
{

View File

@ -1,3 +1,5 @@
import {sqliteConnection as con} from "../../index";
interface Data {
anime_ID: number,
num_ED: number,
@ -6,17 +8,16 @@ interface Data {
eps: string
}
const nuevoED = (req: any, res: any) => {
export const nuevoED = (req: any, res: any) => {
const YAML = require('yaml');
const data: Data = YAML.parse(req.body.data);
const con = require('../../index').conexionMySQL;
if (data) {
const query = `INSERT INTO ED (anime_ID, num_ED, nombre, artista, eps) VALUES ( ${data.anime_ID}, ${data.num_ED},
${con.escape(data.nombre)}, ${con.escape(data.artista)}, ${con.escape(data.eps)} )`;
con.query(query, (err: Error) => {
con.query(query, (err) => {
if (!err) {
res.send("exito: true");
} else {
@ -31,5 +32,3 @@ const nuevoED = (req: any, res: any) => {
}
};
module.exports.nuevoED = nuevoED;

View File

@ -1,3 +1,5 @@
import {sqliteConnection as con} from "../../index";
interface RespuestaED {
ED_ID: number,
anime_ID: number,
@ -7,17 +9,16 @@ interface RespuestaED {
eps: string
}
const obtenerEDs = (req: any, res: any) => {
export const obtenerEDs = (req: any, res: any) => {
const YAML = require('yaml');
const anime_ID: number = req.params.anime_ID;
const con = require('../../index').conexionMySQL;
if (anime_ID) {
const query = `SELECT * FROM ED WHERE anime_ID=${anime_ID}`;
con.query(query, (err: Error, response: RespuestaED[]) => {
con.query(query, (err, response: RespuestaED[]) => {
if (!err) {
res.send(YAML.stringify(response));
@ -34,5 +35,3 @@ const obtenerEDs = (req: any, res: any) => {
}
};
module.exports.obtenerEDs = obtenerEDs;

View File

@ -1,3 +1,5 @@
import {sqliteConnection as con} from "../../index";
interface formatoDataARecibir {
opcion_ID: number,
num_ep: number,
@ -6,9 +8,8 @@ interface formatoDataARecibir {
peso: string
}
const crearLink = (req: any, res: any) => {
export const crearLink = (req: any, res: any) => {
const con = require('../../index').conexionMySQL;
const YAML = require('yaml');
const parametros: formatoDataARecibir = YAML.parse(req.body.params);
@ -18,7 +19,7 @@ const crearLink = (req: any, res: any) => {
const query = `INSERT INTO eps (opcion_ID, num_ep, visitas, link, peso) VALUES (${parametros.opcion_ID},
${parametros.num_ep}, ${parametros.visitas}, ${con.escape(parametros.link)}, ${con.escape(parametros.peso)} )`;
con.query(query, (err: Error) => {
con.query(query, (err) => {
if (!err) {
res.send("error: false");
@ -35,5 +36,3 @@ const crearLink = (req: any, res: any) => {
}
};
module.exports.crearLink = crearLink;

View File

@ -1,16 +1,17 @@
import {Connection, MysqlError} from "mysql";
import * as core from "express-serve-static-core";
import {sqliteConnection as con} from "../../index";
const con: Connection = require('../../index').conexionMySQL;
const YAML = require('yaml');
interface respuesta {
peso: string
}
const estadisticas = (req: core.Request, res: core.Response) => {
export const estadisticas = (req: core.Request, res: core.Response) => {
con.query(`SELECT peso FROM eps`,(err: MysqlError, respuestas: respuesta[]) => {
con.query(`SELECT peso FROM eps`,(err, respuestas: respuesta[]) => {
if (!err) {
let totalMB = 0;
@ -30,5 +31,3 @@ const estadisticas = (req: core.Request, res: core.Response) => {
});
};
module.exports.estadisticas = estadisticas;

View File

@ -1,3 +1,5 @@
import {sqliteConnection as con} from "../../index";
interface epsRespuesta {
ep_ID: number,
opcion_ID: number,
@ -7,9 +9,8 @@ interface epsRespuesta {
peso: string
}
const obtenerLinks = (req: any, res: any) => {
export const obtenerLinks = (req: any, res: any) => {
const con = require('../../index').conexionMySQL;
const YAML = require('yaml');
const opcion_ID = req.params.opcion_ID;
@ -17,7 +18,7 @@ const obtenerLinks = (req: any, res: any) => {
if (opcion_ID) {
const query = `SELECT * FROM eps WHERE opcion_ID=${opcion_ID}`;
con.query(query, (err: Error, response: epsRespuesta[]) => {
con.query(query, (err, response: epsRespuesta[]) => {
if (!err) {
res.send(YAML.stringify(response));
@ -34,5 +35,3 @@ const obtenerLinks = (req: any, res: any) => {
}
};
module.exports.obtenerLinks = obtenerLinks;

View File

@ -1,3 +1,5 @@
import {sqliteConnection as con} from "../../index";
interface respuestaLinks {
opcion_ID: number,
links_ID: number,
@ -8,9 +10,8 @@ interface respuestaLinks {
color: string
}
const obtenerVariantes = (req: any, res: any) => {
export const obtenerVariantes = (req: any, res: any) => {
const con = require('../../index').conexionMySQL;
const YAML = require('yaml');
const anime_ID: string = req.params.anime_ID;
@ -19,7 +20,7 @@ const obtenerVariantes = (req: any, res: any) => {
const query = `SELECT * FROM links_opciones WHERE links_ID=(SELECT links_ID FROM links WHERE anime_ID=${anime_ID})`;
con.query (query, (err: Error, response: respuestaLinks[]) => {
con.query (query, (err, response: respuestaLinks[]) => {
if (!err) {
res.send(YAML.stringify(response));
@ -36,5 +37,3 @@ const obtenerVariantes = (req: any, res: any) => {
}
};
module.exports.obtenerVariantes = obtenerVariantes;

View File

@ -1,6 +1,7 @@
const nuevoOP = (req: any, res: any) => {
import {sqliteConnection as con} from "../../index";
export const nuevoOP = (req: any, res: any) => {
const con = require('../../index').conexionMySQL;
const YAML = require('yaml');
const data = YAML.parse(req.body.data);
@ -21,5 +22,3 @@ const nuevoOP = (req: any, res: any) => {
);
};
module.exports.nuevoOP = nuevoOP;

View File

@ -1,6 +1,7 @@
const obtenerOPs = (req: any, res: any) => {
import {sqliteConnection as con} from "../../index";
export const obtenerOPs = (req: any, res: any) => {
const con = require('../../index').conexionMySQL;
const YAML = require('yaml');
const animeID: number = req.params.id;
@ -24,5 +25,3 @@ const obtenerOPs = (req: any, res: any) => {
res.send("error: true");
}
};
module.exports.obtenerOPs = obtenerOPs;

View File

@ -1,6 +1,7 @@
const crearAnime = (req: any, res: any) => {
import {sqliteConnection as con} from "../index";
export const crearAnime = (req: any, res: any) => {
const con = require('../index').conexionMySQL;
const YAML = require('yaml');
if (req.body.data) {
@ -28,5 +29,3 @@ const crearAnime = (req: any, res: any) => {
res.send("Error. El servidor no recibio ningun dato.");
}
};
module.exports.crearAnime = crearAnime;

View File

@ -1,6 +1,7 @@
const obtenerTodosAnimes = (req: any, res: any) => {
import {sqliteConnection as con} from "../index";
export const obtenerTodosAnimes = (req: any, res: any) => {
const con = require('../index').conexionMySQL;
const YAML = require('yaml');
con.query(
@ -18,5 +19,3 @@ const obtenerTodosAnimes = (req: any, res: any) => {
);
};
module.exports.obtenerTodosAnimes = obtenerTodosAnimes;

View File

@ -1,4 +1,6 @@
import {Connection} from "mysql";
import {sqliteConnection as con} from "../index";
interface RespuestaDatos {
estudio: string,
@ -39,8 +41,6 @@ const obtenerDatos = (req: any, res: any) => {
const anime_ID = req.params.anime_ID;
const con: Connection = require('../index').conexionMySQL;
const respuesta: any = {};
const gestor = new GestorDeTareas(() => {
console.log(YAML.stringify(respuesta));
@ -49,7 +49,7 @@ const obtenerDatos = (req: any, res: any) => {
const query1 = `SELECT estudio, eps, alAire, temporada, anio, fuente, generos FROM animes WHERE anime_ID=${anime_ID}`;
gestor.agregarTarea();
con.query(query1, (err: Error, res: RespuestaDatos[]) => {
con.query(query1, (err, res: RespuestaDatos[]) => {
if (!err) {
const data = res[0];
@ -72,7 +72,7 @@ const obtenerDatos = (req: any, res: any) => {
const query2 = `SELECT * FROM OP WHERE anime_ID=${anime_ID}`;
gestor.agregarTarea();
con.query(query2, (err: Error, res: RespuestaOP[]) => {
con.query(query2, (err, res: RespuestaOP[]) => {
if (!err) {
const ops: any = {};
@ -95,7 +95,7 @@ const obtenerDatos = (req: any, res: any) => {
const query3 = `SELECT * FROM ED WHERE anime_ID=${anime_ID}`;
gestor.agregarTarea();
con.query(query3, (err: Error, res: RespuestaED[]) => {
con.query(query3, (err, res: RespuestaED[]) => {
if (!err) {
const eds: any = {};

View File

@ -1,4 +1,4 @@
class GestorDeTareas {
export class GestorDeTareas {
tareas: boolean[] = [];
alCompletar: (() => void);
@ -20,5 +20,3 @@ class GestorDeTareas {
this.alCompletar();
}
}
module.exports.GestorDeTareas = GestorDeTareas;

View File

@ -1,12 +1,13 @@
const modificarLink = (req: any, res: any) => {
import {sqliteConnection as con} from "../index";
export const modificarLink = (req: any, res: any) => {
const ep_ID = req.body.ep_ID;
const con = require('../index').conexionMySQL;
con.query(
`UPDATE eps SET visitas=visitas+1 WHERE ep_ID=${ep_ID};`,
(err: Error) => {
(err) => {
if (!err) {
res.send("Actualizado con exito.");
} else {
@ -16,5 +17,3 @@ const modificarLink = (req: any, res: any) => {
);
};
module.exports.modificarLinks = modificarLink;

View File

@ -1,6 +1,6 @@
const GestorDeTareas = require("../GestorDeTareas/GestorDeTareas").GestorDeTareas;
const YAML = require('yaml');
import {GestorDeTareas} from "../GestorDeTareas/GestorDeTareas";
import {sqliteConnection as con} from "../index";
import YAML from 'yaml';
interface links {
links_ID: number,
@ -48,9 +48,8 @@ interface Links {
}
}
const obtenerLinks = (req: any, res: any) => {
export const obtenerLinks = (req: any, res: any) => {
const con = require('../index').conexionMySQL;
const animeID = req.body.animeID;
@ -60,7 +59,7 @@ const obtenerLinks = (req: any, res: any) => {
con.query(
`SELECT * FROM links WHERE anime_ID=${animeID} `,
(err: Error, response: links[]) => {
(err, response: links[]) => {
if (!err && response[0] ) {
const subData: links = response[0];
@ -74,7 +73,7 @@ const obtenerLinks = (req: any, res: any) => {
con.query(
`SELECT * FROM links_opciones WHERE links_ID=${subData.links_ID}`,
(err: Error, response: links_opciones[]) => {
(err, response: links_opciones[]) => {
if (!err && response[0]) {
for (const opcionID in response) {
@ -93,7 +92,7 @@ const obtenerLinks = (req: any, res: any) => {
con.query(
`SELECT * FROM eps WHERE opcion_ID=${opcion.opcion_ID}`,
(err: Error, response: eps[]) => {
(err, response: eps[]) => {
if (!err && response[0]) {
for (const epID in response) {
@ -148,5 +147,3 @@ const obtenerLinks = (req: any, res: any) => {
}
};
module.exports.obtenerLinks = obtenerLinks;

View File

@ -1,10 +1,28 @@
import express from 'express';
import * as core from "express-serve-static-core";
import mysql from "mysql2";
import {Database} from "bun:sqlite";
/*
import {obtenerLinks} from './LinksAnimes/obtenerLinks';
import {crearAnime} from './Admin/crearAnime';
import {obtenerTodosAnimes} from './Admin/obtenerTodosAnimes';
import {obtenerOPs} from './Admin/OP/obtenerOPs';
import {nuevoOP} from './Admin/OP/nuevoOP';
import {obtenerEDs} from './Admin/ED/obtenerEDs';
import {nuevoED} from './Admin/ED/nuevoED';
import {obtenerVariantes} from './Admin/Eps/obtenerVariantes';
import {obtenerLinks} from './Admin/Eps/obtenerLinks';
import {crearLink} from './Admin/Eps/crearLink';
import {estadisticas} from './Admin/Eps/estadisticas';
*/
console.log("express??");
export default (app: core.Express) => {
const app = express();
const port = 3000;
const expressApp = (app: core.Express) => {
app.use(express.json());
app.use(express.urlencoded());
@ -12,7 +30,7 @@ export default (app: core.Express) => {
app.get("/");
app.post('/links', require('./LinksAnimes/obtenerLinks').obtenerLinks);
app.put('/links', require('./LinksAnimes/modificarLink').modificarLinks);
app.put('/links', require('./LinksAnimes/modificarLink').modificarLink);
app.put('/a/', require('./Admin/crearAnime').crearAnime);
app.get('/a/', require('./Admin/obtenerTodosAnimes').obtenerTodosAnimes);
@ -30,7 +48,24 @@ export default (app: core.Express) => {
app.get('/estadisticas', require('./Admin/Eps/estadisticas').estadisticas);
}
export const conexionMySQL = (() => {
const sqlite = new Database('pseudosubs.sqlite');
export const sqliteConnection = {
escape: (str: string): string => {
return str;
},
query: (query: string, callback: (err: Error|null, rows: any) => void) => {
const q = sqlite.query(query);
try {
const result = q.all();
callback(null, result);
} catch (e) {
callback(e, null);
}
},
};
const conexion = (() => {
const con = mysql.createConnection({
host: 'localhost',
user: 'root',
@ -49,6 +84,11 @@ export const conexionMySQL = (() => {
return con;
})();
const color = '#cc2f66';
expressApp(app);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
// module.exports.conexionMySQL = conexionMySQL;

75
srv/tablas.sqlite Normal file
View File

@ -0,0 +1,75 @@
-- Tabla Animes
CREATE TABLE animes (
anime_ID ROWID,
titulo TEXT,
link TEXT,
imgUrl TEXT,
descripcion TEXT,
estudio TEXT,
eps INTEGER,
alAire TEXT,
temporada TEXT,
anio TEXT,
fuente TEXT,
generos TEXT,
color TEXT
);
-- Tabla que registra cuales animes estan en el menu principal
CREATE TABLE enPagPrin (
pagPrin_ID ROWID,
posicion INTEGER,
anime_ID INTEGER
);
-- Tabla OP
CREATE TABLE OP (
OP_ID ROWID,
anime_ID INTEGER,
num_OP INTEGER,
nombre TEXT,
artista TEXT,
eps TEXT
);
-- Tabla ED
CREATE TABLE ED (
ED_ID ROWID,
anime_ID INTEGER,
num_ED INTEGER,
nombre TEXT,
artista TEXT,
eps TEXT
);
-- Tabla con los links (y sus tablas complementarias)
CREATE TABLE links (
links_ID ROWID,
anime_ID INTEGER,
aviso TEXT,
sigEp TEXT
);
CREATE TABLE links_opciones (
opcion_ID ROWID,
links_ID INTEGER,
num_opcion INTEGER,
formato TEXT,
res TEXT,
servidor TEXT,
color TEXT
);
CREATE TABLE eps (
ep_ID ROWID,
opcion_ID INTEGER,
num_ep INTEGER,
visitas INTEGER DEFAULT 0,
link TEXT,
peso TEXT
);