aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/types/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /server/types/plugins
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'server/types/plugins')
-rw-r--r--server/types/plugins/index.ts3
-rw-r--r--server/types/plugins/plugin-library.model.ts7
-rw-r--r--server/types/plugins/register-server-auth.model.ts52
-rw-r--r--server/types/plugins/register-server-option.model.ts84
4 files changed, 146 insertions, 0 deletions
diff --git a/server/types/plugins/index.ts b/server/types/plugins/index.ts
new file mode 100644
index 000000000..de30ff2ab
--- /dev/null
+++ b/server/types/plugins/index.ts
@@ -0,0 +1,3 @@
1export * from './plugin-library.model'
2export * from './register-server-auth.model'
3export * from './register-server-option.model'
diff --git a/server/types/plugins/plugin-library.model.ts b/server/types/plugins/plugin-library.model.ts
new file mode 100644
index 000000000..5b517ee9f
--- /dev/null
+++ b/server/types/plugins/plugin-library.model.ts
@@ -0,0 +1,7 @@
1import { RegisterServerOptions } from './register-server-option.model'
2
3export interface PluginLibrary {
4 register: (options: RegisterServerOptions) => Promise<any>
5
6 unregister: () => Promise<any>
7}
diff --git a/server/types/plugins/register-server-auth.model.ts b/server/types/plugins/register-server-auth.model.ts
new file mode 100644
index 000000000..31c71b0d0
--- /dev/null
+++ b/server/types/plugins/register-server-auth.model.ts
@@ -0,0 +1,52 @@
1import * as express from 'express'
2import { UserRole } from '@shared/models'
3import { MOAuthToken, MUser } from '../models'
4
5export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
6
7export interface RegisterServerAuthenticatedResult {
8 username: string
9 email: string
10 role?: UserRole
11 displayName?: string
12}
13
14export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult {
15 req: express.Request
16 res: express.Response
17}
18
19interface RegisterServerAuthBase {
20 // Authentication name (a plugin can register multiple auth strategies)
21 authName: string
22
23 // Called by PeerTube when a user from your plugin logged out
24 onLogout?(user: MUser): void
25
26 // Your plugin can hook PeerTube access/refresh token validity
27 // So you can control for your plugin the user session lifetime
28 hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }>
29}
30
31export interface RegisterServerAuthPassOptions extends RegisterServerAuthBase {
32 // Weight of this authentication so PeerTube tries the auth methods in DESC weight order
33 getWeight(): number
34
35 // Used by PeerTube to login a user
36 // Returns null if the login failed, or { username, email } on success
37 login(body: {
38 id: string
39 password: string
40 }): Promise<RegisterServerAuthenticatedResult | null>
41}
42
43export interface RegisterServerAuthExternalOptions extends RegisterServerAuthBase {
44 // Will be displayed in a block next to the login form
45 authDisplayName: () => string
46
47 onAuthRequest: (req: express.Request, res: express.Response) => void
48}
49
50export interface RegisterServerAuthExternalResult {
51 userAuthenticated (options: RegisterServerExternalAuthenticatedResult): void
52}
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts
new file mode 100644
index 000000000..74303d383
--- /dev/null
+++ b/server/types/plugins/register-server-option.model.ts
@@ -0,0 +1,84 @@
1import * as Bluebird from 'bluebird'
2import { Router } from 'express'
3import { Logger } from 'winston'
4import { ActorModel } from '@server/models/activitypub/actor'
5import {
6 PluginPlaylistPrivacyManager,
7 PluginSettingsManager,
8 PluginStorageManager,
9 PluginVideoCategoryManager,
10 PluginVideoLanguageManager,
11 PluginVideoLicenceManager,
12 PluginVideoPrivacyManager,
13 RegisterServerHookOptions,
14 RegisterServerSettingOptions,
15 VideoBlacklistCreate
16} from '@shared/models'
17import { MVideoThumbnail } from '../models'
18import {
19 RegisterServerAuthExternalOptions,
20 RegisterServerAuthExternalResult,
21 RegisterServerAuthPassOptions
22} from './register-server-auth.model'
23
24export type PeerTubeHelpers = {
25 logger: Logger
26
27 database: {
28 query: Function
29 }
30
31 videos: {
32 loadByUrl: (url: string) => Bluebird<MVideoThumbnail>
33
34 removeVideo: (videoId: number) => Promise<void>
35 }
36
37 config: {
38 getWebserverUrl: () => string
39 }
40
41 moderation: {
42 blockServer: (options: { byAccountId: number, hostToBlock: string }) => Promise<void>
43 unblockServer: (options: { byAccountId: number, hostToUnblock: string }) => Promise<void>
44 blockAccount: (options: { byAccountId: number, handleToBlock: string }) => Promise<void>
45 unblockAccount: (options: { byAccountId: number, handleToUnblock: string }) => Promise<void>
46
47 blacklistVideo: (options: { videoIdOrUUID: number | string, createOptions: VideoBlacklistCreate }) => Promise<void>
48 unblacklistVideo: (options: { videoIdOrUUID: number | string }) => Promise<void>
49 }
50
51 server: {
52 getServerActor: () => Promise<ActorModel>
53 }
54}
55
56export type RegisterServerOptions = {
57 registerHook: (options: RegisterServerHookOptions) => void
58
59 registerSetting: (options: RegisterServerSettingOptions) => void
60
61 settingsManager: PluginSettingsManager
62
63 storageManager: PluginStorageManager
64
65 videoCategoryManager: PluginVideoCategoryManager
66 videoLanguageManager: PluginVideoLanguageManager
67 videoLicenceManager: PluginVideoLicenceManager
68
69 videoPrivacyManager: PluginVideoPrivacyManager
70 playlistPrivacyManager: PluginPlaylistPrivacyManager
71
72 registerIdAndPassAuth: (options: RegisterServerAuthPassOptions) => void
73 registerExternalAuth: (options: RegisterServerAuthExternalOptions) => RegisterServerAuthExternalResult
74 unregisterIdAndPassAuth: (authName: string) => void
75 unregisterExternalAuth: (authName: string) => void
76
77 // Get plugin router to create custom routes
78 // Base routes of this router are
79 // * /plugins/:pluginName/:pluginVersion/router/...
80 // * /plugins/:pluginName/router/...
81 getRouter(): Router
82
83 peertubeHelpers: PeerTubeHelpers
84}