blob: 53078b52e6e3cbafaf2b265097625b313b731b65 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18/**
19 * @file Provider for Shared Service
20 */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053021import { isNullOrUndefined } from 'util';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
23import { EventEmitter, Injectable, Output } from '@angular/core';
24import { FormArray, FormGroup } from '@angular/forms';
25import { Router } from '@angular/router';
Barath Kumar R09cd4ec2020-07-07 16:12:32 +053026import { TranslateService } from '@ngx-translate/core';
Barath Kumar R16070582021-02-08 18:19:35 +053027import {
28 CONSTANTNUMBER,
29 DOMAINS,
30 ERRORDATA,
31 FILESETTINGS,
32 GETAPIURLHEADER,
33 PACKAGEINFO,
34 PAGERSMARTTABLE,
35 SMARTTABLECLASS,
36 TARSETTINGS,
37 TYPESECTION
38} from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053039import { environment } from 'environment';
40import * as HttpStatus from 'http-status-codes';
41import * as untar from 'js-untar';
42import * as pako from 'pako';
43import { RestService } from 'RestService';
Barath Kumar R16070582021-02-08 18:19:35 +053044import { Observable } from 'rxjs';
45import { map } from 'rxjs/operators';
kumaran.m3b4814a2020-05-01 19:48:54 +053046
47/** This is added globally by the tar.js library */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053048// eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +053049declare const Tar: any;
50
51/**
52 * An Injectable is a class adorned with the @Injectable decorator function.
53 * @Injectable takes a metadata object that tells Angular how to compile and run module code
54 */
55@Injectable({
56 providedIn: 'root'
57})
58/** Exporting a class @exports SharedService */
59export class SharedService {
60 /** call the parent using event information @private */
61 @Output() public dataEvent: EventEmitter<{}> = new EventEmitter<{}>();
62
63 /** Variables to hold regexp pattern for URL */
kumaran.m3b4814a2020-05-01 19:48:54 +053064 public REGX_URL_PATTERN: RegExp = new RegExp(/^(http?|ftp|https):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z0-9]{2,15})(:((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4})))*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/);
65
66 /** Variables to hold regexp pattern for IP Address */
67 public REGX_IP_PATTERN: RegExp = new RegExp(/^(?:(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(?!$)|$)){4}$/);
68
69 /** Variables to hold regexp pattern for Port Number */
kumaran.m3b4814a2020-05-01 19:48:54 +053070 public REGX_PORT_PATTERN: RegExp = new RegExp(/^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$/);
71
72 /** Variables to hold regexp pattern for DPID */
73 public REGX_DPID_PATTERN: RegExp = new RegExp(/^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}$/);
74
75 /** Variable to hold regexp pattern for password */
kumaran.m3b4814a2020-05-01 19:48:54 +053076 public REGX_PASSWORD_PATTERN: RegExp = new RegExp(/^.*(?=.{8,})((?=.*[!@#$%^&*()\-_=+{};:,<.>]){1})(?=.*\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$/);
77
Barath Kumar R1245fc82021-04-16 13:34:06 +053078 /** Variables to hold regexp pattern for Latitude */
79 public REGX_LAT_PATTERN: RegExp = new RegExp(/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,15})?))$/);
80
81 /** Variables to hold regexp pattern for Longitude */
Barath Kumar R1245fc82021-04-16 13:34:06 +053082 public REGX_LONG_PATTERN: RegExp = new RegExp(/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,15})?))$/);
83
Barath Kumar R403234e2020-07-07 15:48:58 +053084 /** Variables to hold maxlength for the description @public */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053085 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R403234e2020-07-07 15:48:58 +053086 public MAX_LENGTH_DESCRIPTION: number = 500;
87
88 /** Variables to hold maxlength for the name @public */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053089 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R403234e2020-07-07 15:48:58 +053090 public MAX_LENGTH_NAME: number = 50;
91
kumaran.m3b4814a2020-05-01 19:48:54 +053092 /** FormGroup instance added to the form @ html @public */
93 public formGroup: FormGroup;
94
95 /** Controls the go to top button on scroll @public */
96 public showGotoTop: boolean;
97
98 /** Holds OSM Version value @public */
99 public osmVersion: string;
100
101 /** express number for time manupulation -2 */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530102 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
kumaran.m3b4814a2020-05-01 19:48:54 +0530103 private epochTimeMinus2: number = -2;
104
105 /** express number for time manupulation 1000 */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530106 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
kumaran.m3b4814a2020-05-01 19:48:54 +0530107 private epochTime1000: number = 1000;
108
109 /** Random string generator length */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530110 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
kumaran.m3b4814a2020-05-01 19:48:54 +0530111 private randomStringLength: number = 4;
112
113 /** Instance of the rest service @private */
114 private restService: RestService;
115
116 /** Service holds the router information @private */
117 private router: Router;
118
Barath Kumar R208bef22020-07-07 12:28:04 +0530119 /** Random color string generator length @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530120 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
Barath Kumar R208bef22020-07-07 12:28:04 +0530121 private colorStringLength: number = 256;
122
kumaran.m3b4814a2020-05-01 19:48:54 +0530123 /** Check for the root directory @private */
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530124 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
kumaran.m3b4814a2020-05-01 19:48:54 +0530125 private directoryCount: number = 2;
126
Barath Kumar R09cd4ec2020-07-07 16:12:32 +0530127 /** Contains tranlsate instance @private */
128 private translateService: TranslateService;
129
130 constructor(restService: RestService, router: Router, translateService: TranslateService) {
kumaran.m3b4814a2020-05-01 19:48:54 +0530131 this.restService = restService;
132 this.router = router;
Barath Kumar R09cd4ec2020-07-07 16:12:32 +0530133 this.translateService = translateService;
kumaran.m3b4814a2020-05-01 19:48:54 +0530134 }
135
136 /** convert epoch time function @public */
137 public convertEpochTime(unixtimestamp: number): string {
Barath Kumar R09cd4ec2020-07-07 16:12:32 +0530138 if (!isNullOrUndefined(unixtimestamp)) {
139 const monthsArr: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
140 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
141 const date: Date = new Date(unixtimestamp * this.epochTime1000);
142 const year: number = date.getFullYear();
143 const month: string = monthsArr[date.getMonth()];
144 const day: number = date.getDate();
145 const hours: number = date.getHours();
146 const minutes: string = '0' + date.getMinutes();
147 const seconds: string = '0' + date.getSeconds();
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530148 // eslint-disable-next-line deprecation/deprecation
Barath Kumar R09cd4ec2020-07-07 16:12:32 +0530149 return month + '-' + day + '-' + year + ' ' + hours + ':' + minutes.substr(this.epochTimeMinus2) + ':'
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530150 // eslint-disable-next-line deprecation/deprecation
Barath Kumar R09cd4ec2020-07-07 16:12:32 +0530151 + seconds.substr(this.epochTimeMinus2);
152 }
153 return this.translateService.instant('NODATE');
kumaran.m3b4814a2020-05-01 19:48:54 +0530154 }
155
156 /** Download Files function @public */
Barath Kumar R063a3f12020-12-29 16:35:09 +0530157 public downloadFiles(name: string, binaryData: Blob[], filetype: string): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530158 const downloadLink: HTMLAnchorElement = document.createElement('a');
159 downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, { type: filetype }));
Barath Kumar R063a3f12020-12-29 16:35:09 +0530160 if (name !== undefined) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530161 // eslint-disable-next-line @typescript-eslint/no-explicit-any
162 const newVariable: any = window.navigator;
163 if (newVariable.msSaveOrOpenBlob) {
164 newVariable.msSaveBlob(new Blob(binaryData, { type: filetype }), 'OSM_Export_' + name + '.tar.gz');
kumaran.m3b4814a2020-05-01 19:48:54 +0530165 } else {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530166 downloadLink.setAttribute('download', 'OSM_Export_' + name + '.tar.gz');
kumaran.m3b4814a2020-05-01 19:48:54 +0530167 document.body.appendChild(downloadLink);
168 downloadLink.click();
169 }
170 }
171 }
172
173 /** Call this method after delete perform action is completed in the ng-smart-table data @public */
174 public callData(): void {
175 this.dataEvent.emit();
176 }
177
178 /** Generate random string @public */
179 public randomString(): string {
180 const chars: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
181 let result: string = '';
kumaran.m3b4814a2020-05-01 19:48:54 +0530182 for (let randomStringRef: number = this.randomStringLength; randomStringRef > 0; --randomStringRef) {
183 result += chars[Math.floor(Math.random() * chars.length)];
184 }
185 return result;
186 }
Barath Kumar R16070582021-02-08 18:19:35 +0530187
kumaran.m3b4814a2020-05-01 19:48:54 +0530188 /** Function to read uploaded file String @public */
189 public async getFileString(files: FileList, fileType: string): Promise<string | ArrayBuffer> {
190 const reader: FileReader = new FileReader();
191 return new Promise<string | ArrayBuffer>((resolve: Function, reject: Function): void => {
192 if (this.vaildataFileInfo(files[0], fileType)) {
193 this.readFileContent(reader, files[0], fileType);
194 } else {
195 reject('typeError');
196 }
197 reader.onload = (): void => {
198 if (reader.result === null) {
199 reject('contentError');
200 }
201 resolve(reader.result);
202 };
203 reader.onerror = (event: Event): void => {
204 reject('contentError');
205 };
206 });
207 }
Barath Kumar R16070582021-02-08 18:19:35 +0530208
kumaran.m3b4814a2020-05-01 19:48:54 +0530209 /** Method to handle tar and tar.gz file for shared YAML file content @public */
210 public async targzFile(packageInfo: PACKAGEINFO): Promise<string | ArrayBuffer> {
211 return new Promise<string | ArrayBuffer>((resolve: Function, reject: Function): void => {
212 const httpOptions: GETAPIURLHEADER = this.getHttpOptions();
213 let apiUrl: string = '';
214 apiUrl = packageInfo.packageType === 'nsd' ? environment.NSDESCRIPTORS_URL + '/' + packageInfo.id + '/nsd_content' :
215 environment.VNFPACKAGES_URL + '/' + packageInfo.id + '/package_content';
Barath Kumar R16070582021-02-08 18:19:35 +0530216 this.restService.getResource(apiUrl, httpOptions).subscribe((response: ArrayBuffer): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530217 try {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530218 // eslint-disable-next-line @typescript-eslint/no-explicit-any
kumaran.m3b4814a2020-05-01 19:48:54 +0530219 const tar: any = new Tar();
220 const originalInput: Uint8Array = pako.inflate(response, { to: 'Uint8Array' });
Barath Kumar R16070582021-02-08 18:19:35 +0530221 untar(originalInput.buffer).then((extractedFiles: TARSETTINGS[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530222 const getFoldersFiles: {}[] = extractedFiles;
223 const folderNameStr: string = extractedFiles[0].name;
Barath Kumar R16070582021-02-08 18:19:35 +0530224 getFoldersFiles.forEach((value: TARSETTINGS): void => {
Barath Kumar Rdb1aeb02020-10-13 18:14:16 +0530225 const fileValueObj: FILESETTINGS = this.createFileValueObject(value);
kumaran.m3b4814a2020-05-01 19:48:54 +0530226 const getRootFolder: string[] = value.name.split('/');
227 if (value.name.startsWith(folderNameStr) &&
228 (value.name.endsWith('.yaml') || value.name.endsWith('.yml')) &&
229 getRootFolder.length === this.directoryCount) {
Barath Kumar Rdb1aeb02020-10-13 18:14:16 +0530230 tar.append(value.name, packageInfo.descriptor, fileValueObj);
kumaran.m3b4814a2020-05-01 19:48:54 +0530231 } else {
232 if (value.type !== 'L') {
Barath Kumar Rdb1aeb02020-10-13 18:14:16 +0530233 tar.append(value.name, new Uint8Array(value.buffer), fileValueObj);
kumaran.m3b4814a2020-05-01 19:48:54 +0530234 }
235 }
236 });
237 const out: Uint8Array = tar.out;
238 const originalOutput: Uint8Array = pako.gzip(out);
239 resolve(originalOutput.buffer);
Barath Kumar R16070582021-02-08 18:19:35 +0530240 }, (err: string): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530241 reject('');
242 });
243 } catch (e) {
244 reject('');
245 }
Barath Kumar R16070582021-02-08 18:19:35 +0530246 }, (error: HttpErrorResponse): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530247 if (error.status === HttpStatus.NOT_FOUND || error.status === HttpStatus.UNAUTHORIZED) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530248 this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
249 // Catch Navigation Error
250 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530251 } else {
252 this.restService.handleError(error, 'get');
253 reject('');
254 }
255 });
256 });
257 }
Barath Kumar R16070582021-02-08 18:19:35 +0530258
Barath Kumar Rdb1aeb02020-10-13 18:14:16 +0530259 /** Method to return the file information @public */
260 public createFileValueObject(value: TARSETTINGS): FILESETTINGS {
261 return {
262 type: value.type,
263 linkname: value.linkname,
264 owner: value.uname,
265 group: value.gname
266 };
267 }
Barath Kumar R16070582021-02-08 18:19:35 +0530268
kumaran.m3b4814a2020-05-01 19:48:54 +0530269 /** Method to check given string is JSON or not @public */
270 public checkJson(jsonString: string): boolean {
271 jsonString = jsonString.replace(/'/g, '"');
272 try {
273 JSON.parse(jsonString);
274 } catch (e) {
275 return false;
276 }
277 return true;
278 }
Barath Kumar R16070582021-02-08 18:19:35 +0530279
kumaran.m3b4814a2020-05-01 19:48:54 +0530280 /** Clean the form before submit @public */
Barath Kumar Rd477b852020-07-07 15:24:05 +0530281 public cleanForm(formGroup: FormGroup, formName?: String): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530282 Object.keys(formGroup.controls).forEach((key: string) => {
Barath Kumar Rd477b852020-07-07 15:24:05 +0530283 if ((!isNullOrUndefined((formGroup.get(key) as FormArray | FormGroup).controls)) && key !== 'config') {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530284 // eslint-disable-next-line @typescript-eslint/no-shadow
kumaran.m3b4814a2020-05-01 19:48:54 +0530285 for (const { item, index } of (formGroup.get(key).value).map((item: {}, index: number) => ({ item, index }))) {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530286 // eslint-disable-next-line security/detect-object-injection
kumaran.m3b4814a2020-05-01 19:48:54 +0530287 const newFormGroup: FormGroup = (formGroup.get(key) as FormArray).controls[index] as FormGroup;
288 this.cleanForm(newFormGroup);
289 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530290 } else if (formGroup.get(key).value !== undefined && formGroup.get(key).value !== null && key !== 'config') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530291 if (!Array.isArray(formGroup.get(key).value)) {
292 if (typeof formGroup.get(key).value === 'string') {
293 formGroup.get(key).setValue(formGroup.get(key).value.trim());
294 }
295 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530296 } else if (key === 'config' && formName === 'vim') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530297 const newFormGroup: FormGroup = formGroup.get(key) as FormGroup;
298 this.cleanForm(newFormGroup);
299 }
300 });
301 }
Barath Kumar R16070582021-02-08 18:19:35 +0530302
kumaran.m3b4814a2020-05-01 19:48:54 +0530303 /** Method to return the config of pager value for ngSmarttable @public */
304 public paginationPagerConfig(): PAGERSMARTTABLE {
305 return {
306 display: true,
307 perPage: environment.paginationNumber
308 };
309 }
Barath Kumar R16070582021-02-08 18:19:35 +0530310
kumaran.m3b4814a2020-05-01 19:48:54 +0530311 /** Method to return the class for the table for ngSmarttable @public */
312 public tableClassConfig(): SMARTTABLECLASS {
313 return {
314 class: 'table list-data'
315 };
316 }
Barath Kumar R16070582021-02-08 18:19:35 +0530317
kumaran.m3b4814a2020-05-01 19:48:54 +0530318 /** Method to return all languages name and its code @public */
319 public languageCodeList(): {}[] {
320 return [
321 { code: 'en', language: 'English' },
322 { code: 'es', language: 'Spanish' },
323 { code: 'pt', language: 'Portuguese' },
324 { code: 'de', language: 'German' }
325 ];
326 }
Barath Kumar R16070582021-02-08 18:19:35 +0530327
kumaran.m3b4814a2020-05-01 19:48:54 +0530328 /** Fetch OSM Version @public */
329 public fetchOSMVersion(): void {
Barath Kumar R16070582021-02-08 18:19:35 +0530330 this.restService.getResource(environment.OSM_VERSION_URL).subscribe((res: { version: string }): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530331 const version: string[] = res.version.split('+');
332 if (!isNullOrUndefined(version[0])) {
333 this.osmVersion = version[0];
334 } else {
335 this.osmVersion = null;
336 }
Barath Kumar R16070582021-02-08 18:19:35 +0530337 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530338 this.osmVersion = null;
339 this.restService.handleError(error, 'get');
340 });
341 }
Barath Kumar R16070582021-02-08 18:19:35 +0530342
Barath Kumar R208bef22020-07-07 12:28:04 +0530343 /** Random RGB color code generator @public */
344 public generateColor(): string {
345 const x: number = Math.floor(Math.random() * this.colorStringLength);
346 const y: number = Math.floor(Math.random() * this.colorStringLength);
347 const z: number = Math.floor(Math.random() * this.colorStringLength);
348 return 'rgb(' + x + ',' + y + ',' + z + ')';
349 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530350
351 /** Add custom name/tag to the dropdown @public */
352 public addCustomTag(tag: string): string {
353 return tag;
354 }
355
Barath Kumar Rd22b0942020-07-14 11:05:24 +0530356 /** Fetch file extension @public */
357 public fetchFileExtension(fileInfo: FileList): string {
358 return fileInfo[0].name.substring(fileInfo[0].name.lastIndexOf('.') + 1);
359 }
360
Barath Kumar R16070582021-02-08 18:19:35 +0530361 /** Get domain name @private */
362 public getDomainName(): Observable<TYPESECTION[]> {
363 return this.restService.getResource(environment.DOMAIN_URL).pipe(map((domains: DOMAINS): TYPESECTION[] => {
364 const domainList: TYPESECTION[] = [];
365 try {
366 let domainNames: string[] = [];
367 if (!isNullOrUndefined(domains.project_domain_name)) {
368 domainNames = domainNames.concat(domains.project_domain_name.split(','));
369 }
370 if (!isNullOrUndefined(domains.user_domain_name)) {
371 domainNames = domainNames.concat(domains.user_domain_name.split(','));
372 }
373 domainNames = Array.from(new Set(domainNames));
374 if (domainNames.length > 0) {
375 domainNames.forEach((domainName: string): void => {
376 if (!domainName.endsWith(':ro')) {
377 domainList.push({ title: domainName, value: domainName });
378 }
379 });
380 }
381 return domainList;
382 } catch (e) {
383 return domainList;
384 }
385 }));
386 }
387
kumaran.m3b4814a2020-05-01 19:48:54 +0530388 /** Method to validate file extension and size @private */
389 private vaildataFileInfo(fileInfo: File, fileType: string): boolean {
390 const extension: string = fileInfo.name.substring(fileInfo.name.lastIndexOf('.') + 1);
391 const packageSize: number = CONSTANTNUMBER.oneMB * environment.packageSize;
Barath Kumar Rd477b852020-07-07 15:24:05 +0530392 if (fileType === 'yaml' && (extension.toLowerCase() === 'yaml' || extension.toLowerCase() === 'yml')
393 && fileInfo.size <= packageSize) {
394 return true;
395 } else if (extension.toLowerCase() === fileType && fileInfo.size <= packageSize) {
kumaran.m3b4814a2020-05-01 19:48:54 +0530396 return true;
397 }
398 return false;
399 }
Barath Kumar R16070582021-02-08 18:19:35 +0530400
kumaran.m3b4814a2020-05-01 19:48:54 +0530401 /** Method to read file content based on type @private */
402 private readFileContent(reader: FileReader, fileInfo: File, fileType: string): void {
403 if (fileType === 'gz') {
404 reader.readAsArrayBuffer(fileInfo);
405 } else {
406 reader.readAsText(fileInfo);
407 }
408 }
Barath Kumar R16070582021-02-08 18:19:35 +0530409
kumaran.m3b4814a2020-05-01 19:48:54 +0530410 /** Method to handle http options @public */
411 private getHttpOptions(): GETAPIURLHEADER {
412 return {
413 headers: new HttpHeaders({
414 Accept: 'application/gzip, application/json',
415 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
416 }),
417 responseType: 'arraybuffer'
418 };
419 }
420}