intermediate-component-sa 1.1.0 → 1.1.2
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/app.server.js +7 -0
- package/client/css/main.css +1 -0
- package/{src/client → client}/index.html +6 -40
- package/client/js/app.js +1 -0
- package/client/js/shims.js +17 -0
- package/package.json +75 -340
- package/{src/server/config/app.config.ts → server/config/app.config.js} +47 -57
- package/server/config/jwt.config.js +4 -0
- package/{src/server/config/logger.config.ts → server/config/logger.config.js} +142 -161
- package/server/config/mssql.config.js +32 -0
- package/server/config/redis.config.js +8 -0
- package/server/config/server.config.js +12 -0
- package/server/config/templates.config.js +23 -0
- package/server/crypt.js +29 -0
- package/server/customRequest.js +373 -0
- package/server/index.js +125 -0
- package/server/interfaces/cleaner.interface.js +2 -0
- package/server/interfaces/supervisor.interface.js +2 -0
- package/{src/server/routes-centralized.ts → server/routes-centralized.js} +39 -36
- package/server/routes.js +7 -0
- package/server/services/index.js +8 -0
- package/server/services/routes.service.js +18 -0
- package/server/shared/file-manager.js +616 -0
- package/server/shared/http.shared.js +39 -0
- package/server/shared/promises.shared.js +14 -0
- package/server/shared/security.shared.js +52 -0
- package/CHANGELOG.md +0 -11
- package/README.md +0 -1
- package/build-dev.bat +0 -2
- package/build-prod-aot.bat +0 -2
- package/build-prod-rollup-aot.bat +0 -2
- package/build-prod.bat +0 -2
- package/config.ts +0 -4
- package/gulpfile.ts +0 -172
- package/index.js +0 -12
- package/karma.conf.js +0 -124
- package/postgrator-test.json +0 -9
- package/postgrator.json +0 -9
- package/src/app.server.ts +0 -4
- package/src/client/app/app.component.ts +0 -37
- package/src/client/app/app.html +0 -6
- package/src/client/app/app.module.ts +0 -36
- package/src/client/app/app.routing.ts +0 -7
- package/src/client/app/hot_loader_main.ts +0 -14
- package/src/client/app/main-aot.ts +0 -8
- package/src/client/app/main.ts +0 -8
- package/src/client/app/rxjs-operators.ts +0 -15
- package/src/server/config/jwt.config.ts +0 -4
- package/src/server/config/mssql.config.ts +0 -30
- package/src/server/config/redis.config.ts +0 -10
- package/src/server/config/server.config.ts +0 -20
- package/src/server/config/templates.config.ts +0 -41
- package/src/server/crypt.ts +0 -37
- package/src/server/customRequest.ts +0 -609
- package/src/server/index.ts +0 -231
- package/src/server/interfaces/cleaner.interface.ts +0 -3
- package/src/server/interfaces/supervisor.interface.ts +0 -3
- package/src/server/routes.ts +0 -6
- package/src/server/services/index.ts +0 -10
- package/src/server/services/routes.service.ts +0 -11
- package/src/server/shared/file-manager.ts +0 -1007
- package/src/server/shared/http.shared.ts +0 -49
- package/src/server/shared/promises.shared.ts +0 -13
- package/src/server/shared/security.shared.ts +0 -90
- package/src/server/tsconfig.json +0 -38
- package/tools/build.js.prod.ts +0 -40
- package/tools/config/project.config.ts +0 -718
- package/tools/config.ts +0 -4
- package/tools/database/SchemaZen.exe +0 -0
- package/tools/database/generate-all-data-scripts.bat +0 -32
- package/tools/database/generate-database-scripts.bat +0 -36
- package/tools/debug.ts +0 -17
- package/tools/env/base.ts +0 -8
- package/tools/env/dev.ts +0 -9
- package/tools/env/env-config.interface.ts +0 -1
- package/tools/env/prod.ts +0 -10
- package/tools/manual_typings/project/sample.package.d.ts +0 -3
- package/tools/manual_typings/seed/angular2-hot-loader.d.ts +0 -9
- package/tools/manual_typings/seed/autoprefixer.d.ts +0 -13
- package/tools/manual_typings/seed/colorguard.d.ts +0 -15
- package/tools/manual_typings/seed/connect-livereload.d.ts +0 -5
- package/tools/manual_typings/seed/cssnano.d.ts +0 -18
- package/tools/manual_typings/seed/doiuse.d.ts +0 -16
- package/tools/manual_typings/seed/express-history-api-fallback.d.ts +0 -18
- package/tools/manual_typings/seed/istream.d.ts +0 -10
- package/tools/manual_typings/seed/karma.d.ts +0 -12
- package/tools/manual_typings/seed/merge-stream.d.ts +0 -8
- package/tools/manual_typings/seed/open.d.ts +0 -8
- package/tools/manual_typings/seed/postcss-reporter.d.ts +0 -20
- package/tools/manual_typings/seed/slash.d.ts +0 -5
- package/tools/manual_typings/seed/stylelint.d.ts +0 -16
- package/tools/manual_typings/seed/systemjs-builder.d.ts +0 -10
- package/tools/manual_typings/seed/tildify.d.ts +0 -5
- package/tools/manual_typings/seed/tiny-lr.d.ts +0 -10
- package/tools/manual_typings/seed/walk.d.ts +0 -10
- package/tools/scripts/install.speech-analytic.sh +0 -35
- package/tools/tasks/build.app.server.ts +0 -57
- package/tools/tasks/build.assets.dev.ts +0 -19
- package/tools/tasks/build.assets.prod.ts +0 -31
- package/tools/tasks/build.bundles.app.aot.ts +0 -31
- package/tools/tasks/build.bundles.app.rollup.aot.ts +0 -101
- package/tools/tasks/build.bundles.app.ts +0 -31
- package/tools/tasks/build.bundles.ts +0 -45
- package/tools/tasks/build.database.scripts.runner.ts +0 -137
- package/tools/tasks/build.database.scripts.ts +0 -27
- package/tools/tasks/build.flags.ts +0 -9
- package/tools/tasks/build.fonts.ts +0 -9
- package/tools/tasks/build.html_css.ts +0 -126
- package/tools/tasks/build.index.dev.ts +0 -68
- package/tools/tasks/build.index.prod.ts +0 -64
- package/tools/tasks/build.js.dev.ts +0 -66
- package/tools/tasks/build.js.prod.aot.ts +0 -44
- package/tools/tasks/build.js.prod.rollup.aot.ts +0 -50
- package/tools/tasks/build.js.prod.ts +0 -40
- package/tools/tasks/build.packages.prod.ts +0 -19
- package/tools/tasks/build.server.dev.ts +0 -59
- package/tools/tasks/build.server.prod.ts +0 -31
- package/tools/tasks/build.server.statics.ts +0 -24
- package/tools/tasks/build.skins.ts +0 -51
- package/tools/tasks/build.sme.prod.aot.ts +0 -6
- package/tools/tasks/build.sme.prod.rollup.aot.ts +0 -6
- package/tools/tasks/build.sme.prod.ts +0 -6
- package/tools/tasks/build.tar.prod.ts +0 -17
- package/tools/tasks/build.test.database.scripts.ts +0 -52
- package/tools/tasks/clean.dev.ts +0 -7
- package/tools/tasks/clean.prod.ts +0 -7
- package/tools/tasks/compile.ahead.prod.ts +0 -65
- package/tools/tasks/copy.client.js.prod.rollup.aot.ts +0 -33
- package/tools/tasks/copy.client.js.prod.ts +0 -18
- package/tools/tasks/copy.server.assets.ts +0 -38
- package/tools/tasks/copy.server.js.prod.ts +0 -16
- package/tools/tasks/css-lint.ts +0 -58
- package/tools/tasks/e2e.ts +0 -32
- package/tools/tasks/karma.run.ts +0 -18
- package/tools/tasks/karma.watch.ts +0 -9
- package/tools/tasks/minify.server.statics.ts +0 -52
- package/tools/tasks/server.prod.ts +0 -6
- package/tools/tasks/server.start.ts +0 -6
- package/tools/tasks/test.database.ts +0 -6
- package/tools/tasks/transpile.bundles.rollup.aot.ts +0 -43
- package/tools/tasks/tslint.ts +0 -64
- package/tools/tasks/watch.file.changes.dev.ts +0 -37
- package/tools/tasks/watch.key.press.dev.ts +0 -116
- package/tools/tasks/webdriver.ts +0 -6
- package/tools/utils/project/sample_util.ts +0 -18
- package/tools/utils/project.utils.ts +0 -4
- package/tools/utils/seed/build_optimizer.ts +0 -26
- package/tools/utils/seed/clean.ts +0 -35
- package/tools/utils/seed/code_change_tools.ts +0 -38
- package/tools/utils/seed/karma.start.ts +0 -10
- package/tools/utils/seed/server.ts +0 -43
- package/tools/utils/seed/sme.ts +0 -51
- package/tools/utils/seed/tasks_tools.ts +0 -70
- package/tools/utils/seed/template_locals.ts +0 -64
- package/tools/utils/seed/tsproject.ts +0 -25
- package/tools/utils/seed.utils.ts +0 -11
- package/tools/utils.ts +0 -5
- package/tsconfig.json +0 -33
- package/tslint.json +0 -120
- package/utils.ts +0 -5
- /package/{src/client → client}/tsconfig.json +0 -0
- /package/{src/server → server}/ssl/star_inconcertcc_com.key +0 -0
- /package/{src/server → server}/ssl/star_inconcertcc_com.pem +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
// Nombre de la carpeta final
|
|
3
|
-
export const TEMP_FOLDER = 'temp';
|
|
4
|
-
// Ruta completa de la carpeta de archivos
|
|
5
|
-
export const TEMP_PATH = path.resolve(__dirname, '..', TEMP_FOLDER);
|
|
6
|
-
// Nombre de la carpeta de templates
|
|
7
|
-
export const TEMPLATE_FOLDER: string = 'template';
|
|
8
|
-
// Nombre de la carpeta de views (dentro de la de templates)
|
|
9
|
-
export const VIEWS_FOLDER: string = 'views';
|
|
10
|
-
// Nombre de la carpeta para mailing templates usadas por el sistema
|
|
11
|
-
export const MAIL_FOLDER: string = 'mail';
|
|
12
|
-
// Ruta relativa (URI) de la carpeta de vistas de templates
|
|
13
|
-
export const TEMPLATE_VIEWS_URI: string = TEMPLATE_FOLDER + '/' + VIEWS_FOLDER;
|
|
14
|
-
// Ruta completa de la carpeta de templates
|
|
15
|
-
export const TEMPLATE_PATH: string = path.resolve(__dirname, '..', TEMPLATE_FOLDER);
|
|
16
|
-
// Ruta completa de la carpeta de vistas de templates
|
|
17
|
-
export const TEMPLATE_VIEWS_PATH: string = path.resolve(__dirname, '..', TEMPLATE_FOLDER, VIEWS_FOLDER);
|
|
18
|
-
// Ruta completa de la carpeta de templates para mailing
|
|
19
|
-
export const TEMPLATE_MAIL_PATH: string = path.resolve(__dirname, '..', TEMPLATE_FOLDER, MAIL_FOLDER);
|
|
20
|
-
// Tiempo a mantener los archivos o carpeta temporales
|
|
21
|
-
export const TEMPLATE_TEMP_PERSISTENCE: number = 24 * 60 * 60;
|
|
22
|
-
// Nombre de la carpeta temporal para las templates
|
|
23
|
-
export const TEMPLATE_TEMP_FOLDER: string = 'temp';
|
|
24
|
-
// Prefijo para nombrar las carpetas temporales de las templates
|
|
25
|
-
export const TEMPLATE_TEMP_PREFIX: string = 'temp';
|
|
26
|
-
// Prefijo para nombrar las carpetas temporales de las templates en modo edición
|
|
27
|
-
export const TEMPLATE_EDIT_PREFIX: string = 'edit';
|
|
28
|
-
// Prefijo para nombrar los temporales para descarga de las templates
|
|
29
|
-
export const TEMPLATE_DOWNLOAD_PREFIX: string = 'download';
|
|
30
|
-
// Prefijo para nombrar los temporales para upload de las templates
|
|
31
|
-
export const TEMPLATE_UPLOAD_PREFIX: string = 'upload';
|
|
32
|
-
// Extensión para la generación de snapshots de las templates
|
|
33
|
-
export const TEMPLATE_PREVIEW_EXT: string = '.jpg';
|
|
34
|
-
// Ruta hacia la carpeta temporal donde se alojan las templates
|
|
35
|
-
export const TEMPLATE_TEMP_PATH: string = path.resolve(TEMPLATE_PATH, TEMPLATE_TEMP_FOLDER);
|
|
36
|
-
// Ruta relativa (URI) de la carpeta de vistas de templates
|
|
37
|
-
export const TEMPLATE_TEMP_URI: string = TEMPLATE_FOLDER + '/' + TEMPLATE_TEMP_FOLDER;
|
|
38
|
-
// Ruta completa de la carpeta de archivos js estaticos
|
|
39
|
-
export const STATIC_JS_PATH: string = path.resolve(__dirname, '../static/js');
|
|
40
|
-
// Prefijo para los partiales de archivos js estaticos
|
|
41
|
-
export const STATIC_JS_PARTIALS_PREFIX: string = 'static/js/';
|
package/src/server/crypt.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const crypto = require('crypto');
|
|
2
|
-
|
|
3
|
-
const algorithm = 'aes-256-ctr';
|
|
4
|
-
const password = 'vOVH6sdmpNWjRRIqCc7rdxs01lwHzfr3';
|
|
5
|
-
|
|
6
|
-
export function InconcertEncrypt(myText) : string {
|
|
7
|
-
const iv = crypto.randomBytes(16);
|
|
8
|
-
const cipher = crypto.createCipheriv(algorithm, password, Buffer.from(iv));
|
|
9
|
-
const encrypted = Buffer.concat([cipher.update(myText), cipher.final()]);
|
|
10
|
-
|
|
11
|
-
return `${encrypted.toString('hex')}-${iv.toString('hex')}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function InconcertDecrypt(myEncryptedText) : string {
|
|
15
|
-
const iv = crypto.randomBytes(24);
|
|
16
|
-
let decipher = crypto.createDecipheriv(algorithm, Buffer.from(password), iv);
|
|
17
|
-
let decrypted = '';
|
|
18
|
-
decipher.on(
|
|
19
|
-
'readable',
|
|
20
|
-
() => {
|
|
21
|
-
const data = decipher.read();
|
|
22
|
-
if (data)
|
|
23
|
-
decrypted += data.toString('utf8');
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
decipher.on(
|
|
27
|
-
'end',
|
|
28
|
-
() => {
|
|
29
|
-
return decrypted;
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
decipher.write(myEncryptedText, 'hex');
|
|
34
|
-
decipher.end();
|
|
35
|
-
|
|
36
|
-
return decrypted;
|
|
37
|
-
}
|
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
//import * as log4js from 'log4js';
|
|
2
|
-
//import { LOGGER_CONFIG } from './config/logger.config';
|
|
3
|
-
|
|
4
|
-
import * as sy from 'systeminformation';
|
|
5
|
-
import * as md5 from 'md5';
|
|
6
|
-
|
|
7
|
-
//import { CENTRALIZED_API_BASE_URL } from '../config/config';
|
|
8
|
-
import * as request from 'request-promise-native';
|
|
9
|
-
import { RoutesCentralized } from './routes-centralized';
|
|
10
|
-
import { InconcertEncrypt, InconcertDecrypt } from './crypt';
|
|
11
|
-
import * as moment from 'moment';
|
|
12
|
-
|
|
13
|
-
// Importo funciones para manejo de archivos
|
|
14
|
-
import { ReadFileContent, GetFolderTree, CopyFile, DeleteFile, ExistInFileSystem, CreateFolder } from './shared/file-manager';
|
|
15
|
-
|
|
16
|
-
// Inicializo los logs
|
|
17
|
-
//log4js.configure(LOGGER_CONFIG);
|
|
18
|
-
|
|
19
|
-
// Obtengo logger
|
|
20
|
-
//let logger: log4js.Logger = log4js.getLogger('ServerScripts');
|
|
21
|
-
|
|
22
|
-
const fs = require('fs');
|
|
23
|
-
|
|
24
|
-
//import { DummyPromise } from './shared/promises.shared';
|
|
25
|
-
|
|
26
|
-
// Billing.
|
|
27
|
-
const CENTRALIZED_API_BASE_URL: string = 'http://localhost:9002/';
|
|
28
|
-
//const CENTRALIZED_API_BASE_URL: string = 'https://billing-test.inconcertcc.com/';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Método para hacer el request al servidor centralizado, se recibe el body (data)
|
|
32
|
-
export function InconcertRequest(installationId : string, path : string, data : any) : Promise<any> {
|
|
33
|
-
let systemInformationData: any = null;
|
|
34
|
-
let route:string = RoutesCentralized[path];
|
|
35
|
-
|
|
36
|
-
return DummyPromise()
|
|
37
|
-
.then(
|
|
38
|
-
result => {
|
|
39
|
-
// Validamos que retorne datos.
|
|
40
|
-
if (installationId && route && data)
|
|
41
|
-
// Instanciamos la información del servidor
|
|
42
|
-
return GetSystemInformation(installationId);
|
|
43
|
-
else
|
|
44
|
-
throw 'SERVER_ERROR_MISSING_REQUIRED_PARAMETERS';
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
.then(
|
|
48
|
-
result => {
|
|
49
|
-
// Asignamos el valor de la función GetSystemInformation.
|
|
50
|
-
systemInformationData = result;
|
|
51
|
-
|
|
52
|
-
let plaformHash: string = '';
|
|
53
|
-
|
|
54
|
-
if (systemInformationData) {
|
|
55
|
-
// Obtenemos el contenido en formato md5.
|
|
56
|
-
plaformHash = GenerateMD5Content(systemInformationData);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Configuramos el objeto para realizar el request.
|
|
60
|
-
let options: any = {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
uri: CENTRALIZED_API_BASE_URL + route ,
|
|
63
|
-
body: data,
|
|
64
|
-
headers: {
|
|
65
|
-
'Content-Type': 'application/json',
|
|
66
|
-
'Platform-Hash': plaformHash
|
|
67
|
-
},
|
|
68
|
-
json: true, // Automáticamente stringifies body a JSON.
|
|
69
|
-
resolveWithFullResponse: false
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return request(options);
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
.then(
|
|
76
|
-
result => {
|
|
77
|
-
// Si falla el request retornamor mensaje de fallo
|
|
78
|
-
if (result === null)
|
|
79
|
-
throw 'SERVER_ERROR_EXTERNAL_REQUEST_FAILED';
|
|
80
|
-
|
|
81
|
-
// Retornamos el resultado del request
|
|
82
|
-
return Promise.resolve(result);
|
|
83
|
-
}
|
|
84
|
-
)
|
|
85
|
-
.catch(
|
|
86
|
-
(err: any) => {
|
|
87
|
-
|
|
88
|
-
// Obtenemos mensajes de error.
|
|
89
|
-
let clientMsg: string = (typeof err === 'string' ? err : 'Cannot process request');
|
|
90
|
-
let errorMsg: string = (typeof err === 'string' ? err : err.message || err.description || 'SERVER_ERROR_REQUESTING_ERROR');
|
|
91
|
-
|
|
92
|
-
// Escribo el error en el log.
|
|
93
|
-
//logger.error(errorMsg);
|
|
94
|
-
|
|
95
|
-
// Hago reject y devuelvo el error.
|
|
96
|
-
return Promise.reject(err);
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Método para obtener la información del sistema donde se encuenta instalado.
|
|
102
|
-
export function GetSystemInformation(instalationId: string): Promise<any> {
|
|
103
|
-
|
|
104
|
-
// Definimos variable que contendrá la información del sistema necesaria.
|
|
105
|
-
let systemInformationData: any = {
|
|
106
|
-
installationId: instalationId,
|
|
107
|
-
macAddress: '',
|
|
108
|
-
publicIp: ''
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return DummyPromise()
|
|
112
|
-
.then(
|
|
113
|
-
(result: any) => {
|
|
114
|
-
// Solicitamos a la librería las interfaces de red
|
|
115
|
-
let sys = sy.networkInterfaces();
|
|
116
|
-
|
|
117
|
-
// Por defecto, retorna información de las tarjetas que se tengan instaladas. Se debe filtrar por la tarjeta de red que se encuentre habilitada.
|
|
118
|
-
return sys;
|
|
119
|
-
}
|
|
120
|
-
)
|
|
121
|
-
.then(
|
|
122
|
-
(result: sy.Systeminformation.NetworkInterfacesData[]) => {
|
|
123
|
-
if (result === null)
|
|
124
|
-
throw 'SERVER_ERROR_NOT_FOUND_NETWORK_INTERFACE_INFORMATION';
|
|
125
|
-
|
|
126
|
-
// Validamos que existan datos.
|
|
127
|
-
if (result && result.length) {
|
|
128
|
-
|
|
129
|
-
// Declaramos un objeto para el resultados válido
|
|
130
|
-
let myNetworkInterface : any = null;
|
|
131
|
-
|
|
132
|
-
// Recuperamos los datos de la interface de red activa
|
|
133
|
-
myNetworkInterface = result.filter(r => r.operstate === 'up')[0];
|
|
134
|
-
|
|
135
|
-
// Asignamos la mac
|
|
136
|
-
//systemInformationData.macAddress = result[0].mac;
|
|
137
|
-
systemInformationData.macAddress = myNetworkInterface.mac;
|
|
138
|
-
systemInformationData.ip = myNetworkInterface.ip4;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Retornamos el objeto con los datos recopilados.
|
|
142
|
-
return Promise.resolve(systemInformationData);
|
|
143
|
-
}
|
|
144
|
-
)
|
|
145
|
-
.catch(
|
|
146
|
-
(err: any) => {
|
|
147
|
-
// Retornamos false.
|
|
148
|
-
//return Promise.resolve(false);
|
|
149
|
-
|
|
150
|
-
// Obtengo mensaje de error.
|
|
151
|
-
let errorMsg: string = (err && err.procName ? 'Error al ejecutar \'' + err.procName + '\': ' : 'Error al ejecutar consulta: ') + (err ? typeof err === 'string' ? err : err.message || err.description || '' : '');
|
|
152
|
-
|
|
153
|
-
// Hago reject y devuelvo el error.
|
|
154
|
-
return Promise.reject(err);
|
|
155
|
-
}
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Método para general el platformHash
|
|
160
|
-
export function GenerateMD5Content(data: any): string {
|
|
161
|
-
let result: string = '';
|
|
162
|
-
|
|
163
|
-
// Validamos que no sea null.
|
|
164
|
-
if (data) {
|
|
165
|
-
// Generamos el contenido de archivo .lic con el formato adecuado y luego lo convertimos en md5.
|
|
166
|
-
result += data.installationId;
|
|
167
|
-
result += data.macAddress;
|
|
168
|
-
//result += data.baseboardSerialNumber;
|
|
169
|
-
|
|
170
|
-
result = md5(result);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Retornamos contenido en formato md5.
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function DummyPromise(): Promise<boolean> {
|
|
178
|
-
// Devuelvo promesa dummy que siempre resuelve true
|
|
179
|
-
return new Promise(function(resolve, reject) {
|
|
180
|
-
resolve(true);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function SleepPromise(secondTime: number): Promise<boolean> {
|
|
185
|
-
// Devuelvo promesa dummy que siempre resuelve true
|
|
186
|
-
return new Promise(function(resolve, reject) {
|
|
187
|
-
setTimeout(resolve,(1000 * secondTime));
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/***********************************************************************/
|
|
193
|
-
/*****************************File.ts***********************************/
|
|
194
|
-
/***********************************************************************/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// Ruta donde guardaremos los registros txt de Speech & Quality
|
|
198
|
-
const rootPath : string = '/sq/';
|
|
199
|
-
// Ruta de la carpeta donde guardaremos el registro general
|
|
200
|
-
const storagePath : string = rootPath + 'storage/';
|
|
201
|
-
// Ruta para el archivo de registro general
|
|
202
|
-
const generalFilePath : string = rootPath + 'storage/file.txt';
|
|
203
|
-
// Ruta de carpeta para los archivos segmentados pendientes de enviar al servidor centralizado
|
|
204
|
-
const segmentedFileFolderPath : string = rootPath + 'storage/out/';
|
|
205
|
-
// Ruta de carpeta para los archivos segmentados ya enviados y procesados en el servidor centralizado
|
|
206
|
-
const completedFileFolderPath : string = rootPath + 'storage/completed/';
|
|
207
|
-
|
|
208
|
-
// Función que verificará que existan las carpetas requeridas para el componente intermedio
|
|
209
|
-
export function InconcertCheckSystemFolder() : Promise<boolean> {
|
|
210
|
-
return DummyPromise()
|
|
211
|
-
.then(
|
|
212
|
-
result => {
|
|
213
|
-
// Creamos la carpeta sq
|
|
214
|
-
return CreateFolder(rootPath);
|
|
215
|
-
}
|
|
216
|
-
)
|
|
217
|
-
.then(
|
|
218
|
-
result => {
|
|
219
|
-
// Creamos la carpeta storage
|
|
220
|
-
return CreateFolder(storagePath);
|
|
221
|
-
}
|
|
222
|
-
)
|
|
223
|
-
.then(
|
|
224
|
-
result => {
|
|
225
|
-
// Creamos la carpeta out
|
|
226
|
-
return CreateFolder(segmentedFileFolderPath);
|
|
227
|
-
}
|
|
228
|
-
)
|
|
229
|
-
.then(
|
|
230
|
-
result => {
|
|
231
|
-
// Creamos la carpeta completed
|
|
232
|
-
return CreateFolder(completedFileFolderPath);
|
|
233
|
-
}
|
|
234
|
-
)
|
|
235
|
-
.then(
|
|
236
|
-
result => {
|
|
237
|
-
// Retornamos el resultado
|
|
238
|
-
return Promise.resolve(result);
|
|
239
|
-
}
|
|
240
|
-
)
|
|
241
|
-
.catch(
|
|
242
|
-
err => {
|
|
243
|
-
return Promise.resolve(false);
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Esta función verifica que exista el archivo de registro general y lo crea en caso no exista
|
|
249
|
-
export function InconcertExistsGeneralFile() : boolean {
|
|
250
|
-
try {
|
|
251
|
-
// Verificamos si existe la ruta
|
|
252
|
-
if (fs.existsSync(generalFilePath)) {
|
|
253
|
-
return true;
|
|
254
|
-
} else {
|
|
255
|
-
|
|
256
|
-
//logger.info('[IntermediateComponent::InconcertExistsGeneralFile] Writing to file: ' + generalFilePath);
|
|
257
|
-
|
|
258
|
-
// Generamos el archivo de la ruta general
|
|
259
|
-
fs.writeFile(generalFilePath, '', function(err) {
|
|
260
|
-
if (err) {
|
|
261
|
-
console.error(err);
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Retornamos true si se creó correctamente
|
|
266
|
-
return true;
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
} catch(err) {
|
|
272
|
-
console.error(err)
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Esta función inserta un registro de texto al archivo de registro principal
|
|
278
|
-
export function InconcertAddDataToGeneralFile(myText : string, myTextStatus ?: string) : boolean {
|
|
279
|
-
// Verifica si existe el archivo de registros general y lo crea de no existir
|
|
280
|
-
if (InconcertExistsGeneralFile()) {
|
|
281
|
-
|
|
282
|
-
if (myTextStatus !== undefined)
|
|
283
|
-
// Ingresamos y escriptamos texto al archivo general
|
|
284
|
-
return InconcertAddEncryptTextToFile(generalFilePath, myText, myTextStatus);
|
|
285
|
-
else
|
|
286
|
-
// Ingresamos y escriptamos texto al archivo general
|
|
287
|
-
return InconcertAddEncryptTextToFile(generalFilePath, myText);
|
|
288
|
-
|
|
289
|
-
} else {
|
|
290
|
-
|
|
291
|
-
if (myTextStatus)
|
|
292
|
-
// Si no existe el archivo de registro general se vuelve a lanzar la función
|
|
293
|
-
return InconcertAddDataToGeneralFile(myText, myTextStatus);
|
|
294
|
-
else
|
|
295
|
-
// Si no existe el archivo de registro general se vuelve a lanzar la función
|
|
296
|
-
return InconcertAddDataToGeneralFile(myText);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Esta función agrega un registro de texto al archivo de registro segmentado
|
|
301
|
-
export function InconcertAddDataToSegmentedFile(myText : string[]) : boolean {
|
|
302
|
-
let blockFileNewNamePath : string = segmentedFileFolderPath + moment().format('x') + '1-NEW.txt';
|
|
303
|
-
let blockFileUpdateNamePath : string = segmentedFileFolderPath + moment().format('x') + '2-UPDATE.txt';
|
|
304
|
-
let blockFileCompletedNamePath : string = segmentedFileFolderPath + moment().format('x') + '3-COMPLETED.txt';
|
|
305
|
-
|
|
306
|
-
// Declaramos variables para contar los registros de cada archivo
|
|
307
|
-
let newInsertCounter = 0;
|
|
308
|
-
let updateInsertCounter = 0;
|
|
309
|
-
let completedInsertCounter = 0;
|
|
310
|
-
|
|
311
|
-
myText.map(
|
|
312
|
-
s => {
|
|
313
|
-
if (s && s.length) {
|
|
314
|
-
let operation = s.split('::');
|
|
315
|
-
if (operation.length === 1) {
|
|
316
|
-
newInsertCounter++
|
|
317
|
-
InconcertAddTextToFile(blockFileNewNamePath, s);
|
|
318
|
-
} else {
|
|
319
|
-
switch (operation[1]) {
|
|
320
|
-
case 'new':
|
|
321
|
-
newInsertCounter++
|
|
322
|
-
InconcertAddTextToFile(blockFileNewNamePath, s);
|
|
323
|
-
break;
|
|
324
|
-
case 'update':
|
|
325
|
-
updateInsertCounter++
|
|
326
|
-
InconcertAddTextToFile(blockFileUpdateNamePath, s);
|
|
327
|
-
break;
|
|
328
|
-
case 'success':
|
|
329
|
-
completedInsertCounter++
|
|
330
|
-
InconcertAddTextToFile(blockFileCompletedNamePath, s);
|
|
331
|
-
break;
|
|
332
|
-
case 'failed':
|
|
333
|
-
completedInsertCounter++
|
|
334
|
-
InconcertAddTextToFile(blockFileCompletedNamePath, s);
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Esta función agrega y encripta un registro de texto al archivo indicado en su input
|
|
346
|
-
export function InconcertAddEncryptTextToFile(myFile : string, myText : string, myTextResult ?: string) : boolean {
|
|
347
|
-
// Declaramos una variable para el texto a insertar
|
|
348
|
-
let insertText = '';
|
|
349
|
-
|
|
350
|
-
// Si existe el input result lo agregamos al final de la cadena de texto
|
|
351
|
-
if (myTextResult !== undefined) {
|
|
352
|
-
insertText += InconcertEncrypt(myText) + '::' + myTextResult;
|
|
353
|
-
} else {
|
|
354
|
-
insertText += InconcertEncrypt(myText);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
fs.appendFileSync(myFile, insertText + '\n');
|
|
359
|
-
} catch (err) {
|
|
360
|
-
console.log('Save failed!');
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// Esta función agrega un registro de texto al archivo indicado en su input
|
|
367
|
-
export function InconcertAddTextToFile(myFile : string, myText : string) : boolean {
|
|
368
|
-
try {
|
|
369
|
-
fs.appendFileSync(myFile, myText + '\n');
|
|
370
|
-
} catch (err) {
|
|
371
|
-
// Generamos el archivo de la ruta general
|
|
372
|
-
fs.writeFile(myFile, '', function(err) {
|
|
373
|
-
if (err) {
|
|
374
|
-
console.error(err);
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// Retornamos true si se creó correctamente
|
|
379
|
-
return true;
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
InconcertAddTextToFile(myFile, myText);
|
|
383
|
-
console.log('Save failed!');
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// Esta función genera un archivo por cada 50 registros existentes en el registro principal
|
|
390
|
-
export function InconcertSplitGeneralFileData() : void {
|
|
391
|
-
// Abrimos el archivo de registro general
|
|
392
|
-
let data = fs.readFileSync(generalFilePath, 'utf-8');
|
|
393
|
-
|
|
394
|
-
// Cantidad de registros para los archivos segmentados
|
|
395
|
-
let blockSize = 50;
|
|
396
|
-
|
|
397
|
-
let content = data.toString().split('\n');
|
|
398
|
-
let totalRows = content.filter(r => r.length > 0).length;
|
|
399
|
-
let blocks = Math.ceil(totalRows / blockSize);
|
|
400
|
-
|
|
401
|
-
// Hacemos un recorrido para los bloques identificados
|
|
402
|
-
for (let i = 0; i < blocks; i++) {
|
|
403
|
-
let blockContent = content.splice(0, blockSize);
|
|
404
|
-
InconcertAddDataToSegmentedFile(blockContent);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
fs.writeFileSync(generalFilePath, content.join('\n'), 'utf-8');
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// Esta función envía los archivos contenidos en la carpeta "out" al servicor centralizado
|
|
411
|
-
export function InconcertSegmentedFileUpload(installationId : string) : Promise<any> {
|
|
412
|
-
// Declaramos un array de string para almacenar los nombres de los archivos
|
|
413
|
-
let segmentedFiles : any[] = [];
|
|
414
|
-
let segmentedNewFiles : any[] = [];
|
|
415
|
-
let segmentedUpdateFiles : any[] = [];
|
|
416
|
-
let segmentedCloseFiles : any[] = [];
|
|
417
|
-
|
|
418
|
-
// Declaramos un objeto para almacenar el resultado de los archivos
|
|
419
|
-
let segmentedFilesResult : any[] = [];
|
|
420
|
-
|
|
421
|
-
return DummyPromise()
|
|
422
|
-
.then(
|
|
423
|
-
result => {
|
|
424
|
-
// Validamos que existen las carpetas del sistema
|
|
425
|
-
return InconcertCheckSystemFolder();
|
|
426
|
-
}
|
|
427
|
-
)
|
|
428
|
-
.then(
|
|
429
|
-
result => {
|
|
430
|
-
// Recuperamos los archivos de la carpeta OUT
|
|
431
|
-
return GetFolderTree(segmentedFileFolderPath);
|
|
432
|
-
}
|
|
433
|
-
)
|
|
434
|
-
.then(
|
|
435
|
-
result => {
|
|
436
|
-
if (result && result.length > 0 && result[0].children && result[0].children.length > 0) {
|
|
437
|
-
// Guardamos en nuestra variable todos los archivos
|
|
438
|
-
segmentedFiles = result[0].children;
|
|
439
|
-
|
|
440
|
-
// Declarramos un PromiseArray para obtener el contenido de cada archivo
|
|
441
|
-
let fileContentPromises : Promise<any>[] = [];
|
|
442
|
-
|
|
443
|
-
/*
|
|
444
|
-
// Recorremos el listado de archivos segmentados (Se quitó porque podrían llegar a demasiados archivos causando mucha carga al servidor)
|
|
445
|
-
segmentedFiles.map(
|
|
446
|
-
f => {
|
|
447
|
-
//logger.info('[IntermediateComponent::InconcertSegmentedFileUpload] Promising read: ' + f.fullPath);
|
|
448
|
-
fileContentPromises.push(ReadFileContent(f.fullPath, 'utf8'));
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
// Recorremos el listado de archivos y tomamos los 15 primeros
|
|
454
|
-
for (let i = 0; i < 25; i++) {
|
|
455
|
-
//logger.info('[IntermediateComponent::InconcertSegmentedFileUpload] Promising read: ' + f.fullPath);
|
|
456
|
-
fileContentPromises.push(ReadFileContent(segmentedFiles[i].fullPath, 'utf8'));
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return Promise.all(fileContentPromises);
|
|
460
|
-
} else {
|
|
461
|
-
throw 'SERVER_ERROR_NOT_FOUND_FILE';
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
)
|
|
465
|
-
.then(
|
|
466
|
-
result => {
|
|
467
|
-
let arrSummary : any[] = [];
|
|
468
|
-
|
|
469
|
-
// Sólo subimos 20 archivos por ejecución
|
|
470
|
-
if (result && result.length) {
|
|
471
|
-
for (let i = 0; i < 25; i++) {
|
|
472
|
-
// Creamos el objeto que enviaremos al servidor centralizado
|
|
473
|
-
let body : any = {
|
|
474
|
-
'installationId' : installationId,
|
|
475
|
-
'file' : segmentedFiles[i].name,
|
|
476
|
-
'data' : result[i]
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
arrSummary.push(body);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/*
|
|
483
|
-
result.map(
|
|
484
|
-
(r, i) => {
|
|
485
|
-
// Sólo subimos 20 archivos por ejecución
|
|
486
|
-
if (i < 20) {
|
|
487
|
-
// Creamos el objeto que enviaremos al servidor centralizado
|
|
488
|
-
let body : any = {
|
|
489
|
-
'installationId' : installationId,
|
|
490
|
-
'file' : segmentedFiles[i].name,
|
|
491
|
-
'data' : r
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
arrSummary.push(body);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
)
|
|
498
|
-
*/
|
|
499
|
-
} else {
|
|
500
|
-
throw 'SERVER_ERROR_NOT_FOUND_FILE_CONTENT';
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return InconcertSegmenteFileRecursiveSend(arrSummary);
|
|
504
|
-
}
|
|
505
|
-
)
|
|
506
|
-
.then(
|
|
507
|
-
result => {
|
|
508
|
-
if (result && result.status) {
|
|
509
|
-
return Promise.resolve({'res' : true, 'data' : result});
|
|
510
|
-
} else
|
|
511
|
-
throw 'SERVER_ERROR_MASSIVE_UPLOAD_FAILED';
|
|
512
|
-
}
|
|
513
|
-
)
|
|
514
|
-
.catch(
|
|
515
|
-
err => {
|
|
516
|
-
return Promise.resolve({'res' : false, 'err' : err});
|
|
517
|
-
}
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Función recursiva para enviar los request al servidor centralizado
|
|
522
|
-
function InconcertSegmenteFileRecursiveSend(arrSummary : any[]) : Promise<any> {
|
|
523
|
-
// El array de entrada contiene { 'installationId' : installationId, 'file' : fileName, 'data' : fileTxtContent}
|
|
524
|
-
|
|
525
|
-
// Retiramos un item del array de objetos para trabajar
|
|
526
|
-
let myBody : any = arrSummary.shift();
|
|
527
|
-
|
|
528
|
-
// consulto si tenemos datos en la cola
|
|
529
|
-
return SleepPromise(1)
|
|
530
|
-
.then(result => {
|
|
531
|
-
// Lanzamos el request al servidor centralizado
|
|
532
|
-
return InconcertRequest(myBody.installationId, 'IC_PARAM_URL_BATCH_DETAIL_SAVE', myBody);
|
|
533
|
-
})
|
|
534
|
-
.then(result => {
|
|
535
|
-
// El servidor centralizado retorna en respuesta el estado y nombre del archivo
|
|
536
|
-
if (result === null)
|
|
537
|
-
throw 'SERVER_ERROR_NOT_RECEIVED_RESULT';
|
|
538
|
-
|
|
539
|
-
// Si el resultado del servidor es falso retornamos un throw
|
|
540
|
-
if (result.status !== true) {
|
|
541
|
-
throw 'SERVER_ERROR_FILE_UPLOAD_FAILED';
|
|
542
|
-
|
|
543
|
-
// Si la respuesta es true movemos el archivo a la carpeta Completed
|
|
544
|
-
} else {
|
|
545
|
-
//logger.info('[IntermediateComponent::InconcertSegmenteFileRecursiveSend] Moving file to Completed folder: ' + myBody.file + '::' + result.data);
|
|
546
|
-
|
|
547
|
-
// Movemos el archivo a la carpeta Completed
|
|
548
|
-
return InconcertSegmentedFileToCompletedFolder(result.data);
|
|
549
|
-
}
|
|
550
|
-
})
|
|
551
|
-
.then(result => {
|
|
552
|
-
if (result) {
|
|
553
|
-
if (arrSummary.length > 0) {
|
|
554
|
-
//logger.info('[IntermediateComponent::InconcertSegmenteFileRecursiveSend] Launching recursice function: ' + arrSummary.length);
|
|
555
|
-
|
|
556
|
-
return InconcertSegmenteFileRecursiveSend(arrSummary);
|
|
557
|
-
} else
|
|
558
|
-
return Promise.resolve({'res' : true, 'data' : result});
|
|
559
|
-
} else {
|
|
560
|
-
throw 'SERVER_ERROR_FILE_MOVE_FAILED';
|
|
561
|
-
}
|
|
562
|
-
})
|
|
563
|
-
.catch(err => {
|
|
564
|
-
return Promise.resolve({'res' : false, 'err' : err});
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
function InconcertSegmentedFileToCompletedFolder(segmentedFileName : string) : Promise<any> {
|
|
569
|
-
|
|
570
|
-
let sourcePath : string = segmentedFileFolderPath + segmentedFileName;
|
|
571
|
-
let targetPath: string = completedFileFolderPath + segmentedFileName;
|
|
572
|
-
|
|
573
|
-
return DummyPromise()
|
|
574
|
-
.then(
|
|
575
|
-
result => {
|
|
576
|
-
// Verificamos si existe la carpeta Completed
|
|
577
|
-
return CreateFolder(completedFileFolderPath)
|
|
578
|
-
}
|
|
579
|
-
)
|
|
580
|
-
.then(
|
|
581
|
-
result => {
|
|
582
|
-
// Copiamos el archivo a la carpeta Completed
|
|
583
|
-
return CopyFile(sourcePath, targetPath);
|
|
584
|
-
}
|
|
585
|
-
)
|
|
586
|
-
.then(
|
|
587
|
-
result => {
|
|
588
|
-
if (result) {
|
|
589
|
-
return DeleteFile(sourcePath);
|
|
590
|
-
} else {
|
|
591
|
-
throw 'SERVER_ERROR_COPY_FILE_FAILED';
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
)
|
|
595
|
-
.then(
|
|
596
|
-
result => {
|
|
597
|
-
if (result) {
|
|
598
|
-
return Promise.resolve(true);
|
|
599
|
-
} else {
|
|
600
|
-
throw 'SERVER_ERROR_DELETE_FILE_FAILED';
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
)
|
|
604
|
-
.catch(
|
|
605
|
-
err => {
|
|
606
|
-
return Promise.resolve(false);
|
|
607
|
-
}
|
|
608
|
-
)
|
|
609
|
-
}
|