From 23bdacf8ec24ce47a15529830e116911d7478598 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jul 2019 19:02:54 +0200 Subject: Add setting helper to client plugins --- .../plugin-list-installed.component.ts | 12 ++++--- .../+admin/plugins/shared/plugin-api.service.ts | 42 +++++++++------------- 2 files changed, 23 insertions(+), 31 deletions(-) (limited to 'client/src/app/+admin/plugins') diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts index 9809759db..dced14dee 100644 --- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts @@ -7,6 +7,7 @@ import { ConfirmService, Notifier } from '@app/core' import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' import { ActivatedRoute, Router } from '@angular/router' import { compareSemVer } from '@shared/core-utils/miscs/miscs' +import { PluginService } from '@app/core/plugins/plugin.service' @Component({ selector: 'my-plugin-list-installed', @@ -34,13 +35,14 @@ export class PluginListInstalledComponent implements OnInit { constructor ( private i18n: I18n, - private pluginService: PluginApiService, + private pluginService: PluginService, + private pluginApiService: PluginApiService, private notifier: Notifier, private confirmService: ConfirmService, private router: Router, private route: ActivatedRoute ) { - this.pluginTypeOptions = this.pluginService.getPluginTypeOptions() + this.pluginTypeOptions = this.pluginApiService.getPluginTypeOptions() } ngOnInit () { @@ -60,7 +62,7 @@ export class PluginListInstalledComponent implements OnInit { } loadMorePlugins () { - this.pluginService.getPlugins(this.pluginType, this.pagination, this.sort) + this.pluginApiService.getPlugins(this.pluginType, this.pagination, this.sort) .subscribe( res => { this.plugins = this.plugins.concat(res.data) @@ -106,7 +108,7 @@ export class PluginListInstalledComponent implements OnInit { ) if (res === false) return - this.pluginService.uninstall(plugin.name, plugin.type) + this.pluginApiService.uninstall(plugin.name, plugin.type) .subscribe( () => { this.notifier.success(this.i18n('{{pluginName}} uninstalled.', { pluginName: plugin.name })) @@ -125,7 +127,7 @@ export class PluginListInstalledComponent implements OnInit { this.updating[updatingKey] = true - this.pluginService.update(plugin.name, plugin.type) + this.pluginApiService.update(plugin.name, plugin.type) .pipe() .subscribe( res => { diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.ts index bfcaec011..343eb57b2 100644 --- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts +++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts @@ -12,16 +12,18 @@ import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' +import { PluginService } from '@app/core/plugins/plugin.service' @Injectable() export class PluginApiService { - private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/plugins' + private static BASE_PLUGIN_URL = environment.apiUrl + '/api/v1/plugins' constructor ( private authHttp: HttpClient, private restExtractor: RestExtractor, private restService: RestService, - private i18n: I18n + private i18n: I18n, + private pluginService: PluginService ) { } getPluginTypeOptions () { @@ -56,7 +58,7 @@ export class PluginApiService { params = this.restService.addRestGetParams(params, pagination, sort) params = params.append('pluginType', pluginType.toString()) - return this.authHttp.get>(PluginApiService.BASE_APPLICATION_URL, { params }) + return this.authHttp.get>(PluginApiService.BASE_PLUGIN_URL, { params }) .pipe(catchError(res => this.restExtractor.handleError(res))) } @@ -74,26 +76,28 @@ export class PluginApiService { if (search) params = params.append('search', search) - return this.authHttp.get>(PluginApiService.BASE_APPLICATION_URL + '/available', { params }) + return this.authHttp.get>(PluginApiService.BASE_PLUGIN_URL + '/available', { params }) .pipe(catchError(res => this.restExtractor.handleError(res))) } getPlugin (npmName: string) { - const path = PluginApiService.BASE_APPLICATION_URL + '/' + npmName + const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName return this.authHttp.get(path) .pipe(catchError(res => this.restExtractor.handleError(res))) } getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { - const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' + const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) + const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings' return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path) .pipe(catchError(res => this.restExtractor.handleError(res))) } updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) { - const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/settings' + const npmName = this.pluginService.nameToNpmName(pluginName, pluginType) + const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/settings' return this.authHttp.put(path, { settings }) .pipe(catchError(res => this.restExtractor.handleError(res))) @@ -101,19 +105,19 @@ export class PluginApiService { uninstall (pluginName: string, pluginType: PluginType) { const body: ManagePlugin = { - npmName: this.nameToNpmName(pluginName, pluginType) + npmName: this.pluginService.nameToNpmName(pluginName, pluginType) } - return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/uninstall', body) + return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/uninstall', body) .pipe(catchError(res => this.restExtractor.handleError(res))) } update (pluginName: string, pluginType: PluginType) { const body: ManagePlugin = { - npmName: this.nameToNpmName(pluginName, pluginType) + npmName: this.pluginService.nameToNpmName(pluginName, pluginType) } - return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/update', body) + return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/update', body) .pipe(catchError(res => this.restExtractor.handleError(res))) } @@ -122,21 +126,7 @@ export class PluginApiService { npmName } - return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/install', body) + return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/install', body) .pipe(catchError(res => this.restExtractor.handleError(res))) } - - nameToNpmName (name: string, type: PluginType) { - const prefix = type === PluginType.PLUGIN - ? 'peertube-plugin-' - : 'peertube-theme-' - - return prefix + name - } - - pluginTypeFromNpmName (npmName: string) { - return npmName.startsWith('peertube-plugin-') - ? PluginType.PLUGIN - : PluginType.THEME - } } -- cgit v1.2.3