Using types declarations from the official @peertube/peertube-types package.

This commit is contained in:
John Livingston
2022-01-11 01:29:33 +01:00
parent c1fb7b69ed
commit 7db856ce0f
35 changed files with 3131 additions and 275 deletions

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
/*
For internal API, we will generate an api Key that must be provided as
GET parameter for every API call.

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions, MVideoThumbnail } from '@peertube/peertube-types'
async function initCustomFields (options: RegisterServerOptions): Promise<void> {
const registerHook = options.registerHook
const storageManager = options.storageManager
@ -17,11 +18,11 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
const value = body.pluginData['livechat-active']
// NB: on Peertube 3.2.1, value is "true", "false", or "null", as strings.
if (value === true || value === 'true') {
logger.info(`Saving livechat-active=true for video ${video.id}`)
await storageManager.storeData(`livechat-active-${video.id}`, true)
logger.info(`Saving livechat-active=true for video ${video.id as string}`)
await storageManager.storeData(`livechat-active-${video.id as string}`, true)
} else if (value === false || value === 'false' || value === 'null') {
logger.info(`Saving livechat-active=false for video ${video.id}`)
await storageManager.storeData(`livechat-active-${video.id}`, false)
logger.info(`Saving livechat-active=false for video ${video.id as string}`)
await storageManager.storeData(`livechat-active-${video.id as string}`, false)
} else {
logger.error('Unknown value ' + JSON.stringify(value) + ' for livechat-active field.')
}
@ -38,7 +39,14 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
})
}
async function fillVideoCustomFields (options: RegisterServerOptions, video: MVideoThumbnail): Promise<void> {
// FIXME: @peertube/peertube-types@4.0.0-beta.3 is pluginData missing?
interface MVideoThumbnailLiveChat extends MVideoThumbnail {
pluginData?: {
'livechat-active'?: boolean
}
}
async function fillVideoCustomFields (options: RegisterServerOptions, video: MVideoThumbnailLiveChat): Promise<void> {
if (!video) return video
if (!video.pluginData) video.pluginData = {}
if (!video.id) return
@ -46,8 +54,8 @@ async function fillVideoCustomFields (options: RegisterServerOptions, video: MVi
const logger = options.peertubeHelpers.logger
if (video.isLive) {
const result: any = await storageManager.getData(`livechat-active-${video.id}`)
logger.debug(`Video ${video.id} has livechat-active=` + JSON.stringify(result))
const result: any = await storageManager.getData(`livechat-active-${video.id as string}`)
logger.debug(`Video ${video.id as string} has livechat-active=` + JSON.stringify(result))
// NB: I got weird stuff here. Maybe Peertube 3.2.1 bug?
if (result === true || result === 'true') {
video.pluginData['livechat-active'] = true

View File

@ -1,3 +1,5 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
async function getChannelNameById (options: RegisterServerOptions, channelId: number): Promise<string | null> {
if (!channelId) {
throw new Error('Missing channelId')

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
export async function diagBackend (test: string, _options: RegisterServerOptions): Promise<TestResult> {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
import type { ChatType } from '../../../shared/lib/types'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
export async function diagConverse (test: string, { settingsManager }: RegisterServerOptions): Promise<TestResult> {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { diagBackend } from './backend'
import { diagConverse } from './converse'
import { diagChatType } from './chat-type'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { getProsodyConfig, getProsodyConfigContentForDiagnostic, getWorkingDir } from '../prosody/config'
import { getProsodyAbout, testProsodyCorrectlyRunning } from '../prosody/ctl'
import { newResult, TestResult } from './utils'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
export async function diagUri (test: string, { settingsManager }: RegisterServerOptions): Promise<TestResult> {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { newResult, TestResult } from './utils'
export async function diagVideo (test: string, { settingsManager }: RegisterServerOptions): Promise<TestResult> {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions, PeerTubeHelpers } from '@peertube/peertube-types'
import { Response } from 'express'
const packagejson: any = require('../../../package.json')
@ -39,7 +40,16 @@ async function isUserAdmin (options: RegisterServerOptions, res: Response): Prom
return true
}
async function getUserNickname (options: RegisterServerOptions, user: MUserDefault): Promise<string | undefined> {
// FIXME: @peertube/peertube-types@4.0.0-beta.3 is missing user.Account.name definition.
type Unpack<T> = T extends Promise<infer U | undefined> ? U : T
type AuthUser = Unpack<ReturnType<PeerTubeHelpers['user']['getAuthUser']>>
interface AuthUserFixed extends AuthUser {
Account?: {
name: string
}
}
async function getUserNickname (options: RegisterServerOptions, user: AuthUserFixed): Promise<string | undefined> {
const peertubeHelpers = options.peertubeHelpers
const logger = peertubeHelpers.logger

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { Request, Response, NextFunction } from 'express'
import { getAPIKey } from '../apikey'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { pluginShortName } from '../helpers'
import type { ChatType } from '../../../shared/lib/types'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { ProsodyLogLevel } from './config/content'
import * as fs from 'fs'
import * as path from 'path'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions, MVideoThumbnail } from '@peertube/peertube-types'
import { getProsodyDomain } from './domain'
import { getUserNameByChannelId } from '../../database/channel'

View File

@ -1,3 +1,5 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
async function getProsodyDomain (options: RegisterServerOptions): Promise<string> {
const url = options.peertubeHelpers.config.getWebserverUrl()
const matches = url.match(/^https?:\/\/([^:/]*)(:\d+)?(\/|$)/)

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { getProsodyConfig, getProsodyFilePaths, writeProsodyConfig } from './config'
import { startProsodyLogRotate, stopProsodyLogRotate } from './logrotate'
import { changeHttpBindRoute } from '../routers/webchat'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { ProsodyFilePaths } from './config/paths'
type Rotate = (file: string, options: {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { Router, Request, Response, NextFunction } from 'express'
import { videoHasWebchat } from '../../../shared/lib/video'
import { asyncMiddleware } from '../middlewares/async'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { NextFunction, Request, Response } from 'express'
import { initWebchatRouter } from './webchat'
import { initSettingsRouter } from './settings'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { Router, Request, Response, NextFunction } from 'express'
import { diag } from '../diagnostic'
import { getBaseStaticRoute, isUserAdmin } from '../helpers'

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions, MVideoThumbnail } from '@peertube/peertube-types'
import type { Router, RequestHandler, Request, Response, NextFunction } from 'express'
import type { ProxyOptions } from 'express-http-proxy'
import type {

View File

@ -1,3 +1,4 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl'
import type { ChatType, ConverseJSTheme } from '../../shared/lib/types'