diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-25 19:02:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-26 15:18:28 +0200 |
commit | 23bdacf8ec24ce47a15529830e116911d7478598 (patch) | |
tree | 934e6acd8e2715d528a102e55d5ea95d52c1659e /client/src/app/+admin/plugins/shared | |
parent | a1758df8a3c3f866460edd8f9bbc94e8dd41fd80 (diff) | |
download | PeerTube-23bdacf8ec24ce47a15529830e116911d7478598.tar.gz PeerTube-23bdacf8ec24ce47a15529830e116911d7478598.tar.zst PeerTube-23bdacf8ec24ce47a15529830e116911d7478598.zip |
Add setting helper to client plugins
Diffstat (limited to 'client/src/app/+admin/plugins/shared')
-rw-r--r-- | client/src/app/+admin/plugins/shared/plugin-api.service.ts | 42 |
1 files changed, 16 insertions, 26 deletions
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' | |||
12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' | 12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' |
13 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' | 13 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' |
14 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | 14 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' |
15 | import { PluginService } from '@app/core/plugins/plugin.service' | ||
15 | 16 | ||
16 | @Injectable() | 17 | @Injectable() |
17 | export class PluginApiService { | 18 | export 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 | } |