]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/types/plugins/register-server-option.model.ts
Add ability for plugins to register ws routes
[github/Chocobozzz/PeerTube.git] / server / types / plugins / register-server-option.model.ts
1 import { Response, Router } from 'express'
2 import { Server } from 'http'
3 import { Logger } from 'winston'
4 import { ActorModel } from '@server/models/actor/actor'
5 import {
6 PluginPlaylistPrivacyManager,
7 PluginSettingsManager,
8 PluginStorageManager,
9 PluginTranscodingManager,
10 PluginVideoCategoryManager,
11 PluginVideoLanguageManager,
12 PluginVideoLicenceManager,
13 PluginVideoPrivacyManager,
14 RegisterServerHookOptions,
15 RegisterServerSettingOptions,
16 ServerConfig,
17 ThumbnailType,
18 VideoBlacklistCreate
19 } from '@shared/models'
20 import { MUserDefault, MVideo, MVideoThumbnail, UserNotificationModelForApi } from '../models'
21 import {
22 RegisterServerAuthExternalOptions,
23 RegisterServerAuthExternalResult,
24 RegisterServerAuthPassOptions
25 } from './register-server-auth.model'
26 import { RegisterServerWebSocketRouteOptions } from './register-server-websocket-route.model'
27
28 export type PeerTubeHelpers = {
29 logger: Logger
30
31 database: {
32 query: Function
33 }
34
35 videos: {
36 loadByUrl: (url: string) => Promise<MVideoThumbnail>
37 loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail>
38
39 removeVideo: (videoId: number) => Promise<void>
40
41 ffprobe: (path: string) => Promise<any>
42
43 getFiles: (id: number | string) => Promise<{
44 webtorrent: {
45 videoFiles: {
46 path: string // Could be null if using remote storage
47 url: string
48 resolution: number
49 size: number
50 fps: number
51 }[]
52 }
53
54 hls: {
55 videoFiles: {
56 path: string // Could be null if using remote storage
57 url: string
58 resolution: number
59 size: number
60 fps: number
61 }[]
62 }
63
64 thumbnails: {
65 type: ThumbnailType
66 path: string
67 }[]
68 }>
69 }
70
71 config: {
72 getWebserverUrl: () => string
73
74 getServerConfig: () => Promise<ServerConfig>
75 }
76
77 moderation: {
78 blockServer: (options: { byAccountId: number, hostToBlock: string }) => Promise<void>
79 unblockServer: (options: { byAccountId: number, hostToUnblock: string }) => Promise<void>
80 blockAccount: (options: { byAccountId: number, handleToBlock: string }) => Promise<void>
81 unblockAccount: (options: { byAccountId: number, handleToUnblock: string }) => Promise<void>
82
83 blacklistVideo: (options: { videoIdOrUUID: number | string, createOptions: VideoBlacklistCreate }) => Promise<void>
84 unblacklistVideo: (options: { videoIdOrUUID: number | string }) => Promise<void>
85 }
86
87 server: {
88 // PeerTube >= 5.0
89 getHTTPServer: () => Server
90
91 getServerActor: () => Promise<ActorModel>
92 }
93
94 socket: {
95 sendNotification: (userId: number, notification: UserNotificationModelForApi) => void
96 sendVideoLiveNewState: (video: MVideo) => void
97 }
98
99 plugin: {
100 // PeerTube >= 3.2
101 getBaseStaticRoute: () => string
102
103 // PeerTube >= 3.2
104 getBaseRouterRoute: () => string
105 // PeerTube >= 5.0
106 getBaseWebSocketRoute: () => string
107
108 // PeerTube >= 3.2
109 getDataDirectoryPath: () => string
110 }
111
112 user: {
113 // PeerTube >= 3.2
114 getAuthUser: (response: Response) => Promise<MUserDefault>
115
116 // PeerTube >= 4.3
117 loadById: (id: number) => Promise<MUserDefault>
118 }
119 }
120
121 export type RegisterServerOptions = {
122 registerHook: (options: RegisterServerHookOptions) => void
123
124 registerSetting: (options: RegisterServerSettingOptions) => void
125
126 settingsManager: PluginSettingsManager
127
128 storageManager: PluginStorageManager
129
130 videoCategoryManager: PluginVideoCategoryManager
131 videoLanguageManager: PluginVideoLanguageManager
132 videoLicenceManager: PluginVideoLicenceManager
133
134 videoPrivacyManager: PluginVideoPrivacyManager
135 playlistPrivacyManager: PluginPlaylistPrivacyManager
136
137 transcodingManager: PluginTranscodingManager
138
139 registerIdAndPassAuth: (options: RegisterServerAuthPassOptions) => void
140 registerExternalAuth: (options: RegisterServerAuthExternalOptions) => RegisterServerAuthExternalResult
141 unregisterIdAndPassAuth: (authName: string) => void
142 unregisterExternalAuth: (authName: string) => void
143
144 // Get plugin router to create custom routes
145 // Base routes of this router are
146 // * /plugins/:pluginName/:pluginVersion/router/...
147 // * /plugins/:pluginName/router/...
148 getRouter(): Router
149
150 // PeerTube >= 5.0
151 // Register WebSocket route
152 // Base routes of the WebSocket router are
153 // * /plugins/:pluginName/:pluginVersion/ws/...
154 // * /plugins/:pluginName/ws/...
155 registerWebSocketRoute: (options: RegisterServerWebSocketRouteOptions) => void
156
157 peertubeHelpers: PeerTubeHelpers
158 }