diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-11 12:04:47 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-11 13:33:11 +0200 |
commit | 428ccb8b7a44ce60cabb7401a5464cf5fcbd4dba (patch) | |
tree | b75329b64f5e201abdfb39961f2db09a08292b77 /shared/models/plugins/server | |
parent | 2b02c520e66ea452687cab39401b371711caa9ed (diff) | |
download | PeerTube-428ccb8b7a44ce60cabb7401a5464cf5fcbd4dba.tar.gz PeerTube-428ccb8b7a44ce60cabb7401a5464cf5fcbd4dba.tar.zst PeerTube-428ccb8b7a44ce60cabb7401a5464cf5fcbd4dba.zip |
Reorganize plugin models
Diffstat (limited to 'shared/models/plugins/server')
20 files changed, 252 insertions, 0 deletions
diff --git a/shared/models/plugins/server/api/index.ts b/shared/models/plugins/server/api/index.ts new file mode 100644 index 000000000..eb59a03f0 --- /dev/null +++ b/shared/models/plugins/server/api/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './install-plugin.model' | ||
2 | export * from './manage-plugin.model' | ||
3 | export * from './peertube-plugin.model' | ||
diff --git a/shared/models/plugins/server/api/install-plugin.model.ts b/shared/models/plugins/server/api/install-plugin.model.ts new file mode 100644 index 000000000..5a268ebe1 --- /dev/null +++ b/shared/models/plugins/server/api/install-plugin.model.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export interface InstallOrUpdatePlugin { | ||
2 | npmName?: string | ||
3 | path?: string | ||
4 | } | ||
diff --git a/shared/models/plugins/server/api/manage-plugin.model.ts b/shared/models/plugins/server/api/manage-plugin.model.ts new file mode 100644 index 000000000..612b3056c --- /dev/null +++ b/shared/models/plugins/server/api/manage-plugin.model.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export interface ManagePlugin { | ||
2 | npmName: string | ||
3 | } | ||
diff --git a/shared/models/plugins/server/api/peertube-plugin.model.ts b/shared/models/plugins/server/api/peertube-plugin.model.ts new file mode 100644 index 000000000..54c383f57 --- /dev/null +++ b/shared/models/plugins/server/api/peertube-plugin.model.ts | |||
@@ -0,0 +1,16 @@ | |||
1 | import { PluginType } from '../../plugin.type' | ||
2 | |||
3 | export interface PeerTubePlugin { | ||
4 | name: string | ||
5 | type: PluginType | ||
6 | latestVersion: string | ||
7 | version: string | ||
8 | enabled: boolean | ||
9 | uninstalled: boolean | ||
10 | peertubeEngine: string | ||
11 | description: string | ||
12 | homepage: string | ||
13 | settings: { [ name: string ]: string } | ||
14 | createdAt: Date | ||
15 | updatedAt: Date | ||
16 | } | ||
diff --git a/shared/models/plugins/server/index.ts b/shared/models/plugins/server/index.ts new file mode 100644 index 000000000..d3ff49d3b --- /dev/null +++ b/shared/models/plugins/server/index.ts | |||
@@ -0,0 +1,6 @@ | |||
1 | export * from './api' | ||
2 | export * from './managers' | ||
3 | export * from './settings' | ||
4 | export * from './plugin-translation.model' | ||
5 | export * from './register-server-hook.model' | ||
6 | export * from './server-hook.model' | ||
diff --git a/shared/models/plugins/server/managers/index.ts b/shared/models/plugins/server/managers/index.ts new file mode 100644 index 000000000..49365a854 --- /dev/null +++ b/shared/models/plugins/server/managers/index.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | |||
2 | export * from './plugin-playlist-privacy-manager.model' | ||
3 | export * from './plugin-settings-manager.model' | ||
4 | export * from './plugin-storage-manager.model' | ||
5 | export * from './plugin-transcoding-manager.model' | ||
6 | export * from './plugin-video-category-manager.model' | ||
7 | export * from './plugin-video-language-manager.model' | ||
8 | export * from './plugin-video-licence-manager.model' | ||
9 | export * from './plugin-video-privacy-manager.model' | ||
diff --git a/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts b/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts new file mode 100644 index 000000000..4703c0a8b --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-playlist-privacy-manager.model.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { VideoPlaylistPrivacy } from '../../../videos/playlist/video-playlist-privacy.model' | ||
2 | |||
3 | export interface PluginPlaylistPrivacyManager { | ||
4 | // PUBLIC = 1, | ||
5 | // UNLISTED = 2, | ||
6 | // PRIVATE = 3 | ||
7 | deletePlaylistPrivacy: (privacyKey: VideoPlaylistPrivacy) => boolean | ||
8 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-settings-manager.model.ts b/shared/models/plugins/server/managers/plugin-settings-manager.model.ts new file mode 100644 index 000000000..3c28c0565 --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-settings-manager.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | export interface PluginSettingsManager { | ||
2 | getSetting: (name: string) => Promise<string | boolean> | ||
3 | |||
4 | getSettings: (names: string[]) => Promise<{ [settingName: string]: string | boolean }> | ||
5 | |||
6 | setSetting: (name: string, value: string) => Promise<any> | ||
7 | |||
8 | onSettingsChange: (cb: (names: string[]) => Promise<any>) => void | ||
9 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-storage-manager.model.ts b/shared/models/plugins/server/managers/plugin-storage-manager.model.ts new file mode 100644 index 000000000..51567044a --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-storage-manager.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface PluginStorageManager { | ||
2 | getData: (key: string) => Promise<string> | ||
3 | |||
4 | storeData: (key: string, data: any) => Promise<any> | ||
5 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts b/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts new file mode 100644 index 000000000..a0422a460 --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-transcoding-manager.model.ts | |||
@@ -0,0 +1,13 @@ | |||
1 | import { EncoderOptionsBuilder } from '../../../videos/video-transcoding.model' | ||
2 | |||
3 | export interface PluginTranscodingManager { | ||
4 | addLiveProfile (encoder: string, profile: string, builder: EncoderOptionsBuilder): boolean | ||
5 | |||
6 | addVODProfile (encoder: string, profile: string, builder: EncoderOptionsBuilder): boolean | ||
7 | |||
8 | addLiveEncoderPriority (streamType: 'audio' | 'video', encoder: string, priority: number): void | ||
9 | |||
10 | addVODEncoderPriority (streamType: 'audio' | 'video', encoder: string, priority: number): void | ||
11 | |||
12 | removeAllProfilesAndEncoderPriorities(): void | ||
13 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts new file mode 100644 index 000000000..201bfa979 --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-video-category-manager.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface PluginVideoCategoryManager { | ||
2 | addCategory: (categoryKey: number, categoryLabel: string) => boolean | ||
3 | |||
4 | deleteCategory: (categoryKey: number) => boolean | ||
5 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts new file mode 100644 index 000000000..3fd577a79 --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-video-language-manager.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface PluginVideoLanguageManager { | ||
2 | addLanguage: (languageKey: string, languageLabel: string) => boolean | ||
3 | |||
4 | deleteLanguage: (languageKey: string) => boolean | ||
5 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts new file mode 100644 index 000000000..82a634d3a --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-video-licence-manager.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface PluginVideoLicenceManager { | ||
2 | addLicence: (licenceKey: number, licenceLabel: string) => boolean | ||
3 | |||
4 | deleteLicence: (licenceKey: number) => boolean | ||
5 | } | ||
diff --git a/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts b/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts new file mode 100644 index 000000000..7717115e3 --- /dev/null +++ b/shared/models/plugins/server/managers/plugin-video-privacy-manager.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | import { VideoPrivacy } from '../../../videos/video-privacy.enum' | ||
2 | |||
3 | export interface PluginVideoPrivacyManager { | ||
4 | // PUBLIC = 1 | ||
5 | // UNLISTED = 2 | ||
6 | // PRIVATE = 3 | ||
7 | // INTERNAL = 4 | ||
8 | deletePrivacy: (privacyKey: VideoPrivacy) => boolean | ||
9 | } | ||
diff --git a/shared/models/plugins/server/plugin-translation.model.ts b/shared/models/plugins/server/plugin-translation.model.ts new file mode 100644 index 000000000..a2dd8e560 --- /dev/null +++ b/shared/models/plugins/server/plugin-translation.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export type PluginTranslation = { | ||
2 | [ npmName: string ]: { | ||
3 | [ key: string ]: string | ||
4 | } | ||
5 | } | ||
diff --git a/shared/models/plugins/server/register-server-hook.model.ts b/shared/models/plugins/server/register-server-hook.model.ts new file mode 100644 index 000000000..746fdc329 --- /dev/null +++ b/shared/models/plugins/server/register-server-hook.model.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | import { ServerHookName } from './server-hook.model' | ||
2 | |||
3 | export interface RegisterServerHookOptions { | ||
4 | target: ServerHookName | ||
5 | handler: Function | ||
6 | priority?: number | ||
7 | } | ||
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts new file mode 100644 index 000000000..88277af5a --- /dev/null +++ b/shared/models/plugins/server/server-hook.model.ts | |||
@@ -0,0 +1,123 @@ | |||
1 | // {hookType}:{api?}.{location}.{subLocation?}.{actionType}.{target} | ||
2 | |||
3 | export const serverFilterHookObject = { | ||
4 | // Filter params/result used to list videos for the REST API | ||
5 | // (used by the trending page, recently-added page, local page etc) | ||
6 | 'filter:api.videos.list.params': true, | ||
7 | 'filter:api.videos.list.result': true, | ||
8 | |||
9 | // Filter params/result used to list account videos for the REST API | ||
10 | 'filter:api.accounts.videos.list.params': true, | ||
11 | 'filter:api.accounts.videos.list.result': true, | ||
12 | |||
13 | // Filter params/result used to list channel videos for the REST API | ||
14 | 'filter:api.video-channels.videos.list.params': true, | ||
15 | 'filter:api.video-channels.videos.list.result': true, | ||
16 | |||
17 | // Filter params/result used to list my user videos for the REST API | ||
18 | 'filter:api.user.me.videos.list.params': true, | ||
19 | 'filter:api.user.me.videos.list.result': true, | ||
20 | |||
21 | // Filter params/results to search videos/channels in the DB or on the remote index | ||
22 | 'filter:api.search.videos.local.list.params': true, | ||
23 | 'filter:api.search.videos.local.list.result': true, | ||
24 | 'filter:api.search.videos.index.list.params': true, | ||
25 | 'filter:api.search.videos.index.list.result': true, | ||
26 | 'filter:api.search.video-channels.local.list.params': true, | ||
27 | 'filter:api.search.video-channels.local.list.result': true, | ||
28 | 'filter:api.search.video-channels.index.list.params': true, | ||
29 | 'filter:api.search.video-channels.index.list.result': true, | ||
30 | |||
31 | // Filter the result of the get function | ||
32 | // Used to get detailed video information (video watch page for example) | ||
33 | 'filter:api.video.get.result': true, | ||
34 | |||
35 | // Filter the result of the accept upload/live, import via torrent/url functions | ||
36 | // If this function returns false then the upload is aborted with an error | ||
37 | 'filter:api.video.upload.accept.result': true, | ||
38 | 'filter:api.live-video.create.accept.result': true, | ||
39 | 'filter:api.video.pre-import-url.accept.result': true, | ||
40 | 'filter:api.video.pre-import-torrent.accept.result': true, | ||
41 | 'filter:api.video.post-import-url.accept.result': true, | ||
42 | 'filter:api.video.post-import-torrent.accept.result': true, | ||
43 | // Filter the result of the accept comment (thread or reply) functions | ||
44 | // If the functions return false then the user cannot post its comment | ||
45 | 'filter:api.video-thread.create.accept.result': true, | ||
46 | 'filter:api.video-comment-reply.create.accept.result': true, | ||
47 | |||
48 | // Filter params/result used to list threads of a specific video | ||
49 | // (used by the video watch page) | ||
50 | 'filter:api.video-threads.list.params': true, | ||
51 | 'filter:api.video-threads.list.result': true, | ||
52 | |||
53 | // Filter params/result used to list replies of a specific thread | ||
54 | // (used by the video watch page when we click on the "View replies" button) | ||
55 | 'filter:api.video-thread-comments.list.params': true, | ||
56 | 'filter:api.video-thread-comments.list.result': true, | ||
57 | |||
58 | // Filter result used to check if we need to auto blacklist a video | ||
59 | // (fired when a local or remote video is created or updated) | ||
60 | 'filter:video.auto-blacklist.result': true, | ||
61 | |||
62 | // Filter result used to check if a user can register on the instance | ||
63 | 'filter:api.user.signup.allowed.result': true, | ||
64 | |||
65 | // Filter result used to check if video/torrent download is allowed | ||
66 | 'filter:api.download.video.allowed.result': true, | ||
67 | 'filter:api.download.torrent.allowed.result': true, | ||
68 | |||
69 | // Filter result to check if the embed is allowed for a particular request | ||
70 | 'filter:html.embed.video.allowed.result': true, | ||
71 | 'filter:html.embed.video-playlist.allowed.result': true | ||
72 | } | ||
73 | |||
74 | export type ServerFilterHookName = keyof typeof serverFilterHookObject | ||
75 | |||
76 | export const serverActionHookObject = { | ||
77 | // Fired when the application has been loaded and is listening HTTP requests | ||
78 | 'action:application.listening': true, | ||
79 | |||
80 | // Fired when a local video is updated | ||
81 | 'action:api.video.updated': true, | ||
82 | // Fired when a local video is deleted | ||
83 | 'action:api.video.deleted': true, | ||
84 | // Fired when a local video is uploaded | ||
85 | 'action:api.video.uploaded': true, | ||
86 | // Fired when a local video is viewed | ||
87 | 'action:api.video.viewed': true, | ||
88 | |||
89 | // Fired when a live video is created | ||
90 | 'action:api.live-video.created': true, | ||
91 | |||
92 | // Fired when a thread is created | ||
93 | 'action:api.video-thread.created': true, | ||
94 | // Fired when a reply to a thread is created | ||
95 | 'action:api.video-comment-reply.created': true, | ||
96 | // Fired when a comment (thread or reply) is deleted | ||
97 | 'action:api.video-comment.deleted': true, | ||
98 | |||
99 | // Fired when a user is blocked (banned) | ||
100 | 'action:api.user.blocked': true, | ||
101 | // Fired when a user is unblocked (unbanned) | ||
102 | 'action:api.user.unblocked': true, | ||
103 | // Fired when a user registered on the instance | ||
104 | 'action:api.user.registered': true, | ||
105 | // Fired when an admin/moderator created a user | ||
106 | 'action:api.user.created': true, | ||
107 | // Fired when a user is removed by an admin/moderator | ||
108 | 'action:api.user.deleted': true, | ||
109 | // Fired when a user is updated by an admin/moderator | ||
110 | 'action:api.user.updated': true, | ||
111 | |||
112 | // Fired when a user got a new oauth2 token | ||
113 | 'action:api.user.oauth2-got-token': true | ||
114 | } | ||
115 | |||
116 | export type ServerActionHookName = keyof typeof serverActionHookObject | ||
117 | |||
118 | export const serverHookObject = Object.assign({}, serverFilterHookObject, serverActionHookObject) | ||
119 | export type ServerHookName = keyof typeof serverHookObject | ||
120 | |||
121 | export interface ServerHook { | ||
122 | runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T> | ||
123 | } | ||
diff --git a/shared/models/plugins/server/settings/index.ts b/shared/models/plugins/server/settings/index.ts new file mode 100644 index 000000000..b456de019 --- /dev/null +++ b/shared/models/plugins/server/settings/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './public-server.setting' | ||
2 | export * from './register-server-setting.model' | ||
diff --git a/shared/models/plugins/server/settings/public-server.setting.ts b/shared/models/plugins/server/settings/public-server.setting.ts new file mode 100644 index 000000000..9802c4d7d --- /dev/null +++ b/shared/models/plugins/server/settings/public-server.setting.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export interface PublicServerSetting { | ||
2 | publicSettings: { [ name: string ]: string } | ||
3 | } | ||
diff --git a/shared/models/plugins/server/settings/register-server-setting.model.ts b/shared/models/plugins/server/settings/register-server-setting.model.ts new file mode 100644 index 000000000..d9a798cac --- /dev/null +++ b/shared/models/plugins/server/settings/register-server-setting.model.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import { RegisterClientFormFieldOptions } from '../../client' | ||
2 | |||
3 | export type RegisterServerSettingOptions = RegisterClientFormFieldOptions & { | ||
4 | // If the setting is not private, anyone can view its value (client code included) | ||
5 | // If the setting is private, only server-side hooks can access it | ||
6 | // Mainly used by the PeerTube client to get admin config | ||
7 | private: boolean | ||
8 | } | ||
9 | |||
10 | export interface RegisteredServerSettings { | ||
11 | registeredSettings: RegisterServerSettingOptions[] | ||
12 | } | ||