syncthing/src/app/db-status.service.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-03-17 14:46:32 +01:00
import { Injectable } from '@angular/core';
2020-03-18 03:37:39 +01:00
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
2020-03-17 14:46:32 +01:00
import { CookieService } from './cookie.service';
2020-03-18 03:37:39 +01:00
import { Observable, of } from 'rxjs';
import { map, retry, catchError } from 'rxjs/operators';
2020-03-17 14:46:32 +01:00
import { environment } from '../environments/environment'
2020-03-18 03:37:39 +01:00
import { apiURL, apiRetry } from './api-utils'
import { FolderStatus, Folder } from './folder'
2020-03-17 14:46:32 +01:00
@Injectable({
providedIn: 'root'
})
export class DbStatusService {
2020-03-18 03:37:39 +01:00
private folderStatus: Object = {};
// TODO why isn't this working?
private httpOptions: { headers: HttpHeaders } | { params: HttpParams };
2020-03-17 14:46:32 +01:00
private dbStatusUrl = environment.production ? apiURL + 'rest/db/status' : 'api/dbStatus';
constructor(private http: HttpClient, private cookieService: CookieService) {
this.httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) };
}
2020-03-18 03:37:39 +01:00
getFolderStatus(id: string): Observable<FolderStatus> {
/*
if (id) {
this.httpOptions["params"] = new HttpParams().set('folder', id);
}
*/
2020-03-17 14:46:32 +01:00
return this.http
2020-03-18 03:37:39 +01:00
.get<FolderStatus>(this.dbStatusUrl, this.httpOptions)
.pipe(
retry(apiRetry),
map(res => {
return res;
})
2020-03-17 14:46:32 +01:00
);
}
2020-03-18 03:37:39 +01:00
}