Fix type conflict

This commit is contained in:
Chocobozzz 2021-12-24 10:40:51 +01:00
parent d17c7b4e8c
commit c7cdac4409
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 24 additions and 24 deletions

View File

@ -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,

View File

@ -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[] = []

View File

@ -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<PluginPackageJson>
return readJSON(pluginPath) as Promise<PluginPackageJSON>
}
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 = []

View File

@ -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
}

View File

@ -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 {

View File

@ -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<PluginPackageJson> {
getPackageJSON (npmName: string): Promise<PluginPackageJSON> {
const path = this.getPackageJSONPath(npmName)
return readJSON(path)