From c7cdac440970525d78d257a055899c26f6899a82 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Dec 2021 10:40:51 +0100 Subject: [PATCH] Fix type conflict --- client/src/root-helpers/plugins-manager.ts | 12 ++++++------ server/helpers/custom-validators/plugins.ts | 4 ++-- server/lib/plugins/plugin-manager.ts | 14 +++++++------- shared/models/plugins/plugin-package-json.model.ts | 10 +++++----- shared/models/server/server-config.model.ts | 4 ++-- shared/server-commands/server/plugins-command.ts | 4 ++-- 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' import { ClientHookName, clientHookObject, - ClientScript, + ClientScriptJSON, HTMLServerConfig, PluginClientScope, PluginType, @@ -18,20 +18,20 @@ import { RegisterClientVideoFieldOptions, RegisteredExternalAuthConfig, ServerConfigPlugin -} from '../../../shared/models' +} from '@shared/models' import { environment } from '../environments/environment' -import { ClientScript as ClientScriptModule } from '../types/client-script.model' +import { ClientScript } from '../types' interface HookStructValue extends RegisterClientHookOptions { plugin: ServerConfigPlugin - clientScript: ClientScript + clientScript: ClientScriptJSON } type Hooks = { [ name: string ]: HookStructValue[] } type PluginInfo = { plugin: ServerConfigPlugin - clientScript: ClientScript + clientScript: ClientScriptJSON pluginType: PluginType isTheme: boolean } @@ -248,7 +248,7 @@ class PluginsManager { const absURL = (environment.apiUrl || window.location.origin) + clientScript.script return dynamicImport(absURL) - .then((script: ClientScriptModule) => { + .then((script: ClientScript) => { return script.register({ registerHook, 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' import validator from 'validator' import { PluginType } from '../../../shared/models/plugins/plugin.type' 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' const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS @@ -84,7 +84,7 @@ function isThemeNameValid (name: string) { return isPluginNameValid(name) } -function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { +function isPackageJSONValid (packageJSON: PluginPackageJSON, pluginType: PluginType) { let result = true const badFields: string[] = [] 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' import { decachePlugin } from '@server/helpers/decache' import { MOAuthTokenUser, MUser } from '@server/types/models' 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 { PluginType } from '../../../shared/models/plugins/plugin.type' import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model' @@ -31,7 +31,7 @@ export interface RegisteredPlugin { path: string staticDirs: { [name: string]: string } - clientScripts: { [name: string]: ClientScript } + clientScripts: { [name: string]: ClientScriptJSON } css: string[] @@ -392,7 +392,7 @@ export class PluginManager implements ServerHook { registerHelpers = result.registerStore } - const clientScripts: { [id: string]: ClientScript } = {} + const clientScripts: { [id: string]: ClientScriptJSON } = {} for (const c of packageJSON.clientScripts) { clientScripts[c.script] = c } @@ -415,7 +415,7 @@ export class PluginManager implements ServerHook { 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) // Delete cache if needed @@ -442,7 +442,7 @@ export class PluginManager implements ServerHook { // ###################### 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)) { const path = translationPaths[locale] 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) { const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json') - return readJSON(pluginPath) as Promise + return readJSON(pluginPath) as Promise } 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.css) packageJSON.css = [] 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 @@ import { PluginClientScope } from './client/plugin-client-scope.type' -export type PluginTranslationPaths = { +export type PluginTranslationPathsJSON = { [ locale: string ]: string } -export type ClientScript = { +export type ClientScriptJSON = { script: string scopes: PluginClientScope[] } -export type PluginPackageJson = { +export type PluginPackageJSON = { name: string version: string description: string @@ -23,7 +23,7 @@ export type PluginPackageJson = { staticDirs: { [ name: string ]: string } css: string[] - clientScripts: ClientScript[] + clientScripts: ClientScriptJSON[] - translations: PluginTranslationPaths + translations: PluginTranslationPathsJSON } 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 @@ 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 { BroadcastMessageLevel } from './broadcast-message-level.type' @@ -7,7 +7,7 @@ export interface ServerConfigPlugin { name: string version: string description: string - clientScripts: { [name: string]: ClientScript } + clientScripts: { [name: string]: ClientScriptJSON } } export 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 { PeerTubePlugin, PeerTubePluginIndex, PeertubePluginIndexList, - PluginPackageJson, + PluginPackageJSON, PluginTranslation, PluginType, PublicServerSetting, @@ -245,7 +245,7 @@ export class PluginsCommand extends AbstractCommand { return writeJSON(path, json) } - getPackageJSON (npmName: string): Promise { + getPackageJSON (npmName: string): Promise { const path = this.getPackageJSONPath(npmName) return readJSON(path)