aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/root-helpers/plugins-manager.ts12
-rw-r--r--server/helpers/custom-validators/plugins.ts4
-rw-r--r--server/lib/plugins/plugin-manager.ts14
-rw-r--r--shared/models/plugins/plugin-package-json.model.ts10
-rw-r--r--shared/models/server/server-config.model.ts4
-rw-r--r--shared/server-commands/server/plugins-command.ts4
6 files changed, 24 insertions, 24 deletions
diff --git a/client/src/root-helpers/plugins-manager.ts b/client/src/root-helpers/plugins-manager.ts
index e574e75a3..1157a274e 100644
--- a/client/src/root-helpers/plugins-manager.ts
+++ b/client/src/root-helpers/plugins-manager.ts
@@ -7,7 +7,7 @@ import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
7import { 7import {
8 ClientHookName, 8 ClientHookName,
9 clientHookObject, 9 clientHookObject,
10 ClientScript, 10 ClientScriptJSON,
11 HTMLServerConfig, 11 HTMLServerConfig,
12 PluginClientScope, 12 PluginClientScope,
13 PluginType, 13 PluginType,
@@ -18,20 +18,20 @@ import {
18 RegisterClientVideoFieldOptions, 18 RegisterClientVideoFieldOptions,
19 RegisteredExternalAuthConfig, 19 RegisteredExternalAuthConfig,
20 ServerConfigPlugin 20 ServerConfigPlugin
21} from '../../../shared/models' 21} from '@shared/models'
22import { environment } from '../environments/environment' 22import { environment } from '../environments/environment'
23import { ClientScript as ClientScriptModule } from '../types/client-script.model' 23import { ClientScript } from '../types'
24 24
25interface HookStructValue extends RegisterClientHookOptions { 25interface HookStructValue extends RegisterClientHookOptions {
26 plugin: ServerConfigPlugin 26 plugin: ServerConfigPlugin
27 clientScript: ClientScript 27 clientScript: ClientScriptJSON
28} 28}
29 29
30type Hooks = { [ name: string ]: HookStructValue[] } 30type Hooks = { [ name: string ]: HookStructValue[] }
31 31
32type PluginInfo = { 32type PluginInfo = {
33 plugin: ServerConfigPlugin 33 plugin: ServerConfigPlugin
34 clientScript: ClientScript 34 clientScript: ClientScriptJSON
35 pluginType: PluginType 35 pluginType: PluginType
36 isTheme: boolean 36 isTheme: boolean
37} 37}
@@ -248,7 +248,7 @@ class PluginsManager {
248 248
249 const absURL = (environment.apiUrl || window.location.origin) + clientScript.script 249 const absURL = (environment.apiUrl || window.location.origin) + clientScript.script
250 return dynamicImport(absURL) 250 return dynamicImport(absURL)
251 .then((script: ClientScriptModule) => { 251 .then((script: ClientScript) => {
252 return script.register({ 252 return script.register({
253 registerHook, 253 registerHook,
254 registerVideoField, 254 registerVideoField,
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts
index f2d4efb32..60b29dc89 100644
--- a/server/helpers/custom-validators/plugins.ts
+++ b/server/helpers/custom-validators/plugins.ts
@@ -2,7 +2,7 @@ import { exists, isArray, isSafePath } from './misc'
2import validator from 'validator' 2import validator from 'validator'
3import { PluginType } from '../../../shared/models/plugins/plugin.type' 3import { PluginType } from '../../../shared/models/plugins/plugin.type'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model' 5import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model'
6import { isUrlValid } from './activitypub/misc' 6import { isUrlValid } from './activitypub/misc'
7 7
8const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS 8const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
@@ -84,7 +84,7 @@ function isThemeNameValid (name: string) {
84 return isPluginNameValid(name) 84 return isPluginNameValid(name)
85} 85}
86 86
87function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { 87function isPackageJSONValid (packageJSON: PluginPackageJSON, pluginType: PluginType) {
88 let result = true 88 let result = true
89 const badFields: string[] = [] 89 const badFields: string[] = []
90 90
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 6c2f4764e..ff00ab9e8 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -5,7 +5,7 @@ import { basename, join } from 'path'
5import { decachePlugin } from '@server/helpers/decache' 5import { decachePlugin } from '@server/helpers/decache'
6import { MOAuthTokenUser, MUser } from '@server/types/models' 6import { MOAuthTokenUser, MUser } from '@server/types/models'
7import { getCompleteLocale } from '@shared/core-utils' 7import { getCompleteLocale } from '@shared/core-utils'
8import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models' 8import { ClientScriptJSON, PluginPackageJSON, PluginTranslation, PluginTranslationPathsJSON, RegisterServerHookOptions } from '@shared/models'
9import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' 9import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 10import { PluginType } from '../../../shared/models/plugins/plugin.type'
11import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model' 11import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model'
@@ -31,7 +31,7 @@ export interface RegisteredPlugin {
31 path: string 31 path: string
32 32
33 staticDirs: { [name: string]: string } 33 staticDirs: { [name: string]: string }
34 clientScripts: { [name: string]: ClientScript } 34 clientScripts: { [name: string]: ClientScriptJSON }
35 35
36 css: string[] 36 css: string[]
37 37
@@ -392,7 +392,7 @@ export class PluginManager implements ServerHook {
392 registerHelpers = result.registerStore 392 registerHelpers = result.registerStore
393 } 393 }
394 394
395 const clientScripts: { [id: string]: ClientScript } = {} 395 const clientScripts: { [id: string]: ClientScriptJSON } = {}
396 for (const c of packageJSON.clientScripts) { 396 for (const c of packageJSON.clientScripts) {
397 clientScripts[c.script] = c 397 clientScripts[c.script] = c
398 } 398 }
@@ -415,7 +415,7 @@ export class PluginManager implements ServerHook {
415 await this.addTranslations(plugin, npmName, packageJSON.translations) 415 await this.addTranslations(plugin, npmName, packageJSON.translations)
416 } 416 }
417 417
418 private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJson) { 418 private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJSON) {
419 const npmName = PluginModel.buildNpmName(plugin.name, plugin.type) 419 const npmName = PluginModel.buildNpmName(plugin.name, plugin.type)
420 420
421 // Delete cache if needed 421 // Delete cache if needed
@@ -442,7 +442,7 @@ export class PluginManager implements ServerHook {
442 442
443 // ###################### Translations ###################### 443 // ###################### Translations ######################
444 444
445 private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PluginTranslationPaths) { 445 private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PluginTranslationPathsJSON) {
446 for (const locale of Object.keys(translationPaths)) { 446 for (const locale of Object.keys(translationPaths)) {
447 const path = translationPaths[locale] 447 const path = translationPaths[locale]
448 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))
@@ -513,7 +513,7 @@ export class PluginManager implements ServerHook {
513 private getPackageJSON (pluginName: string, pluginType: PluginType) { 513 private getPackageJSON (pluginName: string, pluginType: PluginType) {
514 const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json') 514 const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json')
515 515
516 return readJSON(pluginPath) as Promise<PluginPackageJson> 516 return readJSON(pluginPath) as Promise<PluginPackageJSON>
517 } 517 }
518 518
519 private getPluginPath (pluginName: string, pluginType: PluginType) { 519 private getPluginPath (pluginName: string, pluginType: PluginType) {
@@ -572,7 +572,7 @@ export class PluginManager implements ServerHook {
572 } 572 }
573 } 573 }
574 574
575 private sanitizeAndCheckPackageJSONOrThrow (packageJSON: PluginPackageJson, pluginType: PluginType) { 575 private sanitizeAndCheckPackageJSONOrThrow (packageJSON: PluginPackageJSON, pluginType: PluginType) {
576 if (!packageJSON.staticDirs) packageJSON.staticDirs = {} 576 if (!packageJSON.staticDirs) packageJSON.staticDirs = {}
577 if (!packageJSON.css) packageJSON.css = [] 577 if (!packageJSON.css) packageJSON.css = []
578 if (!packageJSON.clientScripts) packageJSON.clientScripts = [] 578 if (!packageJSON.clientScripts) packageJSON.clientScripts = []
diff --git a/shared/models/plugins/plugin-package-json.model.ts b/shared/models/plugins/plugin-package-json.model.ts
index b2f92af80..7ce968ff2 100644
--- a/shared/models/plugins/plugin-package-json.model.ts
+++ b/shared/models/plugins/plugin-package-json.model.ts
@@ -1,15 +1,15 @@
1import { PluginClientScope } from './client/plugin-client-scope.type' 1import { PluginClientScope } from './client/plugin-client-scope.type'
2 2
3export type PluginTranslationPaths = { 3export type PluginTranslationPathsJSON = {
4 [ locale: string ]: string 4 [ locale: string ]: string
5} 5}
6 6
7export type ClientScript = { 7export type ClientScriptJSON = {
8 script: string 8 script: string
9 scopes: PluginClientScope[] 9 scopes: PluginClientScope[]
10} 10}
11 11
12export type PluginPackageJson = { 12export type PluginPackageJSON = {
13 name: string 13 name: string
14 version: string 14 version: string
15 description: string 15 description: string
@@ -23,7 +23,7 @@ export type PluginPackageJson = {
23 staticDirs: { [ name: string ]: string } 23 staticDirs: { [ name: string ]: string }
24 css: string[] 24 css: string[]
25 25
26 clientScripts: ClientScript[] 26 clientScripts: ClientScriptJSON[]
27 27
28 translations: PluginTranslationPaths 28 translations: PluginTranslationPathsJSON
29} 29}
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts
index 0e3b4a3d2..8c0e21621 100644
--- a/shared/models/server/server-config.model.ts
+++ b/shared/models/server/server-config.model.ts
@@ -1,5 +1,5 @@
1import { VideoPrivacy } from '../videos/video-privacy.enum' 1import { VideoPrivacy } from '../videos/video-privacy.enum'
2import { ClientScript } from '../plugins/plugin-package-json.model' 2import { ClientScriptJSON } from '../plugins/plugin-package-json.model'
3import { NSFWPolicyType } from '../videos/nsfw-policy.type' 3import { NSFWPolicyType } from '../videos/nsfw-policy.type'
4import { BroadcastMessageLevel } from './broadcast-message-level.type' 4import { BroadcastMessageLevel } from './broadcast-message-level.type'
5 5
@@ -7,7 +7,7 @@ export interface ServerConfigPlugin {
7 name: string 7 name: string
8 version: string 8 version: string
9 description: string 9 description: string
10 clientScripts: { [name: string]: ClientScript } 10 clientScripts: { [name: string]: ClientScriptJSON }
11} 11}
12 12
13export interface ServerConfigTheme extends ServerConfigPlugin { 13export interface ServerConfigTheme extends ServerConfigPlugin {
diff --git a/shared/server-commands/server/plugins-command.ts b/shared/server-commands/server/plugins-command.ts
index 1c44711da..bb1277a7c 100644
--- a/shared/server-commands/server/plugins-command.ts
+++ b/shared/server-commands/server/plugins-command.ts
@@ -8,7 +8,7 @@ import {
8 PeerTubePlugin, 8 PeerTubePlugin,
9 PeerTubePluginIndex, 9 PeerTubePluginIndex,
10 PeertubePluginIndexList, 10 PeertubePluginIndexList,
11 PluginPackageJson, 11 PluginPackageJSON,
12 PluginTranslation, 12 PluginTranslation,
13 PluginType, 13 PluginType,
14 PublicServerSetting, 14 PublicServerSetting,
@@ -245,7 +245,7 @@ export class PluginsCommand extends AbstractCommand {
245 return writeJSON(path, json) 245 return writeJSON(path, json)
246 } 246 }
247 247
248 getPackageJSON (npmName: string): Promise<PluginPackageJson> { 248 getPackageJSON (npmName: string): Promise<PluginPackageJSON> {
249 const path = this.getPackageJSONPath(npmName) 249 const path = this.getPackageJSONPath(npmName)
250 250
251 return readJSON(path) 251 return readJSON(path)