fpavon-ee-shared 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dependency-injection/dependency-injection.ts +56 -0
- package/digitalSignature/application/digitalSignature.useCase.ts +171 -0
- package/digitalSignature/domain/PDFArrayCustom.ts +60 -0
- package/digitalSignature/domain/SignPDF.ts +112 -0
- package/digitalSignature/infrastructure/routes/digitalSignature.routes.ts +3 -0
- package/digitalSignature/infrastructure/template/marco.pdf +0 -0
- package/dist/dependency-injection/dependency-injection.js +46 -0
- package/dist/digitalSignature/application/digitalSignature.useCase.js +180 -0
- package/dist/digitalSignature/domain/PDFArrayCustom.js +59 -0
- package/dist/digitalSignature/domain/SignPDF.js +100 -0
- package/dist/digitalSignature/infrastructure/routes/digitalSignature.routes.js +1 -0
- package/dist/documentos/application/documentos.useCase.js +49 -0
- package/dist/documentos/application/streamConversor.js +14 -0
- package/dist/documentos/domain/documento.class.js +60 -0
- package/dist/documentos/domain/documento.interface.js +2 -0
- package/dist/documentos/domain/documento.repository.js +2 -0
- package/dist/documentos/domain/documentoFTP.js +11 -0
- package/dist/documentos/domain/value-object/uuid.js +21 -0
- package/dist/documentos/infrastructure/repository/documentos.ftp.repository.js +172 -0
- package/dist/estados/application/flujos.useCase.js +21 -0
- package/dist/estados/domain/estado.class.js +150 -0
- package/dist/estados/domain/flujos.repository.js +2 -0
- package/dist/estados/infrastructure/controller/flujos.controller.js +34 -0
- package/dist/estados/infrastructure/repositories/flujos.sql.repository.js +36 -0
- package/dist/estados/infrastructure/routes/flujo.route.js +50 -0
- package/dist/expediente-electronico/application/expediente-electronico.useCase.js +171 -0
- package/dist/expediente-electronico/domain/expediente-electronico.class.js +190 -0
- package/dist/expediente-electronico/domain/expediente-electronico.interface.js +2 -0
- package/dist/expediente-electronico/domain/expediente-electronico.repository.js +2 -0
- package/dist/expediente-electronico/domain/value-object/limited-string.class.js +19 -0
- package/dist/expediente-electronico/domain/value-object/notas.class.js +41 -0
- package/dist/expediente-electronico/infrastructure/controller/expediente-electronico.controller.js +306 -0
- package/dist/expediente-electronico/infrastructure/repositories/expediente-electronico.sql.repository.js +775 -0
- package/dist/expediente-electronico/infrastructure/routes/expediente-electronico.route.js +46 -0
- package/dist/infrastructure/bd/connection.sql.js +64 -0
- package/dist/infrastructure/bd/pagination.sql.js +15 -0
- package/dist/infrastructure/docs/swagger.js +37 -0
- package/dist/infrastructure/fileServer/fileServer.basic-ftp.js +220 -0
- package/dist/infrastructure/fileServer/fileServer.connection.js +94 -0
- package/dist/infrastructure/middlewares/middleware.apikey.js +15 -0
- package/dist/infrastructure/middlewares/middleware.auth.js +372 -0
- package/dist/infrastructure/middlewares/middleware.deslogueo.js +1 -0
- package/dist/infrastructure/middlewares/middleware.validarCampos.js +15 -0
- package/dist/infrastructure/middlewares/middleware.validarRol.js +19 -0
- package/dist/infrastructure/middlewares/validarNivel.js +37 -0
- package/dist/infrastructure/server/httpsServer.class.js +59 -0
- package/dist/infrastructure/server/server.class.js +54 -0
- package/dist/infrastructure/socket/socketIO.js +23 -0
- package/dist/infrastructure/stream-handler/stream-handler.js +137 -0
- package/dist/notificaciones/domain/datosNotificacion.class.js +11 -0
- package/dist/notificaciones/domain/datosNotificacion.interface.js +2 -0
- package/dist/notificaciones/domain/notificacion.class.js +19 -0
- package/dist/notificaciones/domain/notificacion.interface.js +2 -0
- package/dist/notificaciones/domain/notificacion.repository.js +2 -0
- package/dist/notificaciones/infrastructure/notificacion.controller.js +31 -0
- package/dist/usuarios/application/usuarios.useCase.js +22 -0
- package/dist/usuarios/domain/usuario.class.js +24 -0
- package/dist/usuarios/domain/usuario.interface.js +2 -0
- package/dist/usuarios/domain/usuarios.repository.js +2 -0
- package/dist/usuarios/infrastructure/controller/usuarios.controller.js +28 -0
- package/dist/usuarios/infrastructure/repository/usuarios.sql.repository.js +17 -0
- package/dist/usuarios/infrastructure/routes/usuarios.routes.js +19 -0
- package/documentos/application/documentos.useCase.ts +41 -0
- package/documentos/domain/documento.class.ts +101 -0
- package/documentos/domain/documento.interface.ts +9 -0
- package/documentos/domain/documento.repository.ts +12 -0
- package/documentos/domain/documentoFTP.ts +17 -0
- package/documentos/domain/value-object/uuid.ts +23 -0
- package/documentos/infrastructure/repository/documentos.ftp.repository.ts +169 -0
- package/estados/application/flujos.useCase.ts +13 -0
- package/estados/domain/estado.class.ts +213 -0
- package/estados/domain/flujos.repository.ts +8 -0
- package/estados/infrastructure/controller/flujos.controller.ts +21 -0
- package/estados/infrastructure/repositories/flujos.sql.repository.ts +29 -0
- package/estados/infrastructure/routes/flujo.route.ts +56 -0
- package/expediente-electronico/application/expediente-electronico.useCase.ts +154 -0
- package/expediente-electronico/domain/expediente-electronico.class.ts +223 -0
- package/expediente-electronico/domain/expediente-electronico.interface.ts +19 -0
- package/expediente-electronico/domain/expediente-electronico.repository.ts +22 -0
- package/expediente-electronico/domain/value-object/limited-string.class.ts +19 -0
- package/expediente-electronico/domain/value-object/notas.class.ts +51 -0
- package/expediente-electronico/infrastructure/controller/expediente-electronico.controller.ts +308 -0
- package/expediente-electronico/infrastructure/repositories/expediente-electronico.sql.repository.ts +799 -0
- package/expediente-electronico/infrastructure/routes/expediente-electronico.route.ts +64 -0
- package/infrastructure/bd/connection.sql.ts +49 -0
- package/infrastructure/bd/pagination.sql.ts +11 -0
- package/infrastructure/docs/swagger.ts +38 -0
- package/infrastructure/fileServer/fileServer.basic-ftp.ts +196 -0
- package/infrastructure/fileServer/fileServer.connection.ts +78 -0
- package/infrastructure/middlewares/middleware.apikey.ts +17 -0
- package/infrastructure/middlewares/middleware.auth.ts +409 -0
- package/infrastructure/middlewares/middleware.deslogueo.ts +0 -0
- package/infrastructure/middlewares/middleware.validarCampos.ts +15 -0
- package/infrastructure/middlewares/middleware.validarRol.ts +15 -0
- package/infrastructure/middlewares/validarNivel.ts +37 -0
- package/infrastructure/server/httpsServer.class.ts +69 -0
- package/infrastructure/server/server.class.ts +66 -0
- package/infrastructure/socket/socketIO.ts +22 -0
- package/infrastructure/stream-handler/stream-handler.ts +161 -0
- package/jest.config.js +8 -0
- package/notificaciones/domain/datosNotificacion.class.ts +13 -0
- package/notificaciones/domain/datosNotificacion.interface.ts +5 -0
- package/notificaciones/domain/notificacion.class.ts +23 -0
- package/notificaciones/domain/notificacion.interface.ts +15 -0
- package/notificaciones/domain/notificacion.repository.ts +8 -0
- package/notificaciones/infrastructure/notificacion.controller.ts +16 -0
- package/package.json +42 -0
- package/script.js +135 -0
- package/test/expediente-electronico/domain/expediente-electronico.class.test.ts +186 -0
- package/tsconfig.json +73 -0
- package/usuarios/application/usuarios.useCase.ts +12 -0
- package/usuarios/domain/usuario.class.ts +40 -0
- package/usuarios/domain/usuario.interface.ts +18 -0
- package/usuarios/domain/usuarios.repository.ts +3 -0
- package/usuarios/infrastructure/controller/usuarios.controller.ts +19 -0
- package/usuarios/infrastructure/repository/usuarios.sql.repository.ts +19 -0
- package/usuarios/infrastructure/routes/usuarios.routes.ts +20 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const express_1 = require("express");
|
|
7
|
+
const dependency_injection_1 = __importDefault(require("../../../dependency-injection/dependency-injection"));
|
|
8
|
+
const middleware_auth_1 = require("../../../infrastructure/middlewares/middleware.auth");
|
|
9
|
+
const route = (0, express_1.Router)();
|
|
10
|
+
const agregarModulo = (req, res, next) => {
|
|
11
|
+
try {
|
|
12
|
+
const perfil = req.body.usuario.roles;
|
|
13
|
+
if (perfil.length == 0) {
|
|
14
|
+
res.status(401).json({ "error": "No tiene el perfil requerido." });
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
perfil.forEach(rol => {
|
|
18
|
+
req.body.usuario.grupos.push(rol.grupo);
|
|
19
|
+
});
|
|
20
|
+
next();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
res.status(500).json({ "error": `${error}` });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const expedienteElectronicoController = dependency_injection_1.default.get('EE.ExpedienteElectronico.infrastructure.ExpedienteElectronicoController');
|
|
28
|
+
/**
|
|
29
|
+
* Routes
|
|
30
|
+
*/
|
|
31
|
+
route.use('/expediente-electronico', middleware_auth_1.validarToken);
|
|
32
|
+
route.use('/expediente-electronico', agregarModulo);
|
|
33
|
+
route.get('/expediente-electronico', middleware_auth_1.validarToken, expedienteElectronicoController.getExpCtrl);
|
|
34
|
+
route.get('/expediente-electronico-sin-paginacion', middleware_auth_1.validarToken, expedienteElectronicoController.getExpSinPaginacionCtrl);
|
|
35
|
+
route.get('/expediente-electronico/pendientes', expedienteElectronicoController.getExpPendientesCtrl);
|
|
36
|
+
route.get('/expediente-electronico/pendientesSinPaginado', expedienteElectronicoController.getExpPendientesSinPaginadoCtrl);
|
|
37
|
+
route.get('/expediente-electronico/rechazados', expedienteElectronicoController.getExpRechazadosCtrl);
|
|
38
|
+
route.get('/expediente-electronico/aprobados', expedienteElectronicoController.getExpAprobadosCtrl);
|
|
39
|
+
route.get('/expediente-electronico/cantidad', expedienteElectronicoController.getExpCantidadCtrl);
|
|
40
|
+
route.get('/expediente-electronico/cantidadPendientes', expedienteElectronicoController.getExpCantidadPendientesCtrl);
|
|
41
|
+
route.get('/expediente-electronico/cantidadAprobados', expedienteElectronicoController.getExpCantidadAprobadosCtrl);
|
|
42
|
+
route.get('/expediente-electronico/cantidadRechazados', expedienteElectronicoController.getExpACantidadRechazadosCtrl);
|
|
43
|
+
route.get('/unidades', expedienteElectronicoController.getAllUnidades);
|
|
44
|
+
route.get('/unidades/:unidad', expedienteElectronicoController.getUnidadesByUnidad);
|
|
45
|
+
route.patch('/expediente-electronico/firmarDocumento', expedienteElectronicoController.firmarDocumento);
|
|
46
|
+
exports.default = route;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getConnectionForTransaction = exports.executeQuery = exports.getConnection = void 0;
|
|
16
|
+
const mssql_1 = __importDefault(require("mssql"));
|
|
17
|
+
const conexion = {
|
|
18
|
+
user: process.env.DBUSER,
|
|
19
|
+
password: process.env.DBPASSWORD,
|
|
20
|
+
server: process.env.DBSERVER || "",
|
|
21
|
+
database: process.env.DBNAME,
|
|
22
|
+
options: {
|
|
23
|
+
encrypt: true,
|
|
24
|
+
trustServerCertificate: true
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function getConnection(query) {
|
|
28
|
+
return executeQuery(query);
|
|
29
|
+
}
|
|
30
|
+
exports.getConnection = getConnection;
|
|
31
|
+
function executeQuery(query, params) {
|
|
32
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
const pool = yield mssql_1.default.connect(conexion);
|
|
35
|
+
const request = pool.request();
|
|
36
|
+
// Agrega parámetros si se proporcionan
|
|
37
|
+
if (params) {
|
|
38
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
39
|
+
request.input(key, value);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const result = yield request.query(query);
|
|
43
|
+
resolve(result);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error("error BD: ", error);
|
|
47
|
+
reject(error);
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
exports.executeQuery = executeQuery;
|
|
52
|
+
function getConnectionForTransaction() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
try {
|
|
55
|
+
const pool = yield mssql_1.default.connect(conexion);
|
|
56
|
+
return pool;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error("Error al conectar a la base de datos:", error);
|
|
60
|
+
throw new Error("No se pudo conectar a la base de datos");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.getConnectionForTransaction = getConnectionForTransaction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPagination = void 0;
|
|
4
|
+
const getPagination = (page = 1, limit = 10) => {
|
|
5
|
+
if (limit > 25) {
|
|
6
|
+
limit = 10;
|
|
7
|
+
}
|
|
8
|
+
if (page < 1) {
|
|
9
|
+
page = 1;
|
|
10
|
+
}
|
|
11
|
+
const offset = (page - 1) * limit; // Es el número de paginas.
|
|
12
|
+
const limitClause = `FETCH NEXT ${limit} ROWS ONLY`; // Es la cantidad de registros por página.
|
|
13
|
+
return { offset, limitClause };
|
|
14
|
+
};
|
|
15
|
+
exports.getPagination = getPagination;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
|
|
7
|
+
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
8
|
+
const swaggerDefinition = {
|
|
9
|
+
openapi: '3.0.0',
|
|
10
|
+
info: {
|
|
11
|
+
title: 'Expedientes Electronicos API',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
},
|
|
14
|
+
servers: [
|
|
15
|
+
{
|
|
16
|
+
url: `${process.env.URL_SERVE}`
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
components: {
|
|
20
|
+
securitySchemes: {
|
|
21
|
+
Authentication: {
|
|
22
|
+
type: "http",
|
|
23
|
+
scheme: "bearer",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
schemas: {}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const swaggerOptions = {
|
|
30
|
+
swaggerDefinition,
|
|
31
|
+
apis: ['./src/*/infrastructure/routes/*.ts'],
|
|
32
|
+
};
|
|
33
|
+
// export default swaggerJSDoc(swaggerOptions);
|
|
34
|
+
const swaggerDocs = (app, port) => {
|
|
35
|
+
app.use('/api/docs', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup((0, swagger_jsdoc_1.default)(swaggerOptions)));
|
|
36
|
+
};
|
|
37
|
+
exports.default = swaggerDocs;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.FtpConnection = void 0;
|
|
36
|
+
// const ftp = require('basic-ftp');
|
|
37
|
+
const ftp = __importStar(require("basic-ftp"));
|
|
38
|
+
const stream_buffers_1 = require("stream-buffers");
|
|
39
|
+
const node_stream_1 = require("node:stream");
|
|
40
|
+
class FtpConnection {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.client = new ftp.Client(60000);
|
|
43
|
+
}
|
|
44
|
+
connect(host, user, password, secure) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
yield this.client.access({
|
|
48
|
+
host: host,
|
|
49
|
+
user: user,
|
|
50
|
+
password: password,
|
|
51
|
+
secure,
|
|
52
|
+
secureOptions: { rejectUnauthorized: false } // ⚠️ Desactiva validación del certificado
|
|
53
|
+
});
|
|
54
|
+
console.log('Conexión FTP establecida.');
|
|
55
|
+
// console.log(await this.client.list())
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.error('Error al conectar al servidor FTP:', err);
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
disconnect() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
yield this.client.close();
|
|
67
|
+
console.log('Conexión FTP cerrada.');
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.error('Error al cerrar la conexión FTP:', err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
uploadBuffer(buffer, remotePath) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
try {
|
|
77
|
+
const upload = yield this.client.uploadFrom(buffer, remotePath);
|
|
78
|
+
console.log('Archivo cargado con éxito en', remotePath);
|
|
79
|
+
return upload;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
console.error('Error al cargar el archivo:', err);
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
uploadFromStream(stream, remotePath) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
try {
|
|
90
|
+
console.log(`[FTP] 🚀 Iniciando upload de stream a: ${remotePath}`);
|
|
91
|
+
// Stream con logging de progreso
|
|
92
|
+
let totalBytes = 0;
|
|
93
|
+
let chunkCount = 0;
|
|
94
|
+
const progressStream = new node_stream_1.PassThrough();
|
|
95
|
+
// Interceptar datos para logging
|
|
96
|
+
stream.on('data', (chunk) => {
|
|
97
|
+
totalBytes += chunk.length;
|
|
98
|
+
chunkCount++;
|
|
99
|
+
// Log cada 200 chunks para no saturar
|
|
100
|
+
if (chunkCount % 200 === 0) {
|
|
101
|
+
const mb = Math.round(totalBytes / 1024 / 1024 * 100) / 100;
|
|
102
|
+
console.log(`[FTP] 📊 Progreso: ${chunkCount} chunks, ${mb} MB`);
|
|
103
|
+
}
|
|
104
|
+
progressStream.write(chunk);
|
|
105
|
+
});
|
|
106
|
+
stream.on('end', () => {
|
|
107
|
+
const mb = Math.round(totalBytes / 1024 / 1024 * 100) / 100;
|
|
108
|
+
console.log(`[FTP] 📁 Stream terminado: ${chunkCount} chunks totales, ${mb} MB`);
|
|
109
|
+
progressStream.end();
|
|
110
|
+
});
|
|
111
|
+
stream.on('error', (error) => {
|
|
112
|
+
console.error('[FTP] ❌ Error en stream de entrada:', error);
|
|
113
|
+
progressStream.destroy(error);
|
|
114
|
+
});
|
|
115
|
+
// Upload real usando basic-ftp
|
|
116
|
+
yield this.client.uploadFrom(progressStream, remotePath);
|
|
117
|
+
const mb = Math.round(totalBytes / 1024 / 1024 * 100) / 100;
|
|
118
|
+
console.log(`[FTP] ✅ Upload completado: ${remotePath} (${mb} MB)`);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.error(`[FTP] ❌ Error en upload:`, err);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
downloadToBuffer(remotePath) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
try {
|
|
129
|
+
const writableBuffer = new stream_buffers_1.WritableStreamBuffer();
|
|
130
|
+
yield this.client.downloadTo(writableBuffer, remotePath);
|
|
131
|
+
const buffer = writableBuffer.getContents();
|
|
132
|
+
return buffer;
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
console.error('Error al descargar el archivo:', err);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
downloadToStream(remotePath) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
try {
|
|
143
|
+
console.log(`[FTP] Iniciando descarga de stream: ${remotePath}`);
|
|
144
|
+
const passThrough = new node_stream_1.PassThrough({
|
|
145
|
+
highWaterMark: 64 * 1024 // Buffer de 64KB
|
|
146
|
+
});
|
|
147
|
+
// NO usar await aquí - retornar el stream inmediatamente
|
|
148
|
+
const downloadPromise = this.client.downloadTo(passThrough, remotePath);
|
|
149
|
+
// Manejar la finalización de forma asíncrona
|
|
150
|
+
downloadPromise
|
|
151
|
+
.then(() => {
|
|
152
|
+
console.log(`[FTP] Descarga completada: ${remotePath}`);
|
|
153
|
+
// NO llamar passThrough.end() aquí - basic-ftp lo hace automáticamente
|
|
154
|
+
})
|
|
155
|
+
.catch((error) => {
|
|
156
|
+
console.error(`[FTP] Error en descarga: ${remotePath}`, error);
|
|
157
|
+
passThrough.destroy(error);
|
|
158
|
+
});
|
|
159
|
+
// Debugging
|
|
160
|
+
passThrough.on('data', (chunk) => {
|
|
161
|
+
console.log(`[FTP STREAM] Chunk recibido: ${chunk.length} bytes`);
|
|
162
|
+
});
|
|
163
|
+
passThrough.on('end', () => {
|
|
164
|
+
console.log(`[FTP STREAM] Stream terminado: ${remotePath}`);
|
|
165
|
+
});
|
|
166
|
+
passThrough.on('error', (error) => {
|
|
167
|
+
console.error(`[FTP STREAM] Error:`, error);
|
|
168
|
+
});
|
|
169
|
+
return passThrough;
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
console.error('Error al crear stream:', err);
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
deleteByUuid(uuid) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
try {
|
|
180
|
+
yield this.client.remove(uuid);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
console.error('Error al borrar el archivo:', err);
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
list(path) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
yield this.client.useDefaultSettings();
|
|
192
|
+
return yield this.client.list(path);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
deleteAllFilesOnFtpServer() {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
try {
|
|
198
|
+
// Obtener una lista de archivos en el directorio actual
|
|
199
|
+
const fileList = yield this.client.list();
|
|
200
|
+
// Eliminar cada archivo en la lista
|
|
201
|
+
for (const file of fileList) {
|
|
202
|
+
// console.log(file.type);
|
|
203
|
+
if (file.type === 1) {
|
|
204
|
+
console.log(`Eliminando archivo: ${file.name}`);
|
|
205
|
+
yield this.client.remove(file.name);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
console.log('Todos los archivos han sido eliminados correctamente.');
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.error('Error al eliminar archivos:', error);
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
// Cerrar la conexión
|
|
215
|
+
yield this.client.close();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.FtpConnection = FtpConnection;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.FtpConnection = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
class FtpConnection {
|
|
29
|
+
constructor() {
|
|
30
|
+
let Client = require('ftp');
|
|
31
|
+
this.client = new Client();
|
|
32
|
+
this.client.on('error', (err) => {
|
|
33
|
+
console.error('Error en la conexión FTP:', err);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
connect(host, user, password) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
this.client.on('ready', () => {
|
|
39
|
+
console.log('Conexión FTP exitosa');
|
|
40
|
+
this.client.list((err, list) => {
|
|
41
|
+
if (err)
|
|
42
|
+
throw err;
|
|
43
|
+
// console.log(list);
|
|
44
|
+
this.client.end();
|
|
45
|
+
});
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
this.client.connect({
|
|
49
|
+
host: host,
|
|
50
|
+
user: user,
|
|
51
|
+
password: password
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
uploadFile(localPath, remotePath) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
this.client.put(localPath, remotePath, (err) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
console.error('Error al subir el archivo:', err);
|
|
60
|
+
reject(err);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log('Archivo subido exitosamente');
|
|
64
|
+
resolve();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
downloadFile(remotePath, localPath) {
|
|
70
|
+
console.log('Descargando..');
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
this.client.get(remotePath, function (err, stream) {
|
|
73
|
+
if (err) {
|
|
74
|
+
console.error('Error al descargar el archivo:');
|
|
75
|
+
reject(err);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
stream.once('close', () => {
|
|
79
|
+
console.log('Archivo descargado exitosamente');
|
|
80
|
+
stream.pipe(fs.createWriteStream(localPath));
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
stream.once('end', () => {
|
|
84
|
+
console.log('La conexión se cerró sin errores.');
|
|
85
|
+
resolve();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
disconnect() {
|
|
91
|
+
this.client.end();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.FtpConnection = FtpConnection;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validarApiKeyInternet = void 0;
|
|
4
|
+
const API_KEY_SECRET = process.env.APIKEY;
|
|
5
|
+
const validarApiKeyInternet = (req, res, next) => {
|
|
6
|
+
const apiKey = req.headers['x-api-key'];
|
|
7
|
+
if (!apiKey) {
|
|
8
|
+
return res.status(401).json({ error: 'Acceso no autorizado. Falta la clave API.' });
|
|
9
|
+
}
|
|
10
|
+
if (apiKey !== API_KEY_SECRET) {
|
|
11
|
+
return res.status(401).json({ error: 'Clave API inválida.' });
|
|
12
|
+
}
|
|
13
|
+
next();
|
|
14
|
+
};
|
|
15
|
+
exports.validarApiKeyInternet = validarApiKeyInternet;
|