-
Notifications
You must be signed in to change notification settings - Fork 2
/
sip.service.ts
44 lines (39 loc) · 1.43 KB
/
sip.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpResponse} from '@angular/common/http';
import {Observable} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';
import {ArchiveTransfer} from '../dtos/archive-transfer';
import {SipData} from '../dtos/sip';
import {ServiceUtil} from './service-util';
export const LOCAL_STORAGE_PATH = '/home/helene/Desktop';
const LOCAL_SERVER_URL = 'http://localhost:8080';
@Injectable({
providedIn: 'root'
})
export class SipService {
private sipHealthCheckUrl = `${LOCAL_SERVER_URL}/actuator/health`;
private sipGenerationUrl = `${LOCAL_SERVER_URL}/sip/generate-sync`;
private httpOptions = {
headers: new HttpHeaders({
Accept: 'application/octet-stream',
'Content-Type': 'application/json'
}),
observe: 'response',
responseType: 'blob'
} as const;
constructor(private http: HttpClient) {
}
isAvailable(): Observable<any> {
return this.http.get(this.sipHealthCheckUrl)
.pipe(
tap(_ => ServiceUtil.log('trying to reach SIP service'))
);
}
generateSip(archiveTransfer: ArchiveTransfer): Observable<HttpResponse<Blob>> {
return this.http.post(this.sipGenerationUrl, SipData.fromArchiveTransfer(archiveTransfer), this.httpOptions)
.pipe(
tap(_ => ServiceUtil.log('generated SIP')),
catchError(ServiceUtil.handleError<HttpResponse<Blob>>('generateSip', new HttpResponse()))
);
}
}