]>
Commit | Line | Data |
---|---|---|
d00dc28d C |
1 | import { catchError } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | |
3 | import { Injectable } from '@angular/core' | |
4 | import { environment } from '../../../../environments/environment' | |
5 | import { RestExtractor, RestService } from '../../../shared' | |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
7 | import { PluginType } from '@shared/models/plugins/plugin.type' | |
8 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | |
9 | import { ResultList } from '@shared/models' | |
10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' | |
11 | ||
12 | @Injectable() | |
13 | export class PluginApiService { | |
14 | private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/plugins' | |
15 | ||
16 | constructor ( | |
17 | private authHttp: HttpClient, | |
18 | private restExtractor: RestExtractor, | |
19 | private restService: RestService, | |
20 | private i18n: I18n | |
21 | ) { } | |
22 | ||
23 | getPluginTypeOptions () { | |
24 | return [ | |
25 | { | |
26 | label: this.i18n('Plugin'), | |
27 | value: PluginType.PLUGIN | |
28 | }, | |
29 | { | |
30 | label: this.i18n('Theme'), | |
31 | value: PluginType.THEME | |
32 | } | |
33 | ] | |
34 | } | |
35 | ||
36 | getPlugins ( | |
37 | type: PluginType, | |
38 | componentPagination: ComponentPagination, | |
39 | sort: string | |
40 | ) { | |
41 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | |
42 | ||
43 | let params = new HttpParams() | |
44 | params = this.restService.addRestGetParams(params, pagination, sort) | |
45 | params = params.append('type', type.toString()) | |
46 | ||
47 | return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params }) | |
48 | .pipe(catchError(res => this.restExtractor.handleError(res))) | |
49 | } | |
50 | } |