]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/plugins/shared/plugin-api.service.ts
WIP plugins: list installed plugins in client
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / plugins / shared / plugin-api.service.ts
CommitLineData
d00dc28d
C
1import { catchError } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { environment } from '../../../../environments/environment'
5import { RestExtractor, RestService } from '../../../shared'
6import { I18n } from '@ngx-translate/i18n-polyfill'
7import { PluginType } from '@shared/models/plugins/plugin.type'
8import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
9import { ResultList } from '@shared/models'
10import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
11
12@Injectable()
13export 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}