diff options
Diffstat (limited to 'server/lib/plugins')
-rw-r--r-- | server/lib/plugins/hooks.ts | 6 | ||||
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 6 | ||||
-rw-r--r-- | server/lib/plugins/plugin-index.ts | 20 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 41 | ||||
-rw-r--r-- | server/lib/plugins/register-helpers.ts | 34 |
5 files changed, 58 insertions, 49 deletions
diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts index aa92f03cc..5e97b52a0 100644 --- a/server/lib/plugins/hooks.ts +++ b/server/lib/plugins/hooks.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { ServerActionHookName, ServerFilterHookName } from '../../../shared/models/plugins/server-hook.model' | ||
2 | import { PluginManager } from './plugin-manager' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { ServerActionHookName, ServerFilterHookName } from '../../../shared/models' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { PluginManager } from './plugin-manager' | ||
5 | 5 | ||
6 | type PromiseFunction <U, T> = (params: U) => Promise<T> | Bluebird<T> | 6 | type PromiseFunction <U, T> = (params: U) => Promise<T> | Bluebird<T> |
7 | type RawFunction <U, T> = (params: U) => T | 7 | type RawFunction <U, T> = (params: U) => T |
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index f1bc24d8b..8487672ba 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -15,9 +15,9 @@ import { MPlugin } from '@server/types/models' | |||
15 | import { PeerTubeHelpers } from '@server/types/plugins' | 15 | import { PeerTubeHelpers } from '@server/types/plugins' |
16 | import { VideoBlacklistCreate } from '@shared/models' | 16 | import { VideoBlacklistCreate } from '@shared/models' |
17 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' | 17 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' |
18 | import { getServerConfig } from '../config' | 18 | import { ServerConfigManager } from '../server-config-manager' |
19 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | 19 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' |
20 | import { UserModel } from '@server/models/account/user' | 20 | import { UserModel } from '@server/models/user/user' |
21 | 21 | ||
22 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { | 22 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { |
23 | const logger = buildPluginLogger(npmName) | 23 | const logger = buildPluginLogger(npmName) |
@@ -147,7 +147,7 @@ function buildConfigHelpers () { | |||
147 | }, | 147 | }, |
148 | 148 | ||
149 | getServerConfig () { | 149 | getServerConfig () { |
150 | return getServerConfig() | 150 | return ServerConfigManager.Instance.getServerConfig() |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts index 165bc91b3..119cee8e0 100644 --- a/server/lib/plugins/plugin-index.ts +++ b/server/lib/plugins/plugin-index.ts | |||
@@ -1,16 +1,16 @@ | |||
1 | import { sanitizeUrl } from '@server/helpers/core-utils' | 1 | import { sanitizeUrl } from '@server/helpers/core-utils' |
2 | import { ResultList } from '../../../shared/models' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' | 3 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plugin-index.model' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { PEERTUBE_VERSION } from '@server/initializers/constants' | ||
6 | import { PluginModel } from '@server/models/server/plugin' | ||
5 | import { | 7 | import { |
8 | PeerTubePluginIndex, | ||
9 | PeertubePluginIndexList, | ||
6 | PeertubePluginLatestVersionRequest, | 10 | PeertubePluginLatestVersionRequest, |
7 | PeertubePluginLatestVersionResponse | 11 | PeertubePluginLatestVersionResponse, |
8 | } from '../../../shared/models/plugins/peertube-plugin-latest-version.model' | 12 | ResultList |
9 | import { logger } from '../../helpers/logger' | 13 | } from '@shared/models' |
10 | import { doJSONRequest } from '../../helpers/requests' | ||
11 | import { CONFIG } from '../../initializers/config' | ||
12 | import { PEERTUBE_VERSION } from '../../initializers/constants' | ||
13 | import { PluginModel } from '../../models/server/plugin' | ||
14 | import { PluginManager } from './plugin-manager' | 14 | import { PluginManager } from './plugin-manager' |
15 | 15 | ||
16 | async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) { | 16 | async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) { |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index ba9814383..6599bccca 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -4,16 +4,11 @@ import { createReadStream, createWriteStream } from 'fs' | |||
4 | import { ensureDir, 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 { getCompleteLocale } from '@shared/core-utils' |
8 | import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models' | ||
8 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' | 9 | import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' |
9 | import { | ||
10 | ClientScript, | ||
11 | PluginPackageJson, | ||
12 | PluginTranslationPaths as PackagePluginTranslations | ||
13 | } from '../../../shared/models/plugins/plugin-package-json.model' | ||
14 | import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model' | ||
15 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
16 | import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model' | 11 | import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model' |
17 | import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins' | 12 | import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins' |
18 | import { logger } from '../../helpers/logger' | 13 | import { logger } from '../../helpers/logger' |
19 | import { CONFIG } from '../../initializers/config' | 14 | import { CONFIG } from '../../initializers/config' |
@@ -23,7 +18,6 @@ import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPas | |||
23 | import { ClientHtml } from '../client-html' | 18 | import { ClientHtml } from '../client-html' |
24 | import { RegisterHelpers } from './register-helpers' | 19 | import { RegisterHelpers } from './register-helpers' |
25 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' | 20 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' |
26 | import { getCompleteLocale } from '@shared/core-utils' | ||
27 | 21 | ||
28 | export interface RegisteredPlugin { | 22 | export interface RegisteredPlugin { |
29 | npmName: string | 23 | npmName: string |
@@ -310,22 +304,28 @@ export class PluginManager implements ServerHook { | |||
310 | uninstalled: false, | 304 | uninstalled: false, |
311 | peertubeEngine: packageJSON.engine.peertube | 305 | peertubeEngine: packageJSON.engine.peertube |
312 | }, { returning: true }) | 306 | }, { returning: true }) |
313 | } catch (err) { | 307 | |
314 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err }) | 308 | logger.info('Successful installation of plugin %s.', toInstall) |
309 | |||
310 | await this.registerPluginOrTheme(plugin) | ||
311 | } catch (rootErr) { | ||
312 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) | ||
315 | 313 | ||
316 | try { | 314 | try { |
317 | await removeNpmPlugin(npmName) | 315 | await this.uninstall(npmName) |
318 | } catch (err) { | 316 | } catch (err) { |
319 | logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err }) | 317 | logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) |
318 | |||
319 | try { | ||
320 | await removeNpmPlugin(npmName) | ||
321 | } catch (err) { | ||
322 | logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err }) | ||
323 | } | ||
320 | } | 324 | } |
321 | 325 | ||
322 | throw err | 326 | throw rootErr |
323 | } | 327 | } |
324 | 328 | ||
325 | logger.info('Successful installation of plugin %s.', toInstall) | ||
326 | |||
327 | await this.registerPluginOrTheme(plugin) | ||
328 | |||
329 | return plugin | 329 | return plugin |
330 | } | 330 | } |
331 | 331 | ||
@@ -431,8 +431,7 @@ export class PluginManager implements ServerHook { | |||
431 | 431 | ||
432 | await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath()) | 432 | await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath()) |
433 | 433 | ||
434 | library.register(registerOptions) | 434 | await library.register(registerOptions) |
435 | .catch(err => logger.error('Cannot register plugin %s.', npmName, { err })) | ||
436 | 435 | ||
437 | logger.info('Add plugin %s CSS to global file.', npmName) | 436 | logger.info('Add plugin %s CSS to global file.', npmName) |
438 | 437 | ||
@@ -443,7 +442,7 @@ export class PluginManager implements ServerHook { | |||
443 | 442 | ||
444 | // ###################### Translations ###################### | 443 | // ###################### Translations ###################### |
445 | 444 | ||
446 | private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PackagePluginTranslations) { | 445 | private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PluginTranslationPaths) { |
447 | for (const locale of Object.keys(translationPaths)) { | 446 | for (const locale of Object.keys(translationPaths)) { |
448 | const path = translationPaths[locale] | 447 | const path = translationPaths[locale] |
449 | const json = await readJSON(join(this.getPluginPath(plugin.name, plugin.type), path)) | 448 | const json = await readJSON(join(this.getPluginPath(plugin.name, plugin.type), path)) |
diff --git a/server/lib/plugins/register-helpers.ts b/server/lib/plugins/register-helpers.ts index aa69ca2a2..09275f9ba 100644 --- a/server/lib/plugins/register-helpers.ts +++ b/server/lib/plugins/register-helpers.ts | |||
@@ -26,10 +26,10 @@ import { | |||
26 | PluginVideoLicenceManager, | 26 | PluginVideoLicenceManager, |
27 | PluginVideoPrivacyManager, | 27 | PluginVideoPrivacyManager, |
28 | RegisterServerHookOptions, | 28 | RegisterServerHookOptions, |
29 | RegisterServerSettingOptions | 29 | RegisterServerSettingOptions, |
30 | serverHookObject | ||
30 | } from '@shared/models' | 31 | } from '@shared/models' |
31 | import { serverHookObject } from '@shared/models/plugins/server-hook.model' | 32 | import { VideoTranscodingProfilesManager } from '../transcoding/video-transcoding-profiles' |
32 | import { VideoTranscodingProfilesManager } from '../video-transcoding-profiles' | ||
33 | import { buildPluginHelpers } from './plugin-helpers-builder' | 33 | import { buildPluginHelpers } from './plugin-helpers-builder' |
34 | 34 | ||
35 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' | 35 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' |
@@ -37,18 +37,20 @@ type VideoConstant = { [key in number | string]: string } | |||
37 | 37 | ||
38 | type UpdatedVideoConstant = { | 38 | type UpdatedVideoConstant = { |
39 | [name in AlterableVideoConstant]: { | 39 | [name in AlterableVideoConstant]: { |
40 | added: { key: number | string, label: string }[] | 40 | [ npmName: string]: { |
41 | deleted: { key: number | string, label: string }[] | 41 | added: { key: number | string, label: string }[] |
42 | deleted: { key: number | string, label: string }[] | ||
43 | } | ||
42 | } | 44 | } |
43 | } | 45 | } |
44 | 46 | ||
45 | export class RegisterHelpers { | 47 | export class RegisterHelpers { |
46 | private readonly updatedVideoConstants: UpdatedVideoConstant = { | 48 | private readonly updatedVideoConstants: UpdatedVideoConstant = { |
47 | playlistPrivacy: { added: [], deleted: [] }, | 49 | playlistPrivacy: { }, |
48 | privacy: { added: [], deleted: [] }, | 50 | privacy: { }, |
49 | language: { added: [], deleted: [] }, | 51 | language: { }, |
50 | licence: { added: [], deleted: [] }, | 52 | licence: { }, |
51 | category: { added: [], deleted: [] } | 53 | category: { } |
52 | } | 54 | } |
53 | 55 | ||
54 | private readonly transcodingProfiles: { | 56 | private readonly transcodingProfiles: { |
@@ -377,7 +379,7 @@ export class RegisterHelpers { | |||
377 | const { npmName, type, obj, key } = parameters | 379 | const { npmName, type, obj, key } = parameters |
378 | 380 | ||
379 | if (!obj[key]) { | 381 | if (!obj[key]) { |
380 | logger.warn('Cannot delete %s %s by plugin %s: key does not exist.', type, npmName, key) | 382 | logger.warn('Cannot delete %s by plugin %s: key %s does not exist.', type, npmName, key) |
381 | return false | 383 | return false |
382 | } | 384 | } |
383 | 385 | ||
@@ -388,7 +390,15 @@ export class RegisterHelpers { | |||
388 | } | 390 | } |
389 | } | 391 | } |
390 | 392 | ||
391 | this.updatedVideoConstants[type][npmName].deleted.push({ key, label: obj[key] }) | 393 | const updatedConstants = this.updatedVideoConstants[type][npmName] |
394 | |||
395 | const alreadyAdded = updatedConstants.added.find(a => a.key === key) | ||
396 | if (alreadyAdded) { | ||
397 | updatedConstants.added.filter(a => a.key !== key) | ||
398 | } else if (obj[key]) { | ||
399 | updatedConstants.deleted.push({ key, label: obj[key] }) | ||
400 | } | ||
401 | |||
392 | delete obj[key] | 402 | delete obj[key] |
393 | 403 | ||
394 | return true | 404 | return true |