diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 14:40:19 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (patch) | |
tree | 7695023d90b78f972abafc718346c50264587ff5 /client/src/app/+admin/plugins/shared/plugin-api.service.ts | |
parent | d00dc28dd73ad9dd419d5a5ac6ac747cefbc6e8b (diff) | |
download | PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.gz PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.zst PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.zip |
WIP plugins: add plugin settings/uninstall in client
Diffstat (limited to 'client/src/app/+admin/plugins/shared/plugin-api.service.ts')
-rw-r--r-- | client/src/app/+admin/plugins/shared/plugin-api.service.ts | 68 |
1 files changed, 66 insertions, 2 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 bfc2b918f..1d33cd179 100644 --- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts +++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts | |||
@@ -8,6 +8,9 @@ import { PluginType } from '@shared/models/plugins/plugin.type' | |||
8 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 8 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
9 | import { ResultList } from '@shared/models' | 9 | import { ResultList } from '@shared/models' |
10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' | 10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' |
11 | import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' | ||
12 | import { InstallPlugin } from '@shared/models/plugins/install-plugin.model' | ||
13 | import { RegisterSettingOptions } from '@shared/models/plugins/register-setting.model' | ||
11 | 14 | ||
12 | @Injectable() | 15 | @Injectable() |
13 | export class PluginApiService { | 16 | export class PluginApiService { |
@@ -23,16 +26,24 @@ export class PluginApiService { | |||
23 | getPluginTypeOptions () { | 26 | getPluginTypeOptions () { |
24 | return [ | 27 | return [ |
25 | { | 28 | { |
26 | label: this.i18n('Plugin'), | 29 | label: this.i18n('Plugins'), |
27 | value: PluginType.PLUGIN | 30 | value: PluginType.PLUGIN |
28 | }, | 31 | }, |
29 | { | 32 | { |
30 | label: this.i18n('Theme'), | 33 | label: this.i18n('Themes'), |
31 | value: PluginType.THEME | 34 | value: PluginType.THEME |
32 | } | 35 | } |
33 | ] | 36 | ] |
34 | } | 37 | } |
35 | 38 | ||
39 | getPluginTypeLabel (type: PluginType) { | ||
40 | if (type === PluginType.PLUGIN) { | ||
41 | return this.i18n('plugin') | ||
42 | } | ||
43 | |||
44 | return this.i18n('theme') | ||
45 | } | ||
46 | |||
36 | getPlugins ( | 47 | getPlugins ( |
37 | type: PluginType, | 48 | type: PluginType, |
38 | componentPagination: ComponentPagination, | 49 | componentPagination: ComponentPagination, |
@@ -47,4 +58,57 @@ export class PluginApiService { | |||
47 | return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params }) | 58 | return this.authHttp.get<ResultList<PeerTubePlugin>>(PluginApiService.BASE_APPLICATION_URL, { params }) |
48 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 59 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
49 | } | 60 | } |
61 | |||
62 | getPlugin (npmName: string) { | ||
63 | const path = PluginApiService.BASE_APPLICATION_URL + '/' + npmName | ||
64 | |||
65 | return this.authHttp.get<PeerTubePlugin>(path) | ||
66 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
67 | } | ||
68 | |||
69 | getPluginRegisteredSettings (pluginName: string, pluginType: PluginType) { | ||
70 | const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/registered-settings' | ||
71 | |||
72 | return this.authHttp.get<{ settings: RegisterSettingOptions[] }>(path) | ||
73 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
74 | } | ||
75 | |||
76 | updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) { | ||
77 | const path = PluginApiService.BASE_APPLICATION_URL + '/' + this.nameToNpmName(pluginName, pluginType) + '/settings' | ||
78 | |||
79 | return this.authHttp.put(path, { settings }) | ||
80 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
81 | } | ||
82 | |||
83 | uninstall (pluginName: string, pluginType: PluginType) { | ||
84 | const body: ManagePlugin = { | ||
85 | npmName: this.nameToNpmName(pluginName, pluginType) | ||
86 | } | ||
87 | |||
88 | return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/uninstall', body) | ||
89 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
90 | } | ||
91 | |||
92 | install (npmName: string) { | ||
93 | const body: InstallPlugin = { | ||
94 | npmName | ||
95 | } | ||
96 | |||
97 | return this.authHttp.post(PluginApiService.BASE_APPLICATION_URL + '/install', body) | ||
98 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
99 | } | ||
100 | |||
101 | nameToNpmName (name: string, type: PluginType) { | ||
102 | const prefix = type === PluginType.PLUGIN | ||
103 | ? 'peertube-plugin-' | ||
104 | : 'peertube-theme-' | ||
105 | |||
106 | return prefix + name | ||
107 | } | ||
108 | |||
109 | pluginTypeFromNpmName (npmName: string) { | ||
110 | return npmName.startsWith('peertube-plugin-') | ||
111 | ? PluginType.PLUGIN | ||
112 | : PluginType.THEME | ||
113 | } | ||
50 | } | 114 | } |