syncthing/next-gen-gui/src/app/services/db-status.service.ts

43 lines
1.1 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 { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
2020-03-17 14:46:32 +01:00
2020-03-25 14:41:22 +01:00
import { environment } from '../../environments/environment'
import { apiURL } from '../api-utils'
2020-03-25 14:41:22 +01:00
import Folder from '../folder'
2020-03-17 14:46:32 +01:00
@Injectable({
providedIn: 'root'
})
export class DbStatusService {
private dbStatusUrl = environment.production ? apiURL + 'rest/db/status' : 'api/dbStatus';
constructor(private http: HttpClient) { }
2020-03-17 14:46:32 +01:00
getFolderStatus(id: string): Observable<Folder.Status> {
let httpOptions: { params: HttpParams };
2020-03-18 03:37:39 +01:00
if (id) {
httpOptions = {
params: new HttpParams().set('folder', id)
};
} else { }
2020-03-18 03:37:39 +01:00
2020-03-17 14:46:32 +01:00
return this.http
.get<Folder.Status>(this.dbStatusUrl, httpOptions)
2020-03-18 03:37:39 +01:00
.pipe(
map(res => {
// Remove from array in developement
// in-memory-web-api returns arrays
if (!environment.production) {
const a: any = res as any;
if (a.length > 0) {
res = res[0];
}
}
2020-03-18 03:37:39 +01:00
return res;
})
2020-03-17 14:46:32 +01:00
);
}
2020-03-18 03:37:39 +01:00
}