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'
13 export class PluginApiService {
14 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/plugins'
17 private authHttp: HttpClient,
18 private restExtractor: RestExtractor,
19 private restService: RestService,
23 getPluginTypeOptions () {
26 label: this.i18n('Plugin'),
27 value: PluginType.PLUGIN
30 label: this.i18n('Theme'),
31 value: PluginType.THEME
38 componentPagination: ComponentPagination,
41 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
43 let params = new HttpParams()
44 params = this.restService.addRestGetParams(params, pagination, sort)
45 params = params.append('type', type.toString())
47 return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params })
48 .pipe(catchError(res => this.restExtractor.handleError(res)))