Fix type conflict
This commit is contained in:
parent
d17c7b4e8c
commit
c7cdac4409
6 changed files with 24 additions and 24 deletions
|
@ -7,7 +7,7 @@ import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
|
||||||
import {
|
import {
|
||||||
ClientHookName,
|
ClientHookName,
|
||||||
clientHookObject,
|
clientHookObject,
|
||||||
ClientScript,
|
ClientScriptJSON,
|
||||||
HTMLServerConfig,
|
HTMLServerConfig,
|
||||||
PluginClientScope,
|
PluginClientScope,
|
||||||
PluginType,
|
PluginType,
|
||||||
|
@ -18,20 +18,20 @@ import {
|
||||||
RegisterClientVideoFieldOptions,
|
RegisterClientVideoFieldOptions,
|
||||||
RegisteredExternalAuthConfig,
|
RegisteredExternalAuthConfig,
|
||||||
ServerConfigPlugin
|
ServerConfigPlugin
|
||||||
} from '../../../shared/models'
|
} from '@shared/models'
|
||||||
import { environment } from '../environments/environment'
|
import { environment } from '../environments/environment'
|
||||||
import { ClientScript as ClientScriptModule } from '../types/client-script.model'
|
import { ClientScript } from '../types'
|
||||||
|
|
||||||
interface HookStructValue extends RegisterClientHookOptions {
|
interface HookStructValue extends RegisterClientHookOptions {
|
||||||
plugin: ServerConfigPlugin
|
plugin: ServerConfigPlugin
|
||||||
clientScript: ClientScript
|
clientScript: ClientScriptJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
type Hooks = { [ name: string ]: HookStructValue[] }
|
type Hooks = { [ name: string ]: HookStructValue[] }
|
||||||
|
|
||||||
type PluginInfo = {
|
type PluginInfo = {
|
||||||
plugin: ServerConfigPlugin
|
plugin: ServerConfigPlugin
|
||||||
clientScript: ClientScript
|
clientScript: ClientScriptJSON
|
||||||
pluginType: PluginType
|
pluginType: PluginType
|
||||||
isTheme: boolean
|
isTheme: boolean
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ class PluginsManager {
|
||||||
|
|
||||||
const absURL = (environment.apiUrl || window.location.origin) + clientScript.script
|
const absURL = (environment.apiUrl || window.location.origin) + clientScript.script
|
||||||
return dynamicImport(absURL)
|
return dynamicImport(absURL)
|
||||||
.then((script: ClientScriptModule) => {
|
.then((script: ClientScript) => {
|
||||||
return script.register({
|
return script.register({
|
||||||
registerHook,
|
registerHook,
|
||||||
registerVideoField,
|
registerVideoField,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { exists, isArray, isSafePath } from './misc'
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model'
|
import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model'
|
||||||
import { isUrlValid } from './activitypub/misc'
|
import { isUrlValid } from './activitypub/misc'
|
||||||
|
|
||||||
const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
|
const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
|
||||||
|
@ -84,7 +84,7 @@ function isThemeNameValid (name: string) {
|
||||||
return isPluginNameValid(name)
|
return isPluginNameValid(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) {
|
function isPackageJSONValid (packageJSON: PluginPackageJSON, pluginType: PluginType) {
|
||||||
let result = true
|
let result = true
|
||||||
const badFields: string[] = []
|
const badFields: string[] = []
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { basename, join } from 'path'
|
||||||
import { decachePlugin } from '@server/helpers/decache'
|
import { decachePlugin } from '@server/helpers/decache'
|
||||||
import { MOAuthTokenUser, MUser } from '@server/types/models'
|
import { MOAuthTokenUser, MUser } from '@server/types/models'
|
||||||
import { getCompleteLocale } from '@shared/core-utils'
|
import { getCompleteLocale } from '@shared/core-utils'
|
||||||
import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models'
|
import { ClientScriptJSON, PluginPackageJSON, PluginTranslation, PluginTranslationPathsJSON, RegisterServerHookOptions } from '@shared/models'
|
||||||
import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
|
import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
|
||||||
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
import { PluginType } from '../../../shared/models/plugins/plugin.type'
|
||||||
import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model'
|
import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model'
|
||||||
|
@ -31,7 +31,7 @@ export interface RegisteredPlugin {
|
||||||
path: string
|
path: string
|
||||||
|
|
||||||
staticDirs: { [name: string]: string }
|
staticDirs: { [name: string]: string }
|
||||||
clientScripts: { [name: string]: ClientScript }
|
clientScripts: { [name: string]: ClientScriptJSON }
|
||||||
|
|
||||||
css: string[]
|
css: string[]
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ export class PluginManager implements ServerHook {
|
||||||
registerHelpers = result.registerStore
|
registerHelpers = result.registerStore
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientScripts: { [id: string]: ClientScript } = {}
|
const clientScripts: { [id: string]: ClientScriptJSON } = {}
|
||||||
for (const c of packageJSON.clientScripts) {
|
for (const c of packageJSON.clientScripts) {
|
||||||
clientScripts[c.script] = c
|
clientScripts[c.script] = c
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ export class PluginManager implements ServerHook {
|
||||||
await this.addTranslations(plugin, npmName, packageJSON.translations)
|
await this.addTranslations(plugin, npmName, packageJSON.translations)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJson) {
|
private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJSON) {
|
||||||
const npmName = PluginModel.buildNpmName(plugin.name, plugin.type)
|
const npmName = PluginModel.buildNpmName(plugin.name, plugin.type)
|
||||||
|
|
||||||
// Delete cache if needed
|
// Delete cache if needed
|
||||||
|
@ -442,7 +442,7 @@ export class PluginManager implements ServerHook {
|
||||||
|
|
||||||
// ###################### Translations ######################
|
// ###################### Translations ######################
|
||||||
|
|
||||||
private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PluginTranslationPaths) {
|
private async addTranslations (plugin: PluginModel, npmName: string, translationPaths: PluginTranslationPathsJSON) {
|
||||||
for (const locale of Object.keys(translationPaths)) {
|
for (const locale of Object.keys(translationPaths)) {
|
||||||
const path = translationPaths[locale]
|
const path = translationPaths[locale]
|
||||||
const json = await readJSON(join(this.getPluginPath(plugin.name, plugin.type), path))
|
const json = await readJSON(join(this.getPluginPath(plugin.name, plugin.type), path))
|
||||||
|
@ -513,7 +513,7 @@ export class PluginManager implements ServerHook {
|
||||||
private getPackageJSON (pluginName: string, pluginType: PluginType) {
|
private getPackageJSON (pluginName: string, pluginType: PluginType) {
|
||||||
const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json')
|
const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json')
|
||||||
|
|
||||||
return readJSON(pluginPath) as Promise<PluginPackageJson>
|
return readJSON(pluginPath) as Promise<PluginPackageJSON>
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPluginPath (pluginName: string, pluginType: PluginType) {
|
private getPluginPath (pluginName: string, pluginType: PluginType) {
|
||||||
|
@ -572,7 +572,7 @@ export class PluginManager implements ServerHook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sanitizeAndCheckPackageJSONOrThrow (packageJSON: PluginPackageJson, pluginType: PluginType) {
|
private sanitizeAndCheckPackageJSONOrThrow (packageJSON: PluginPackageJSON, pluginType: PluginType) {
|
||||||
if (!packageJSON.staticDirs) packageJSON.staticDirs = {}
|
if (!packageJSON.staticDirs) packageJSON.staticDirs = {}
|
||||||
if (!packageJSON.css) packageJSON.css = []
|
if (!packageJSON.css) packageJSON.css = []
|
||||||
if (!packageJSON.clientScripts) packageJSON.clientScripts = []
|
if (!packageJSON.clientScripts) packageJSON.clientScripts = []
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { PluginClientScope } from './client/plugin-client-scope.type'
|
import { PluginClientScope } from './client/plugin-client-scope.type'
|
||||||
|
|
||||||
export type PluginTranslationPaths = {
|
export type PluginTranslationPathsJSON = {
|
||||||
[ locale: string ]: string
|
[ locale: string ]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ClientScript = {
|
export type ClientScriptJSON = {
|
||||||
script: string
|
script: string
|
||||||
scopes: PluginClientScope[]
|
scopes: PluginClientScope[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PluginPackageJson = {
|
export type PluginPackageJSON = {
|
||||||
name: string
|
name: string
|
||||||
version: string
|
version: string
|
||||||
description: string
|
description: string
|
||||||
|
@ -23,7 +23,7 @@ export type PluginPackageJson = {
|
||||||
staticDirs: { [ name: string ]: string }
|
staticDirs: { [ name: string ]: string }
|
||||||
css: string[]
|
css: string[]
|
||||||
|
|
||||||
clientScripts: ClientScript[]
|
clientScripts: ClientScriptJSON[]
|
||||||
|
|
||||||
translations: PluginTranslationPaths
|
translations: PluginTranslationPathsJSON
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { VideoPrivacy } from '../videos/video-privacy.enum'
|
import { VideoPrivacy } from '../videos/video-privacy.enum'
|
||||||
import { ClientScript } from '../plugins/plugin-package-json.model'
|
import { ClientScriptJSON } from '../plugins/plugin-package-json.model'
|
||||||
import { NSFWPolicyType } from '../videos/nsfw-policy.type'
|
import { NSFWPolicyType } from '../videos/nsfw-policy.type'
|
||||||
import { BroadcastMessageLevel } from './broadcast-message-level.type'
|
import { BroadcastMessageLevel } from './broadcast-message-level.type'
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ export interface ServerConfigPlugin {
|
||||||
name: string
|
name: string
|
||||||
version: string
|
version: string
|
||||||
description: string
|
description: string
|
||||||
clientScripts: { [name: string]: ClientScript }
|
clientScripts: { [name: string]: ClientScriptJSON }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerConfigTheme extends ServerConfigPlugin {
|
export interface ServerConfigTheme extends ServerConfigPlugin {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
PeerTubePlugin,
|
PeerTubePlugin,
|
||||||
PeerTubePluginIndex,
|
PeerTubePluginIndex,
|
||||||
PeertubePluginIndexList,
|
PeertubePluginIndexList,
|
||||||
PluginPackageJson,
|
PluginPackageJSON,
|
||||||
PluginTranslation,
|
PluginTranslation,
|
||||||
PluginType,
|
PluginType,
|
||||||
PublicServerSetting,
|
PublicServerSetting,
|
||||||
|
@ -245,7 +245,7 @@ export class PluginsCommand extends AbstractCommand {
|
||||||
return writeJSON(path, json)
|
return writeJSON(path, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackageJSON (npmName: string): Promise<PluginPackageJson> {
|
getPackageJSON (npmName: string): Promise<PluginPackageJSON> {
|
||||||
const path = this.getPackageJSONPath(npmName)
|
const path = this.getPackageJSONPath(npmName)
|
||||||
|
|
||||||
return readJSON(path)
|
return readJSON(path)
|
||||||
|
|
Loading…
Add table
Reference in a new issue