X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FSharedService.ts;h=26e5e0791e5b86cd8290c7e49384284c1e141291;hb=43dec1560d59d84cbc5d9290549ac987f1c285ce;hp=d35e41d3c047319378c1d1b4228f639b38367262;hpb=09cd4ecd880a8c04282cc3388d37d559f07327a9;p=osm%2FNG-UI.git diff --git a/src/services/SharedService.ts b/src/services/SharedService.ts index d35e41d..26e5e07 100644 --- a/src/services/SharedService.ts +++ b/src/services/SharedService.ts @@ -23,7 +23,7 @@ import { EventEmitter, Injectable, Output } from '@angular/core'; import { FormArray, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { CONSTANTNUMBER, ERRORDATA, GETAPIURLHEADER, PACKAGEINFO, PAGERSMARTTABLE, SMARTTABLECLASS, TARSETTINGS } from 'CommonModel'; +import { CONSTANTNUMBER, ERRORDATA, FILESETTINGS, GETAPIURLHEADER, PACKAGEINFO, PAGERSMARTTABLE, SMARTTABLECLASS, TARSETTINGS } from 'CommonModel'; import { environment } from 'environment'; import * as HttpStatus from 'http-status-codes'; import * as untar from 'js-untar'; @@ -129,14 +129,14 @@ export class SharedService { } /** Download Files function @public */ - public downloadFiles(shortName: string, binaryData: Blob[], filetype: string): void { + public downloadFiles(name: string, binaryData: Blob[], filetype: string): void { const downloadLink: HTMLAnchorElement = document.createElement('a'); downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, { type: filetype })); - if (shortName !== undefined) { + if (name !== undefined) { if (window.navigator.msSaveOrOpenBlob) { - window.navigator.msSaveBlob(new Blob(binaryData, { type: filetype }), 'OSM_Export_' + shortName + '.tar.gz'); + window.navigator.msSaveBlob(new Blob(binaryData, { type: filetype }), 'OSM_Export_' + name + '.tar.gz'); } else { - downloadLink.setAttribute('download', 'OSM_Export_' + shortName + '.tar.gz'); + downloadLink.setAttribute('download', 'OSM_Export_' + name + '.tar.gz'); document.body.appendChild(downloadLink); downloadLink.click(); } @@ -194,14 +194,15 @@ export class SharedService { const getFoldersFiles: {}[] = extractedFiles; const folderNameStr: string = extractedFiles[0].name; getFoldersFiles.forEach((value: TARSETTINGS) => { + const fileValueObj: FILESETTINGS = this.createFileValueObject(value); const getRootFolder: string[] = value.name.split('/'); if (value.name.startsWith(folderNameStr) && (value.name.endsWith('.yaml') || value.name.endsWith('.yml')) && getRootFolder.length === this.directoryCount) { - tar.append(value.name, packageInfo.descriptor, { type: value.type }); + tar.append(value.name, packageInfo.descriptor, fileValueObj); } else { if (value.type !== 'L') { - tar.append(value.name, new Uint8Array(value.buffer), { type: value.type }); + tar.append(value.name, new Uint8Array(value.buffer), fileValueObj); } } }); @@ -224,6 +225,15 @@ export class SharedService { }); }); } + /** Method to return the file information @public */ + public createFileValueObject(value: TARSETTINGS): FILESETTINGS { + return { + type: value.type, + linkname: value.linkname, + owner: value.uname, + group: value.gname + }; + } /** Method to check given string is JSON or not @public */ public checkJson(jsonString: string): boolean { jsonString = jsonString.replace(/'/g, '"'); @@ -304,6 +314,11 @@ export class SharedService { return tag; } + /** Fetch file extension @public */ + public fetchFileExtension(fileInfo: FileList): string { + return fileInfo[0].name.substring(fileInfo[0].name.lastIndexOf('.') + 1); + } + /** Method to validate file extension and size @private */ private vaildataFileInfo(fileInfo: File, fileType: string): boolean { const extension: string = fileInfo.name.substring(fileInfo.name.lastIndexOf('.') + 1);