aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins')
-rw-r--r--server/lib/plugins/plugin-helpers-builder.ts44
-rw-r--r--server/lib/plugins/plugin-manager.ts5
2 files changed, 34 insertions, 15 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 @@
1import { PeerTubeHelpers } from '@server/types/plugins' 1import * as express from 'express'
2import { sequelizeTypescript } from '@server/initializers/database' 2import { join } from 'path'
3import { buildLogger } from '@server/helpers/logger' 3import { buildLogger } from '@server/helpers/logger'
4import { VideoModel } from '@server/models/video/video' 4import { CONFIG } from '@server/initializers/config'
5import { WEBSERVER } from '@server/initializers/constants' 5import { WEBSERVER } from '@server/initializers/constants'
6import { ServerModel } from '@server/models/server/server' 6import { sequelizeTypescript } from '@server/initializers/database'
7import { AccountModel } from '@server/models/account/account'
8import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
7import { getServerActor } from '@server/models/application/application' 9import { getServerActor } from '@server/models/application/application'
8import { addServerInBlocklist, removeServerFromBlocklist, addAccountInBlocklist, removeAccountFromBlocklist } from '../blocklist' 10import { ServerModel } from '@server/models/server/server'
9import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 11import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
10import { AccountModel } from '@server/models/account/account' 12import { VideoModel } from '@server/models/video/video'
11import { VideoBlacklistCreate } from '@shared/models'
12import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
13import { VideoBlacklistModel } from '@server/models/video/video-blacklist' 13import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
14import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
15import { getServerConfig } from '../config'
16import { MPlugin } from '@server/types/models' 14import { MPlugin } from '@server/types/models'
15import { PeerTubeHelpers } from '@server/types/plugins'
16import { VideoBlacklistCreate } from '@shared/models'
17import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist'
18import { getServerConfig } from '../config'
19import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
17 20
18function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { 21function 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
148function buildPluginRelatedHelpers (plugin: MPlugin) { 154function 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
164function 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}
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index ae05af721..ba9814383 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -1,7 +1,7 @@
1import decache from 'decache' 1import decache from 'decache'
2import * as express from 'express' 2import * as express from 'express'
3import { createReadStream, createWriteStream } from 'fs' 3import { createReadStream, createWriteStream } from 'fs'
4import { outputFile, readJSON } from 'fs-extra' 4import { ensureDir, outputFile, readJSON } from 'fs-extra'
5import { basename, join } from 'path' 5import { basename, join } from 'path'
6import { MOAuthTokenUser, MUser } from '@server/types/models' 6import { MOAuthTokenUser, MUser } from '@server/types/models'
7import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' 7import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model'
@@ -428,6 +428,9 @@ export class PluginManager implements ServerHook {
428 } 428 }
429 429
430 const { registerOptions, registerStore } = this.getRegisterHelpers(npmName, plugin) 430 const { registerOptions, registerStore } = this.getRegisterHelpers(npmName, plugin)
431
432 await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath())
433
431 library.register(registerOptions) 434 library.register(registerOptions)
432 .catch(err => logger.error('Cannot register plugin %s.', npmName, { err })) 435 .catch(err => logger.error('Cannot register plugin %s.', npmName, { err }))
433 436