diff options
Diffstat (limited to 'server/lib/plugins/plugin-helpers-builder.ts')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index cbd849742..d57c69ef0 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -1,19 +1,22 @@ | |||
1 | import { PeerTubeHelpers } from '@server/types/plugins' | 1 | import * as express from 'express' |
2 | import { sequelizeTypescript } from '@server/initializers/database' | 2 | import { join } from 'path' |
3 | import { buildLogger } from '@server/helpers/logger' | 3 | import { buildLogger } from '@server/helpers/logger' |
4 | import { VideoModel } from '@server/models/video/video' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { WEBSERVER } from '@server/initializers/constants' | 5 | import { WEBSERVER } from '@server/initializers/constants' |
6 | import { ServerModel } from '@server/models/server/server' | 6 | import { sequelizeTypescript } from '@server/initializers/database' |
7 | import { AccountModel } from '@server/models/account/account' | ||
8 | import { AccountBlocklistModel } from '@server/models/account/account-blocklist' | ||
7 | import { getServerActor } from '@server/models/application/application' | 9 | import { getServerActor } from '@server/models/application/application' |
8 | import { addServerInBlocklist, removeServerFromBlocklist, addAccountInBlocklist, removeAccountFromBlocklist } from '../blocklist' | 10 | import { ServerModel } from '@server/models/server/server' |
9 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' | 11 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' |
10 | import { AccountModel } from '@server/models/account/account' | 12 | import { VideoModel } from '@server/models/video/video' |
11 | import { VideoBlacklistCreate } from '@shared/models' | ||
12 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | ||
13 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' | 13 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
14 | import { AccountBlocklistModel } from '@server/models/account/account-blocklist' | ||
15 | import { getServerConfig } from '../config' | ||
16 | import { MPlugin } from '@server/types/models' | 14 | import { MPlugin } from '@server/types/models' |
15 | import { PeerTubeHelpers } from '@server/types/plugins' | ||
16 | import { VideoBlacklistCreate } from '@shared/models' | ||
17 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' | ||
18 | import { getServerConfig } from '../config' | ||
19 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | ||
17 | 20 | ||
18 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { | 21 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { |
19 | const logger = buildPluginLogger(npmName) | 22 | const logger = buildPluginLogger(npmName) |
@@ -27,7 +30,9 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel | |||
27 | 30 | ||
28 | const moderation = buildModerationHelpers() | 31 | const moderation = buildModerationHelpers() |
29 | 32 | ||
30 | const plugin = buildPluginRelatedHelpers(pluginModel) | 33 | const plugin = buildPluginRelatedHelpers(pluginModel, npmName) |
34 | |||
35 | const user = buildUserHelpers() | ||
31 | 36 | ||
32 | return { | 37 | return { |
33 | logger, | 38 | logger, |
@@ -36,7 +41,8 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel | |||
36 | config, | 41 | config, |
37 | moderation, | 42 | moderation, |
38 | plugin, | 43 | plugin, |
39 | server | 44 | server, |
45 | user | ||
40 | } | 46 | } |
41 | } | 47 | } |
42 | 48 | ||
@@ -145,8 +151,18 @@ function buildConfigHelpers () { | |||
145 | } | 151 | } |
146 | } | 152 | } |
147 | 153 | ||
148 | function buildPluginRelatedHelpers (plugin: MPlugin) { | 154 | function buildPluginRelatedHelpers (plugin: MPlugin, npmName: string) { |
155 | return { | ||
156 | getBaseStaticRoute: () => `/plugins/${plugin.name}/${plugin.version}/static/`, | ||
157 | |||
158 | getBaseRouterRoute: () => `/plugins/${plugin.name}/${plugin.version}/router/`, | ||
159 | |||
160 | getDataDirectoryPath: () => join(CONFIG.STORAGE.PLUGINS_DIR, 'data', npmName) | ||
161 | } | ||
162 | } | ||
163 | |||
164 | function buildUserHelpers () { | ||
149 | return { | 165 | return { |
150 | getBaseStaticRoute: () => `/plugins/${plugin.name}/${plugin.version}/static/` | 166 | getAuthUser: (res: express.Response) => res.locals.oauth?.token?.User |
151 | } | 167 | } |
152 | } | 168 | } |