generated from lapig-ufg/plataform-base
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lapig-ufg/downloadsys
dowload-minio
- Loading branch information
Showing
4 changed files
with
94 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 58 additions & 5 deletions
63
src/client/src/app/components/services/download.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,76 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import {HttpClient, HttpHeaders} from '@angular/common/http'; | ||
import { environment } from "../../../environments/environment"; | ||
import { catchError, map } from 'rxjs/operators'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class DownloadService { | ||
|
||
private apiURL = `${environment.OWS}/api/download`; | ||
private apiS3 = `${environment.LAPIG_DOWNLOAD_API}/api/download/`; | ||
|
||
constructor(private httpClient: HttpClient) {} | ||
constructor( | ||
private httpClient: HttpClient | ||
) {} | ||
|
||
|
||
downloadFromS3(parameters): Observable<any>{ | ||
return this.httpClient.post<any>(this.apiS3, parameters) | ||
.pipe(map(response => response)) | ||
.pipe(catchError(this.errorHandlerS3)); | ||
} | ||
|
||
downloadRequest(parameters): Observable<Blob> { | ||
return this.httpClient.post(this.apiURL, parameters, { responseType: 'blob' }) | ||
return this.httpClient.post(this.apiURL, parameters, { | ||
headers: new HttpHeaders({ | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': 'Content-Type', | ||
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT' | ||
}), | ||
responseType: 'blob' | ||
}); | ||
} | ||
|
||
downloadRequestSLD(layer): Observable<Blob> { | ||
const url = `${environment.OWS}/ows?request=GetStyles&layers=${layer}&service=wms&version=1.1.1`; | ||
return this.httpClient.get(url, { responseType: 'blob' }) | ||
return this.httpClient.get(url, { | ||
headers: new HttpHeaders({ | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': 'Content-Type', | ||
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT' | ||
}), | ||
responseType: 'blob' | ||
}) | ||
} | ||
|
||
errorHandlerS3(error) { | ||
let errorMessage = ''; | ||
if (error.error instanceof ErrorEvent) { | ||
errorMessage = error.error.message; | ||
} else if(["unable_filter_layer", 'file_empty',"file_not_found"].includes(error.error.message)){ | ||
|
||
errorMessage = 'left_sidebar.layer.s3_'+error.error.message | ||
} | ||
else{ | ||
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; | ||
} | ||
return throwError(errorMessage); | ||
} | ||
|
||
errorHandler(error) { | ||
let errorMessage = ''; | ||
if (error.error instanceof ErrorEvent) { | ||
errorMessage = error.error.message; | ||
} else { | ||
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; | ||
} | ||
return throwError(errorMessage); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters