utn-cli 2.1.18 → 2.1.20
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/commands/backend.js +64 -40
- package/package.json +1 -1
- package/templates/backend/InformacionDelModulo.json +0 -4
- package/templates/backend/servicios/Nucleo/InformacionDelModulo.js +96 -0
- package/templates/backend/servicios/Nucleo/Miscelaneas.js +2451 -92
- package/templates/backend/servicios/InformacionDelModulo.js +0 -193
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Archivos.js +0 -329
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Autenticacion.js +0 -388
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/InicializacionDelModulo.js +0 -254
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Modulos.js +0 -261
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Notificaciones.js +0 -82
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Personas.js +0 -93
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/Reportes.js +0 -370
- package/templates/backend/servicios/Nucleo/MiscelaneasMixins/TareasProgramadas.js +0 -105
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
class InformacionDelModulo {
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
try {
|
|
7
|
-
this._json = require(path.join(__dirname, '../InformacionDelModulo.json'));
|
|
8
|
-
} catch (e) {
|
|
9
|
-
this._json = {};
|
|
10
|
-
}
|
|
11
|
-
this._db = null;
|
|
12
|
-
this._initialized = false;
|
|
13
|
-
this._loadPromise = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Carga los datos desde la BD. Si no encuentra el módulo, mantiene los valores del JSON.
|
|
17
|
-
async initialize() {
|
|
18
|
-
if (this._initialized) return;
|
|
19
|
-
if (this._loadPromise) return this._loadPromise;
|
|
20
|
-
this._loadPromise = this._cargarDesdeDB().finally(() => {
|
|
21
|
-
this._initialized = true;
|
|
22
|
-
this._loadPromise = null;
|
|
23
|
-
});
|
|
24
|
-
return this._loadPromise;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async _cargarDesdeDB() {
|
|
28
|
-
try {
|
|
29
|
-
const { ejecutarConsultaSIGU } = require('./Nucleo/db.js');
|
|
30
|
-
const nombreCanonico = this._json['NOMBRE_DEL_CANONICO_DEL_PROYECTO'];
|
|
31
|
-
const nombreBackend = this._json['NOMBRE_DEL_REPOSITORIO_DE_BACKEND'];
|
|
32
|
-
|
|
33
|
-
// Si el JSON todavía tiene el placeholder, no tiene sentido consultar la BD
|
|
34
|
-
if (!nombreCanonico || nombreCanonico === 'NOMBRE_DEL_CANONICO_DEL_PROYECTO') return;
|
|
35
|
-
|
|
36
|
-
const [modulos, permisos, backendAccesos] = await Promise.all([
|
|
37
|
-
ejecutarConsultaSIGU(
|
|
38
|
-
"SELECT `Nombre`, `Padre`, `Descripcion`, `Detalle`, `Tipo`, `Color`, `Correo`, `Version`, `Repositorios` FROM `SIGU`.`SIGU_ModulosV2` WHERE `Nombre` = ?",
|
|
39
|
-
[nombreCanonico]
|
|
40
|
-
),
|
|
41
|
-
ejecutarConsultaSIGU(
|
|
42
|
-
"SELECT `Nombre`, `Descripcion` FROM `SIGU`.`SIGU_PermisosV2` WHERE `Modulo` = ? LIMIT 1",
|
|
43
|
-
[nombreCanonico]
|
|
44
|
-
),
|
|
45
|
-
(nombreBackend && nombreBackend !== 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND')
|
|
46
|
-
? ejecutarConsultaSIGU(
|
|
47
|
-
"SELECT `RepositorioDestino` FROM `SIGU`.`SIGU_RepositoriosAccesos` WHERE `RepositorioOrigen` = ?",
|
|
48
|
-
[nombreBackend]
|
|
49
|
-
)
|
|
50
|
-
: Promise.resolve([])
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
// Módulo no registrado aún en BD → se usan valores del JSON
|
|
54
|
-
if (modulos.length === 0) return;
|
|
55
|
-
|
|
56
|
-
const m = modulos[0];
|
|
57
|
-
this._db = {};
|
|
58
|
-
|
|
59
|
-
this._db.DescripcionDelModulo = m.Descripcion;
|
|
60
|
-
this._db.DetalleDelModulo = m.Detalle;
|
|
61
|
-
this._db.TipoDeCard = m.Tipo;
|
|
62
|
-
this._db.ColorDelModulo = m.Color;
|
|
63
|
-
this._db.CorreoParaReportes = m.Correo;
|
|
64
|
-
this._db.MenuPadre = m.Padre;
|
|
65
|
-
// La versión se almacena como "1.0.0$$NombreCanonico"; se extrae solo la parte semántica
|
|
66
|
-
this._db.Version = m.Version ? m.Version.split('$$')[0] : null;
|
|
67
|
-
|
|
68
|
-
// Repositorios: "https://grupo/repo-bd,https://grupo/repo-back,https://grupo/repo-front"
|
|
69
|
-
if (m.Repositorios) {
|
|
70
|
-
const repos = m.Repositorios.split(',');
|
|
71
|
-
if (repos.length >= 3) {
|
|
72
|
-
const extractName = url => url.trim().split('/').pop();
|
|
73
|
-
const extractGroup = url => url.trim().split('/').slice(0, -1).join('/');
|
|
74
|
-
this._db.NombreDelRepositorioDeLaBaseDeDatos = extractName(repos[0]);
|
|
75
|
-
this._db.NombreDelRepositorioDelBackend = extractName(repos[1]);
|
|
76
|
-
this._db.NombreDelRepositorioDelFrontend = extractName(repos[2]);
|
|
77
|
-
this._db.UrlDelGrupo = extractGroup(repos[0]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (permisos.length > 0) {
|
|
82
|
-
this._db.NombreDelPermiso = permisos[0].Nombre;
|
|
83
|
-
this._db.DescripcionDelPermiso = permisos[0].Descripcion;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (backendAccesos.length > 0) {
|
|
87
|
-
this._db.BackEndsQueConsumeEsteModulo = backendAccesos.map(r => r.RepositorioDestino);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
} catch (e) {
|
|
91
|
-
console.warn('InformacionDelModulo: no se pudo cargar desde BD, usando JSON:', e.message);
|
|
92
|
-
this._db = null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Retorna el valor de BD si existe, si no el del JSON, si no el fallback
|
|
97
|
-
_get(dbKey, jsonKey, fallback = '') {
|
|
98
|
-
if (this._db && this._db[dbKey] != null) return this._db[dbKey];
|
|
99
|
-
const jsonVal = this._json?.[jsonKey];
|
|
100
|
-
if (jsonVal != null) return jsonVal;
|
|
101
|
-
return fallback;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getNombreDelModulo() {
|
|
105
|
-
return this._get('NombreDelModulo', 'NOMBRE_DEL_PROYECTO', 'NOMBRE_DEL_PROYECTO');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getDescripcionDelModulo() {
|
|
109
|
-
return this._get('DescripcionDelModulo', 'DESCRIPCION_DEL_PROYECTO', 'DESCRIPCION_DEL_PROYECTO');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getDetalleDelModulo() {
|
|
113
|
-
return this._get('DetalleDelModulo', 'DETALLE_DEL_PROYECTO', 'DETALLE_DEL_PROYECTO');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
getNombreCanonicoDelModulo() {
|
|
117
|
-
return this._get('NombreCanonicoDelModulo', 'NOMBRE_DEL_CANONICO_DEL_PROYECTO', 'NOMBRE_DEL_CANONICO_DEL_PROYECTO');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
getTipoDeCard() {
|
|
121
|
-
return this._get('TipoDeCard', 'TIPO_DE_TARJETA', 'TIPO_DE_TARJETA');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getNombreDelRol() {
|
|
125
|
-
return this._get('NombreDelRol', 'NOMBRE_DEL_ROL', 'NOMBRE_DEL_ROL');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getNombreDelRepositorioDeLaBaseDeDatos() {
|
|
129
|
-
return this._get('NombreDelRepositorioDeLaBaseDeDatos', 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
getNombreDelRepositorioDelBackend() {
|
|
133
|
-
return this._get('NombreDelRepositorioDelBackend', 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND', 'NOMBRE_DEL_REPOSITORIO_DE_BACKEND');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
getNombreDelRepositorioDelFrontend() {
|
|
137
|
-
return this._get('NombreDelRepositorioDelFrontend', 'NOMBRE_DEL_REPOSITORIO_DE_FRONTEND', 'NOMBRE_DEL_REPOSITORIO_DE_FRONTEND');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getNombreDelPermiso() {
|
|
141
|
-
return this._get('NombreDelPermiso', 'NOMBRE_DEL_PERMISO', 'NOMBRE_DEL_PERMISO');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
getDescripcionDelPermiso() {
|
|
145
|
-
return this._get('DescripcionDelPermiso', 'DESCRIPCION_DEL_PERMISO', 'DESCRIPCION_DEL_PERMISO');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getMenuPadre() {
|
|
149
|
-
return this._get('MenuPadre', 'MENU_PADRE', 'MENU_PADRE');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
getBackEndsQueConsumeEsteModulo() {
|
|
153
|
-
if (this._db?.BackEndsQueConsumeEsteModulo?.length) {
|
|
154
|
-
return this._db.BackEndsQueConsumeEsteModulo;
|
|
155
|
-
}
|
|
156
|
-
const val = this._json?.['BACKENDS_QUE_CONSUME_ESTE_MODULO'];
|
|
157
|
-
if (!val || val === 'BACKENDS_QUE_CONSUME_ESTE_MODULO') return [];
|
|
158
|
-
return Array.isArray(val) ? val : [val];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
getPerfilGeneral() {
|
|
162
|
-
return this._get('PerfilGeneral', 'PERFIL_GENERAL', 'Servidor');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
getUsuariosConAccesoInicial() {
|
|
166
|
-
const lista = this._json?.['USUARIOS_CON_ACCESO_INICIAL'];
|
|
167
|
-
if (Array.isArray(lista)) return lista;
|
|
168
|
-
// Compatibilidad con formato anterior: cédula suelta + base fija
|
|
169
|
-
const cedula = this._json?.['CEDULA_DEL_DESARROLLADOR'];
|
|
170
|
-
const base = ['111050570', '204540859', '602990078', '109840817', '206860639', '801680123'];
|
|
171
|
-
if (cedula && cedula !== 'CEDULA_DEL_DESARROLLADOR') return [...base, cedula];
|
|
172
|
-
return base;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
getColorDelModulo() {
|
|
176
|
-
return this._get('ColorDelModulo', 'COLOR_DEL_MODULO', 'COLOR_DEL_MODULO');
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
getCorreoParaReportes() {
|
|
180
|
-
return this._get('CorreoParaReportes', 'CORREO_PARA_REPORTES', 'CORREO_PARA_REPORTES');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
getVersion() {
|
|
184
|
-
return this._get('Version', 'VERSION', 'VERSION');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
getUrlDelGrupo() {
|
|
188
|
-
return this._get('UrlDelGrupo', 'url_del_grupo', 'url_del_grupo');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
module.exports = new InformacionDelModulo();
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
const { ejecutarConsulta, ejecutarConsultaSIGU } = require('../db.js');
|
|
2
|
-
const ManejadorDeErrores = require('../ManejadorDeErrores.js');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
|
|
6
|
-
_archivoFuenteActual: null,
|
|
7
|
-
_archivoCache: new Map(),
|
|
8
|
-
|
|
9
|
-
_buscarArchivoRecursivo(dir, nombre) {
|
|
10
|
-
if (this._archivoCache.has(nombre)) return this._archivoCache.get(nombre);
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
const buscar = (directorio) => {
|
|
14
|
-
for (const entrada of fs.readdirSync(directorio, { withFileTypes: true })) {
|
|
15
|
-
const ruta = path.join(directorio, entrada.name);
|
|
16
|
-
if (entrada.isDirectory()) {
|
|
17
|
-
const resultado = buscar(ruta);
|
|
18
|
-
if (resultado) return resultado;
|
|
19
|
-
} else if (entrada.name === nombre) {
|
|
20
|
-
return ruta;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
|
-
const resultado = buscar(dir);
|
|
26
|
-
this._archivoCache.set(nombre, resultado);
|
|
27
|
-
return resultado;
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
fechaConFormato() {
|
|
31
|
-
const ahora = new Date(Date.now());
|
|
32
|
-
const anio = ahora.getFullYear();
|
|
33
|
-
const mes = String(ahora.getMonth() + 1).padStart(2, '0');
|
|
34
|
-
const dia = String(ahora.getDate()).padStart(2, '0');
|
|
35
|
-
const hora = String(ahora.getHours()).padStart(2, '0');
|
|
36
|
-
const minutos = String(ahora.getMinutes()).padStart(2, '0');
|
|
37
|
-
const segundos = String(ahora.getSeconds()).padStart(2, '0');
|
|
38
|
-
return `${anio}${mes}${dia}${hora}${minutos}${segundos}`;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
creacionDeldirectorioParaElAlmacenamientoDeArchivos() {
|
|
42
|
-
const fs = require('fs');
|
|
43
|
-
try {
|
|
44
|
-
if (!fs.existsSync(this.directorioParaElAlmacenamientoDeArchivos())) {
|
|
45
|
-
fs.mkdirSync(this.directorioParaElAlmacenamientoDeArchivos(), { recursive: true });
|
|
46
|
-
console.log(`El directorio '${this.directorioParaElAlmacenamientoDeArchivos()}' ha sido creado.`);
|
|
47
|
-
} else {
|
|
48
|
-
console.log(`El directorio '${this.directorioParaElAlmacenamientoDeArchivos()}' ya existe.`);
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error(`Se presentó el siguiente problema al interactuar con el sistema de archivos: ${error}`);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
directorioParaElAlmacenamientoDeArchivos() {
|
|
56
|
-
return '/var/storage/public/' + this.NombreCanonicoDelModulo;
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
async convertirTextoEnArchivoLocal(Texto, Token, NombreDelArchivo, Etiquetas) {
|
|
60
|
-
let EnlaceDelBack = 'http';
|
|
61
|
-
EnlaceDelBack = EnlaceDelBack + ((process.env.ENV || 'local') === 'production' ? 's' : '');
|
|
62
|
-
EnlaceDelBack = EnlaceDelBack + '://';
|
|
63
|
-
EnlaceDelBack = EnlaceDelBack + (['desarrollo', 'calidad', 'pruebas', 'production'].includes(process.env.ENV) ? this.NombreDelRepositorioDelBackend : 'localhost');
|
|
64
|
-
EnlaceDelBack = EnlaceDelBack + '/misc/cargarArchivo/' + Etiquetas;
|
|
65
|
-
const Encabezados = {
|
|
66
|
-
'Authorization': Token,
|
|
67
|
-
'Referrer': this.NombreDelRepositorioDelBackend,
|
|
68
|
-
'Origin': EnlaceDelBack
|
|
69
|
-
};
|
|
70
|
-
const blob = new Blob([Texto], { type: 'text/plain' });
|
|
71
|
-
const formData = new FormData();
|
|
72
|
-
formData.append('archivo', blob, NombreDelArchivo);
|
|
73
|
-
try {
|
|
74
|
-
const response = await fetch(EnlaceDelBack, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
headers: Encabezados,
|
|
77
|
-
body: formData,
|
|
78
|
-
redirect: 'error'
|
|
79
|
-
});
|
|
80
|
-
if (!response.ok) {
|
|
81
|
-
const errorTexto = await response.text();
|
|
82
|
-
throw new Error(`Error del servidor (${response.status}): ${errorTexto}`);
|
|
83
|
-
}
|
|
84
|
-
return await response.json();
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error(error.message);
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
async almacenarArchivoEnDisco(Solicitud, UId) {
|
|
91
|
-
const fs = require('fs');
|
|
92
|
-
const trozos = [];
|
|
93
|
-
let tamanioTotal = 0;
|
|
94
|
-
let informacionDelArchivo = {};
|
|
95
|
-
|
|
96
|
-
await new Promise((resolve, reject) => {
|
|
97
|
-
Solicitud.on('data', (trozo) => {
|
|
98
|
-
trozos.push(trozo);
|
|
99
|
-
tamanioTotal += trozo.length;
|
|
100
|
-
});
|
|
101
|
-
Solicitud.on('end', resolve);
|
|
102
|
-
Solicitud.on('error', reject);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const buffer = Buffer.concat(trozos);
|
|
107
|
-
const limite = Solicitud.headers['content-type'].split('; ')[1].split('=')[1];
|
|
108
|
-
const limiteDelimitador = `--${limite}`;
|
|
109
|
-
const partes = buffer.toString('latin1').split(limiteDelimitador).filter(Boolean);
|
|
110
|
-
|
|
111
|
-
for (const parte of partes) {
|
|
112
|
-
if (parte.includes('filename=')) {
|
|
113
|
-
const [headers, ...contentParts] = parte.split('\r\n\r\n');
|
|
114
|
-
const contenidoBinario = Buffer.from(contentParts.join('\r\n\r\n'), 'latin1');
|
|
115
|
-
const nombreDeArchivoMatch = headers.match(/filename="([^"]+)"/);
|
|
116
|
-
const tipoDeContenidoMatch = headers.match(/Content-Type: ([^\r\n]+)/);
|
|
117
|
-
|
|
118
|
-
if (nombreDeArchivoMatch) {
|
|
119
|
-
const nombreDeArchivo = Buffer.from(nombreDeArchivoMatch[1], 'latin1').toString('utf8');
|
|
120
|
-
const tipoDeContenido = tipoDeContenidoMatch ? tipoDeContenidoMatch[1] : 'application/octet-stream';
|
|
121
|
-
const rutaDeArchivo = `${this.directorioParaElAlmacenamientoDeArchivos()}/${UId}-${this.fechaConFormato()}-${nombreDeArchivo}`;
|
|
122
|
-
|
|
123
|
-
fs.writeFileSync(rutaDeArchivo, contenidoBinario);
|
|
124
|
-
|
|
125
|
-
informacionDelArchivo = {
|
|
126
|
-
nombreDeArchivo,
|
|
127
|
-
tipoDeContenido,
|
|
128
|
-
tamanioTotal,
|
|
129
|
-
rutaDeArchivo,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.error('Error al guardar el archivo:', error);
|
|
136
|
-
throw new ManejadorDeErrores(error.message, ManejadorDeErrores.obtenerNumeroDeLinea());
|
|
137
|
-
}
|
|
138
|
-
return informacionDelArchivo;
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
async cargarArchivo(Solicitud, Etiquetas) {
|
|
142
|
-
const Partes = Etiquetas.split('--');
|
|
143
|
-
Etiquetas = Partes.slice(0, -1).join("--");
|
|
144
|
-
let Resultado = undefined;
|
|
145
|
-
try {
|
|
146
|
-
Resultado = await this.obtenerDatosDelUsuario(Solicitud.headers.authorization);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.error(error);
|
|
149
|
-
}
|
|
150
|
-
if (Resultado) {
|
|
151
|
-
const informacionDelArchivo = await this.almacenarArchivoEnDisco(Solicitud, Resultado['uid']);
|
|
152
|
-
const Respuesta = await ejecutarConsultaSIGU("INSERT INTO `SIGU`.`SIGU_Adjuntos` (`AdjuntosId`, `Identificador`, `Modulo`, `Seccion`, `Nombre`,\
|
|
153
|
-
`NombreOriginal`, `Ruta`, `Tipo`, `Tamanio`, `Etiqueta`, `LastUpdate`, `LastUser`)\
|
|
154
|
-
VALUES (NULL, ?, ?, 'No aplica', ?, ?, ?, ?, ?, ?, NOW(4), ?)"
|
|
155
|
-
, [Resultado['uid'], this.NombreCanonicoDelModulo, informacionDelArchivo.nombreDeArchivo, informacionDelArchivo.nombreDeArchivo
|
|
156
|
-
, informacionDelArchivo.rutaDeArchivo, informacionDelArchivo.tipoDeContenido, informacionDelArchivo.tamanioTotal
|
|
157
|
-
, Etiquetas, Resultado['uid']]);
|
|
158
|
-
informacionDelArchivo.insertId = Respuesta.insertId;
|
|
159
|
-
informacionDelArchivo.Etiquetas = Etiquetas;
|
|
160
|
-
await ejecutarConsulta("INSERT INTO `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
161
|
-
VALUES (?, ?, ?, ?, ?, NOW(4), ?)"
|
|
162
|
-
, [Respuesta.insertId, Resultado.Identificador, informacionDelArchivo.rutaDeArchivo, informacionDelArchivo.nombreDeArchivo
|
|
163
|
-
, Etiquetas, Resultado.Identificador]);
|
|
164
|
-
return informacionDelArchivo;
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
archivoCSVAJSON(rutaArchivo) {
|
|
170
|
-
const fs = require('fs');
|
|
171
|
-
const path = require('path');
|
|
172
|
-
return new Promise((resolve, reject) => {
|
|
173
|
-
fs.readFile(path.resolve(rutaArchivo), 'utf8', (err, data) => {
|
|
174
|
-
if (err) {
|
|
175
|
-
return reject(err);
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const lineas = data.trim().split('\n');
|
|
179
|
-
const encabezados = lineas[0].split(',');
|
|
180
|
-
const resultados = lineas.slice(1).map((linea) => {
|
|
181
|
-
const valores = linea.split(',');
|
|
182
|
-
const objeto = {};
|
|
183
|
-
encabezados.forEach((encabezado, index) => {
|
|
184
|
-
objeto[encabezado.trim()] = valores[index]?.trim();
|
|
185
|
-
});
|
|
186
|
-
return objeto;
|
|
187
|
-
});
|
|
188
|
-
resolve(resultados);
|
|
189
|
-
} catch (error) {
|
|
190
|
-
reject(error);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
async listarArchivos(Datos) {
|
|
197
|
-
const Partes = Datos.Etiquetas.split('--');
|
|
198
|
-
const Etiquetas = Partes.slice(0, -1).join("--");
|
|
199
|
-
const partes = Datos.Etiquetas.split('--');
|
|
200
|
-
const ultimaParte = partes[partes.length - 1].split('=')[1];
|
|
201
|
-
if (ultimaParte === 'Usuario') {
|
|
202
|
-
let Resultado = undefined;
|
|
203
|
-
try {
|
|
204
|
-
Resultado = await this.obtenerDatosDelUsuario(Datos.Token);
|
|
205
|
-
if (!Resultado) {
|
|
206
|
-
throw new ManejadorDeErrores(ManejadorDeErrores.mensajeDeErrorVerificacionDeToken(), ManejadorDeErrores.obtenerNumeroDeLinea());
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
console.log(error);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
return await ejecutarConsulta("SELECT `ArchivoId`, `Identificador`, `Ruta`, CONCAT(`Nombre`, ' (', DATE_FORMAT(`LastUpdate`, '%Y-%M-%d %H:%i'), ')') AS `Nombre`, `Etiquetas`\
|
|
213
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
214
|
-
WHERE `Identificador` = ? AND `Etiquetas` = ?"
|
|
215
|
-
, [Resultado.Identificador, Etiquetas]);
|
|
216
|
-
}
|
|
217
|
-
if (ultimaParte === 'Servicio') {
|
|
218
|
-
return await ejecutarConsulta("SELECT `ArchivoId`, `Identificador`, `Ruta`, CONCAT(`Nombre`, ' (', DATE_FORMAT(`LastUpdate`, '%Y-%M-%d %H:%i'), ')') AS `Nombre`, `Etiquetas`\
|
|
219
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
220
|
-
WHERE `Etiquetas` = ?"
|
|
221
|
-
, [Etiquetas]);
|
|
222
|
-
}
|
|
223
|
-
if (ultimaParte === 'Proceso') {
|
|
224
|
-
return await ejecutarConsulta("SELECT `ArchivoId`, `Identificador`, `Ruta`, CONCAT(`Nombre`, ' (', DATE_FORMAT(`LastUpdate`, '%Y-%M-%d %H:%i'), ')') AS `Nombre`, `Etiquetas`\
|
|
225
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
226
|
-
WHERE `Etiquetas` = ?"
|
|
227
|
-
, [Etiquetas]);
|
|
228
|
-
}
|
|
229
|
-
if (typeof ultimaParte === "number") {
|
|
230
|
-
if (this.validarTokenV2(Datos.Token, ultimaParte)) {
|
|
231
|
-
return await ejecutarConsulta("SELECT `ArchivoId`, `Identificador`, `Ruta`, CONCAT(`Nombre`, ' (', DATE_FORMAT(`LastUpdate`, '%Y-%M-%d %H:%i'), ')') AS `Nombre`, `Etiquetas`\
|
|
232
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
233
|
-
WHERE `Etiquetas` = ?"
|
|
234
|
-
, [Etiquetas]);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
async listarArchivosExterno(Datos) {
|
|
240
|
-
const Partes = Datos.Etiquetas.split('--');
|
|
241
|
-
const Etiquetas = Partes.slice(0, -1).join("--");
|
|
242
|
-
let Resultado = undefined;
|
|
243
|
-
try {
|
|
244
|
-
Resultado = await this.obtenerDatosDelUsuario(Datos.Token);
|
|
245
|
-
if (!Resultado) {
|
|
246
|
-
throw new ManejadorDeErrores(ManejadorDeErrores.mensajeDeErrorVerificacionDeToken(), ManejadorDeErrores.obtenerNumeroDeLinea());
|
|
247
|
-
}
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.log(error);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
return await ejecutarConsulta("SELECT `ArchivoId`, `Identificador`, `Ruta`, CONCAT(`Nombre`, ' (', DATE_FORMAT(`LastUpdate`, '%Y-%M-%d %H:%i'), ')') AS `Nombre`, `Etiquetas`\
|
|
253
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
254
|
-
WHERE `Identificador` = ?"
|
|
255
|
-
, [Etiquetas]);
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
async borrarArchivo(Datos) {
|
|
259
|
-
let Resultado = undefined;
|
|
260
|
-
try {
|
|
261
|
-
Resultado = await this.obtenerDatosDelUsuario(Datos.Token);
|
|
262
|
-
if (!Resultado) {
|
|
263
|
-
throw new ManejadorDeErrores(ManejadorDeErrores.mensajeDeErrorVerificacionDeToken(), ManejadorDeErrores.obtenerNumeroDeLinea());
|
|
264
|
-
}
|
|
265
|
-
} catch (error) {
|
|
266
|
-
console.log(error);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
const fs = require('fs');
|
|
270
|
-
const Archivo = await ejecutarConsulta("SELECT `Ruta`\
|
|
271
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
272
|
-
WHERE `Identificador` = ? AND `ArchivoId` = ?"
|
|
273
|
-
, [Resultado.Identificador, Datos.ArchivoId]);
|
|
274
|
-
fs.unlinkSync(Archivo[0]['Ruta']);
|
|
275
|
-
await ejecutarConsulta("DELETE FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
276
|
-
WHERE `Identificador` = ? AND `ArchivoId` = ?"
|
|
277
|
-
, [Resultado.Identificador, Datos.ArchivoId]);
|
|
278
|
-
await ejecutarConsultaSIGU("DELETE FROM `SIGU`.`SIGU_Adjuntos`\
|
|
279
|
-
WHERE `Identificador` = ? AND `AdjuntosId` = ?"
|
|
280
|
-
, [Resultado.Identificador, Datos.ArchivoId]);
|
|
281
|
-
return;
|
|
282
|
-
},
|
|
283
|
-
|
|
284
|
-
async descargarArchivo(Respuesta, Datos) {
|
|
285
|
-
let RutaDelArchivo = undefined;
|
|
286
|
-
const ArchivoId = Datos.ArchivoId.split('--')[0];
|
|
287
|
-
const partes = Datos.ArchivoId.split('--');
|
|
288
|
-
const ultimaParte = partes[partes.length - 1].split('=')[1];
|
|
289
|
-
if (ultimaParte === 'Usuario') {
|
|
290
|
-
let Resultado = undefined;
|
|
291
|
-
try {
|
|
292
|
-
Resultado = await this.obtenerDatosDelUsuario(Datos.Token);
|
|
293
|
-
if (!Resultado) {
|
|
294
|
-
throw new ManejadorDeErrores(ManejadorDeErrores.mensajeDeErrorVerificacionDeToken(), ManejadorDeErrores.obtenerNumeroDeLinea());
|
|
295
|
-
}
|
|
296
|
-
} catch (error) {
|
|
297
|
-
console.log(error);
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
RutaDelArchivo = await ejecutarConsulta("SELECT `Ruta`\
|
|
301
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
302
|
-
WHERE `Identificador` = ? AND `ArchivoId` = ?"
|
|
303
|
-
, [Resultado.Identificador, ArchivoId]);
|
|
304
|
-
}
|
|
305
|
-
if (ultimaParte === 'Servicio') {
|
|
306
|
-
RutaDelArchivo = await ejecutarConsulta("SELECT `Ruta`\
|
|
307
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
308
|
-
WHERE `ArchivoId` = ?"
|
|
309
|
-
, [ArchivoId]);
|
|
310
|
-
}
|
|
311
|
-
if (ultimaParte === 'Proceso') {
|
|
312
|
-
RutaDelArchivo = await ejecutarConsulta("SELECT `Ruta`\
|
|
313
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
314
|
-
WHERE `ArchivoId` = ?"
|
|
315
|
-
, [ArchivoId]);
|
|
316
|
-
}
|
|
317
|
-
if (typeof ultimaParte === "number") {
|
|
318
|
-
if (this.validarTokenV2(Datos.Token, ultimaParte)) {
|
|
319
|
-
RutaDelArchivo = await ejecutarConsulta("SELECT `Ruta`\
|
|
320
|
-
FROM `" + this.NombreDelRepositorioDeLaBaseDeDatos.slice(0, -3) + "`.`Archivos`\
|
|
321
|
-
WHERE `ArchivoId` = ?"
|
|
322
|
-
, [ArchivoId]);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
Respuesta.download(RutaDelArchivo[0]['Ruta']);
|
|
326
|
-
return;
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
};
|