diff options
Diffstat (limited to 'server/lib/plugins/plugin-helpers-builder.ts')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index 4e799b3d4..7b1def6e3 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { Server } from 'http' | ||
2 | import { join } from 'path' | 3 | import { join } from 'path' |
3 | import { ffprobePromise } from '@server/helpers/ffmpeg/ffprobe-utils' | 4 | import { ffprobePromise } from '@server/helpers/ffmpeg/ffprobe-utils' |
4 | import { buildLogger } from '@server/helpers/logger' | 5 | import { buildLogger } from '@server/helpers/logger' |
@@ -13,15 +14,16 @@ import { ServerBlocklistModel } from '@server/models/server/server-blocklist' | |||
13 | import { UserModel } from '@server/models/user/user' | 14 | import { UserModel } from '@server/models/user/user' |
14 | import { VideoModel } from '@server/models/video/video' | 15 | import { VideoModel } from '@server/models/video/video' |
15 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' | 16 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
16 | import { MPlugin } from '@server/types/models' | 17 | import { MPlugin, MVideo, UserNotificationModelForApi } from '@server/types/models' |
17 | import { PeerTubeHelpers } from '@server/types/plugins' | 18 | import { PeerTubeHelpers } from '@server/types/plugins' |
18 | import { VideoBlacklistCreate, VideoStorage } from '@shared/models' | 19 | import { VideoBlacklistCreate, VideoStorage } from '@shared/models' |
19 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' | 20 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' |
21 | import { PeerTubeSocket } from '../peertube-socket' | ||
20 | import { ServerConfigManager } from '../server-config-manager' | 22 | import { ServerConfigManager } from '../server-config-manager' |
21 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | 23 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' |
22 | import { VideoPathManager } from '../video-path-manager' | 24 | import { VideoPathManager } from '../video-path-manager' |
23 | 25 | ||
24 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { | 26 | function buildPluginHelpers (httpServer: Server, pluginModel: MPlugin, npmName: string): PeerTubeHelpers { |
25 | const logger = buildPluginLogger(npmName) | 27 | const logger = buildPluginLogger(npmName) |
26 | 28 | ||
27 | const database = buildDatabaseHelpers() | 29 | const database = buildDatabaseHelpers() |
@@ -29,12 +31,14 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel | |||
29 | 31 | ||
30 | const config = buildConfigHelpers() | 32 | const config = buildConfigHelpers() |
31 | 33 | ||
32 | const server = buildServerHelpers() | 34 | const server = buildServerHelpers(httpServer) |
33 | 35 | ||
34 | const moderation = buildModerationHelpers() | 36 | const moderation = buildModerationHelpers() |
35 | 37 | ||
36 | const plugin = buildPluginRelatedHelpers(pluginModel, npmName) | 38 | const plugin = buildPluginRelatedHelpers(pluginModel, npmName) |
37 | 39 | ||
40 | const socket = buildSocketHelpers() | ||
41 | |||
38 | const user = buildUserHelpers() | 42 | const user = buildUserHelpers() |
39 | 43 | ||
40 | return { | 44 | return { |
@@ -45,6 +49,7 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel | |||
45 | moderation, | 49 | moderation, |
46 | plugin, | 50 | plugin, |
47 | server, | 51 | server, |
52 | socket, | ||
48 | user | 53 | user |
49 | } | 54 | } |
50 | } | 55 | } |
@@ -65,8 +70,10 @@ function buildDatabaseHelpers () { | |||
65 | } | 70 | } |
66 | } | 71 | } |
67 | 72 | ||
68 | function buildServerHelpers () { | 73 | function buildServerHelpers (httpServer: Server) { |
69 | return { | 74 | return { |
75 | getHTTPServer: () => httpServer, | ||
76 | |||
70 | getServerActor: () => getServerActor() | 77 | getServerActor: () => getServerActor() |
71 | } | 78 | } |
72 | } | 79 | } |
@@ -214,10 +221,23 @@ function buildPluginRelatedHelpers (plugin: MPlugin, npmName: string) { | |||
214 | 221 | ||
215 | getBaseRouterRoute: () => `/plugins/${plugin.name}/${plugin.version}/router/`, | 222 | getBaseRouterRoute: () => `/plugins/${plugin.name}/${plugin.version}/router/`, |
216 | 223 | ||
224 | getBaseWebSocketRoute: () => `/plugins/${plugin.name}/${plugin.version}/ws/`, | ||
225 | |||
217 | getDataDirectoryPath: () => join(CONFIG.STORAGE.PLUGINS_DIR, 'data', npmName) | 226 | getDataDirectoryPath: () => join(CONFIG.STORAGE.PLUGINS_DIR, 'data', npmName) |
218 | } | 227 | } |
219 | } | 228 | } |
220 | 229 | ||
230 | function buildSocketHelpers () { | ||
231 | return { | ||
232 | sendNotification: (userId: number, notification: UserNotificationModelForApi) => { | ||
233 | PeerTubeSocket.Instance.sendNotification(userId, notification) | ||
234 | }, | ||
235 | sendVideoLiveNewState: (video: MVideo) => { | ||
236 | PeerTubeSocket.Instance.sendVideoLiveNewState(video) | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
221 | function buildUserHelpers () { | 241 | function buildUserHelpers () { |
222 | return { | 242 | return { |
223 | loadById: (id: number) => { | 243 | loadById: (id: number) => { |