aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-25 19:02:54 +0200
committerChocobozzz <me@florianbigard.com>2019-07-26 15:18:28 +0200
commit23bdacf8ec24ce47a15529830e116911d7478598 (patch)
tree934e6acd8e2715d528a102e55d5ea95d52c1659e /client/src/app/+admin
parenta1758df8a3c3f866460edd8f9bbc94e8dd41fd80 (diff)
downloadPeerTube-23bdacf8ec24ce47a15529830e116911d7478598.tar.gz
PeerTube-23bdacf8ec24ce47a15529830e116911d7478598.tar.zst
PeerTube-23bdacf8ec24ce47a15529830e116911d7478598.zip
Add setting helper to client plugins
Diffstat (limited to 'client/src/app/+admin')
-rw-r--r--client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts12
-rw-r--r--client/src/app/+admin/plugins/shared/plugin-api.service.ts42
2 files changed, 23 insertions, 31 deletions
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'
7import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' 7import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
8import { ActivatedRoute, Router } from '@angular/router' 8import { ActivatedRoute, Router } from '@angular/router'
9import { compareSemVer } from '@shared/core-utils/miscs/miscs' 9import { compareSemVer } from '@shared/core-utils/miscs/miscs'
10import { PluginService } from '@app/core/plugins/plugin.service'
10 11
11@Component({ 12@Component({
12 selector: 'my-plugin-list-installed', 13 selector: 'my-plugin-list-installed',
@@ -34,13 +35,14 @@ export class PluginListInstalledComponent implements OnInit {
34 35
35 constructor ( 36 constructor (
36 private i18n: I18n, 37 private i18n: I18n,
37 private pluginService: PluginApiService, 38 private pluginService: PluginService,
39 private pluginApiService: PluginApiService,
38 private notifier: Notifier, 40 private notifier: Notifier,
39 private confirmService: ConfirmService, 41 private confirmService: ConfirmService,
40 private router: Router, 42 private router: Router,
41 private route: ActivatedRoute 43 private route: ActivatedRoute
42 ) { 44 ) {
43 this.pluginTypeOptions = this.pluginService.getPluginTypeOptions() 45 this.pluginTypeOptions = this.pluginApiService.getPluginTypeOptions()
44 } 46 }
45 47
46 ngOnInit () { 48 ngOnInit () {
@@ -60,7 +62,7 @@ export class PluginListInstalledComponent implements OnInit {
60 } 62 }
61 63
62 loadMorePlugins () { 64 loadMorePlugins () {
63 this.pluginService.getPlugins(this.pluginType, this.pagination, this.sort) 65 this.pluginApiService.getPlugins(this.pluginType, this.pagination, this.sort)
64 .subscribe( 66 .subscribe(
65 res => { 67 res => {
66 this.plugins = this.plugins.concat(res.data) 68 this.plugins = this.plugins.concat(res.data)
@@ -106,7 +108,7 @@ export class PluginListInstalledComponent implements OnInit {
106 ) 108 )
107 if (res === false) return 109 if (res === false) return
108 110
109 this.pluginService.uninstall(plugin.name, plugin.type) 111 this.pluginApiService.uninstall(plugin.name, plugin.type)
110 .subscribe( 112 .subscribe(
111 () => { 113 () => {
112 this.notifier.success(this.i18n('{{pluginName}} uninstalled.', { pluginName: plugin.name })) 114 this.notifier.success(this.i18n('{{pluginName}} uninstalled.', { pluginName: plugin.name }))
@@ -125,7 +127,7 @@ export class PluginListInstalledComponent implements OnInit {
125 127
126 this.updating[updatingKey] = true 128 this.updating[updatingKey] = true
127 129
128 this.pluginService.update(plugin.name, plugin.type) 130 this.pluginApiService.update(plugin.name, plugin.type)
129 .pipe() 131 .pipe()
130 .subscribe( 132 .subscribe(
131 res => { 133 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'
12import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' 12import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model'
13import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' 13import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model'
14import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' 14import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
15import { PluginService } from '@app/core/plugins/plugin.service'
15 16
16@Injectable() 17@Injectable()
17export class PluginApiService { 18export class PluginApiService {
18 private static BASE_APPLICATION_URL = environment.apiUrl + '/api/v1/plugins' 19 private static BASE_PLUGIN_URL = environment.apiUrl + '/api/v1/plugins'
19 20
20 constructor ( 21 constructor (
21 private authHttp: HttpClient, 22 private authHttp: HttpClient,
22 private restExtractor: RestExtractor, 23 private restExtractor: RestExtractor,
23 private restService: RestService, 24 private restService: RestService,
24 private i18n: I18n 25 private i18n: I18n,
26 private pluginService: PluginService
25 ) { } 27 ) { }
26 28
27 getPluginTypeOptions () { 29 getPluginTypeOptions () {
@@ -56,7 +58,7 @@ export class PluginApiService {
56 params = this.restService.addRestGetParams(params, pagination, sort) 58 params = this.restService.addRestGetParams(params, pagination, sort)
57 params = params.append('pluginType', pluginType.toString()) 59 params = params.append('pluginType', pluginType.toString())
58 60
59 return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params }) 61 return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_PLUGIN_URL, { params })
60 .pipe(catchError(res => this.restExtractor.handleError(res))) 62 .pipe(catchError(res => this.restExtractor.handleError(res)))
61 } 63 }
62 64
@@ -74,26 +76,28 @@ export class PluginApiService {
74 76
75 if (search) params = params.append('search', search) 77 if (search) params = params.append('search', search)
76 78
77 return this.authHttp.get<ResultList<PeerTubePluginIndex>>(PluginApiService.BASE_APPLICATION_URL + '/available', { params }) 79 return this.authHttp.get<ResultList<PeerTubePluginIndex>>(PluginApiService.BASE_PLUGIN_URL + '/available', { params })
78 .pipe(catchError(res => this.restExtractor.handleError(res))) 80 .pipe(catchError(res => this.restExtractor.handleError(res)))
79 } 81 }
80 82
81 getPlugin (npmName: string) { 83 getPlugin (npmName: string) {
82 const path = PluginApiService.BASE_APPLICATION_URL + '/' + npmName 84 const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName
83 85
84 return this.authHttp.get<PeerTubePlugin>(path) 86 return this.authHttp.get<PeerTubePlugin>(path)
85 .pipe(catchError(res => this.restExtractor.handleError(res))) 87 .pipe(catchError(res => this.restExtractor.handleError(res)))
86 } 88 }
87 89
88 getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { 90 getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) {
89 const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' 91 const npmName = this.pluginService.nameToNpmName(pluginName, pluginType)
92 const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings'
90 93
91 return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path) 94 return this.authHttp.get<{ settings: RegisterServerSettingOptions[] }>(path)
92 .pipe(catchError(res => this.restExtractor.handleError(res))) 95 .pipe(catchError(res => this.restExtractor.handleError(res)))
93 } 96 }
94 97
95 updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) { 98 updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) {
96 const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/settings' 99 const npmName = this.pluginService.nameToNpmName(pluginName, pluginType)
100 const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/settings'
97 101
98 return this.authHttp.put(path, { settings }) 102 return this.authHttp.put(path, { settings })
99 .pipe(catchError(res => this.restExtractor.handleError(res))) 103 .pipe(catchError(res => this.restExtractor.handleError(res)))
@@ -101,19 +105,19 @@ export class PluginApiService {
101 105
102 uninstall (pluginName: string, pluginType: PluginType) { 106 uninstall (pluginName: string, pluginType: PluginType) {
103 const body: ManagePlugin = { 107 const body: ManagePlugin = {
104 npmName: this.nameToNpmName(pluginName, pluginType) 108 npmName: this.pluginService.nameToNpmName(pluginName, pluginType)
105 } 109 }
106 110
107 return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/uninstall', body) 111 return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/uninstall', body)
108 .pipe(catchError(res => this.restExtractor.handleError(res))) 112 .pipe(catchError(res => this.restExtractor.handleError(res)))
109 } 113 }
110 114
111 update (pluginName: string, pluginType: PluginType) { 115 update (pluginName: string, pluginType: PluginType) {
112 const body: ManagePlugin = { 116 const body: ManagePlugin = {
113 npmName: this.nameToNpmName(pluginName, pluginType) 117 npmName: this.pluginService.nameToNpmName(pluginName, pluginType)
114 } 118 }
115 119
116 return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/update', body) 120 return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/update', body)
117 .pipe(catchError(res => this.restExtractor.handleError(res))) 121 .pipe(catchError(res => this.restExtractor.handleError(res)))
118 } 122 }
119 123
@@ -122,21 +126,7 @@ export class PluginApiService {
122 npmName 126 npmName
123 } 127 }
124 128
125 return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/install', body) 129 return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/install', body)
126 .pipe(catchError(res => this.restExtractor.handleError(res))) 130 .pipe(catchError(res => this.restExtractor.handleError(res)))
127 } 131 }
128
129 nameToNpmName (name: string, type: PluginType) {
130 const prefix = type === PluginType.PLUGIN
131 ? 'peertube-plugin-'
132 : 'peertube-theme-'
133
134 return prefix + name
135 }
136
137 pluginTypeFromNpmName (npmName: string) {
138 return npmName.startsWith('peertube-plugin-')
139 ? PluginType.PLUGIN
140 : PluginType.THEME
141 }
142} 132}