import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { saveAs } from 'file-saver' ; import { Observable } from 'rxjs' ; import { tap } from 'rxjs/operators' ; import { environment } from '../../../environments/environment' ; import { ExportFormat } from '../models/export' ; @ Injectable ( { providedIn : 'root' , } ) export class ExportService { private endpoint = environment . apiEndpoint ; constructor ( private http ) { } export ( projectId , localeCode , format ) { return this . http . get ( `${ this . endpoint }/projects/${ projectId }/exports?locale=${ localeCode }&format=${ format }` , { responseType : 'blob' , } ) ; } exportAndDownload ( projectId , localeCode , format ) { return this . export ( projectId , localeCode , format . code ) . pipe ( tap ( data => saveAs ( data , `${ localeCode }.${ format . extension }` ) ) ) ; } }