diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-22 10:55:28 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-04-22 10:55:28 +0200 |
commit | 302eba0d898e38dca14739486441c27c0be6c62f (patch) | |
tree | 280d18bfe2ad1b16248277371e609c31d6b3aaa4 /server/lib/plugins | |
parent | 3e0e8d4afded28559b7c473061bbdc31ab542e1c (diff) | |
download | PeerTube-302eba0d898e38dca14739486441c27c0be6c62f.tar.gz PeerTube-302eba0d898e38dca14739486441c27c0be6c62f.tar.zst PeerTube-302eba0d898e38dca14739486441c27c0be6c62f.zip |
Add data directory for plugins and some helpers
Diffstat (limited to 'server/lib/plugins')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 44 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 5 |
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 @@ | |||
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 | } |
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 @@ | |||
1 | import decache from 'decache' | 1 | import decache from 'decache' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { createReadStream, createWriteStream } from 'fs' | 3 | import { createReadStream, createWriteStream } from 'fs' |
4 | import { outputFile, readJSON } from 'fs-extra' | 4 | import { ensureDir, outputFile, readJSON } from 'fs-extra' |
5 | import { basename, join } from 'path' | 5 | import { basename, join } from 'path' |
6 | import { MOAuthTokenUser, MUser } from '@server/types/models' | 6 | import { MOAuthTokenUser, MUser } from '@server/types/models' |
7 | import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' | 7 | import { 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 | ||