src/app/shared/api/rgw-bucket.service.ts
Properties |
|
Methods |
constructor(http: HttpClient)
|
||||||
Defined in src/app/shared/api/rgw-bucket.service.ts:16
|
||||||
Parameters :
|
create |
create(bucket: string, uid: string)
|
Defined in src/app/shared/api/rgw-bucket.service.ts:51
|
Returns :
any
|
delete | ||||||||||||
delete(bucket: string, purgeObjects)
|
||||||||||||
Defined in src/app/shared/api/rgw-bucket.service.ts:65
|
||||||||||||
Parameters :
Returns :
any
|
enumerate |
enumerate()
|
Defined in src/app/shared/api/rgw-bucket.service.ts:43
|
Get the list of bucket names.
Returns :
any
|
exists | ||||||
exists(bucket: string)
|
||||||
Defined in src/app/shared/api/rgw-bucket.service.ts:76
|
||||||
Check if the specified bucket exists.
Parameters :
Returns :
any
|
get | ||||||
get(bucket: string)
|
||||||
Defined in src/app/shared/api/rgw-bucket.service.ts:47
|
||||||
Parameters :
Returns :
any
|
list |
list()
|
Defined in src/app/shared/api/rgw-bucket.service.ts:24
|
Get the list of buckets.
Returns :
any
|
update |
update(bucket: string, bucketId: string, uid: string)
|
Defined in src/app/shared/api/rgw-bucket.service.ts:58
|
Returns :
any
|
Private url |
Type : string
|
Default value : 'api/rgw/bucket'
|
Defined in src/app/shared/api/rgw-bucket.service.ts:16
|
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import * as _ from 'lodash';
import { forkJoin as observableForkJoin, of as observableOf } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { cdEncode } from '../decorators/cd-encode';
import { ApiModule } from './api.module';
@cdEncode
@Injectable({
providedIn: ApiModule
})
export class RgwBucketService {
private url = 'api/rgw/bucket';
constructor(private http: HttpClient) {}
/**
* Get the list of buckets.
* @return {Observable<Object[]>}
*/
list() {
return this.enumerate().pipe(
mergeMap((buckets: string[]) => {
if (buckets.length > 0) {
return observableForkJoin(
buckets.map((bucket: string) => {
return this.get(bucket);
})
);
}
return observableOf([]);
})
);
}
/**
* Get the list of bucket names.
* @return {Observable<string[]>}
*/
enumerate() {
return this.http.get(this.url);
}
get(bucket: string) {
return this.http.get(`${this.url}/${bucket}`);
}
create(bucket: string, uid: string) {
let params = new HttpParams();
params = params.append('bucket', bucket);
params = params.append('uid', uid);
return this.http.post(this.url, null, { params: params });
}
update(bucket: string, bucketId: string, uid: string) {
let params = new HttpParams();
params = params.append('bucket_id', bucketId);
params = params.append('uid', uid);
return this.http.put(`${this.url}/${bucket}`, null, { params: params });
}
delete(bucket: string, purgeObjects = true) {
let params = new HttpParams();
params = params.append('purge_objects', purgeObjects ? 'true' : 'false');
return this.http.delete(`${this.url}/${bucket}`, { params: params });
}
/**
* Check if the specified bucket exists.
* @param {string} uid The bucket name to check.
* @return {Observable<boolean>}
*/
exists(bucket: string) {
return this.enumerate().pipe(
mergeMap((resp: string[]) => {
const index = _.indexOf(resp, bucket);
return observableOf(-1 !== index);
})
);
}
}