Update @peertube/peertube-types to 4.2.2:

* using a stable version (4.2.2)
* minimum Peertube version is now 4.2.0
* removing some type customizations

Related to issue #122.

Note: there are still some quirks. See: https://github.com/Chocobozzz/PeerTube/issues/5446
This commit is contained in:
John Livingston 2022-12-07 16:55:44 +01:00
parent ed3f236120
commit 901d1e96ab
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
6 changed files with 1558 additions and 1090 deletions

View File

@ -1,5 +1,21 @@
# Changelog # Changelog
## 6.1.0 (Not Released Yet)
### Important Notes
If you haven't upgraded to v6.0.0 yet, please read v6.0.0 changelog first.
### New Features
### Changes
* Minimum Peertube version is now v4.2.0.
### Minor changes and fixes
* Update @types/peertube to v4.2.2 (requiring Peertube v4.2.0).
## 6.0.0 ## 6.0.0
### Breaking changes ### Breaking changes

2594
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "peertube-plugin-livechat", "name": "peertube-plugin-livechat",
"description": "PeerTube plugin livechat: offers a way to embed a chat system into Peertube.", "description": "PeerTube plugin livechat: offers a way to embed a chat system into Peertube.",
"version": "6.0.0", "version": "6.1.0",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"author": { "author": {
"name": "John Livingston", "name": "John Livingston",
@ -40,7 +40,7 @@
"validate-color": "^2.2.1" "validate-color": "^2.2.1"
}, },
"devDependencies": { "devDependencies": {
"@peertube/peertube-types": "^4.0.0-beta.3", "@peertube/peertube-types": "^4.2.2",
"@purtuga/esm-webpack-plugin": "^1.5.0", "@purtuga/esm-webpack-plugin": "^1.5.0",
"@tsconfig/node12": "^1.0.9", "@tsconfig/node12": "^1.0.9",
"@types/async": "^3.2.9", "@types/async": "^3.2.9",
@ -71,7 +71,7 @@
"webpack-cli": "^3.3.12" "webpack-cli": "^3.3.12"
}, },
"engine": { "engine": {
"peertube": ">=3.2.0" "peertube": ">=4.3.0"
}, },
"engines": { "engines": {
"npm": ">=7" "npm": ">=7"

View File

@ -1,4 +1,4 @@
import type { RegisterServerOptions, MVideoThumbnail } from '@peertube/peertube-types' import type { RegisterServerOptions, Video } from '@peertube/peertube-types'
async function initCustomFields (options: RegisterServerOptions): Promise<void> { async function initCustomFields (options: RegisterServerOptions): Promise<void> {
const registerHook = options.registerHook const registerHook = options.registerHook
const storageManager = options.storageManager const storageManager = options.storageManager
@ -10,7 +10,7 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
logger.debug('Saving a video, checking for custom fields') logger.debug('Saving a video, checking for custom fields')
const body: any = params.body const body: any = params.body
const video: MVideoThumbnail | undefined = params.video const video: Video | undefined = params.video
if (!video || !video.id) { if (!video || !video.id) {
return return
} }
@ -18,11 +18,11 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
const value = body.pluginData['livechat-active'] const value = body.pluginData['livechat-active']
// NB: on Peertube 3.2.1, value is "true", "false", or "null", as strings. // NB: on Peertube 3.2.1, value is "true", "false", or "null", as strings.
if (value === true || value === 'true') { if (value === true || value === 'true') {
logger.info(`Saving livechat-active=true for video ${video.id as string}`) logger.info(`Saving livechat-active=true for video ${video.id.toString()}`)
await storageManager.storeData(`livechat-active-${video.id as string}`, true) await storageManager.storeData(`livechat-active-${video.id.toString()}`, true)
} else if (value === false || value === 'false' || value === 'null') { } else if (value === false || value === 'false' || value === 'null') {
logger.info(`Saving livechat-active=false for video ${video.id as string}`) logger.info(`Saving livechat-active=false for video ${video.id.toString()}`)
await storageManager.storeData(`livechat-active-${video.id as string}`, false) await storageManager.storeData(`livechat-active-${video.id.toString()}`, false)
} else { } else {
logger.error('Unknown value ' + JSON.stringify(value) + ' for livechat-active field.') logger.error('Unknown value ' + JSON.stringify(value) + ' for livechat-active field.')
} }
@ -31,7 +31,7 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
registerHook({ registerHook({
target: 'filter:api.video.get.result', target: 'filter:api.video.get.result',
handler: async (video: MVideoThumbnail): Promise<MVideoThumbnail> => { handler: async (video: Video): Promise<Video> => {
logger.debug('Getting a video, searching for custom fields') logger.debug('Getting a video, searching for custom fields')
await fillVideoCustomFields(options, video) await fillVideoCustomFields(options, video)
return video return video
@ -39,14 +39,17 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
}) })
} }
// FIXME: @peertube/peertube-types@4.0.0-beta.3 is pluginData missing? // FIXME: @peertube/peertype-types@4.2.2: wrongly thinks that loadByIdOrUUID return a MVideoThumbnail.
interface MVideoThumbnailLiveChat extends MVideoThumbnail { // So we create this custom interface for fillVideoCustomFields to accept Video and MVideoThumbnail types.
interface LiveChatCustomFieldsVideo {
id?: number | string
isLive: boolean
pluginData?: { pluginData?: {
'livechat-active'?: boolean 'livechat-active'?: boolean
} }
} }
async function fillVideoCustomFields (options: RegisterServerOptions, video: MVideoThumbnailLiveChat): Promise<void> { async function fillVideoCustomFields (options: RegisterServerOptions, video: LiveChatCustomFieldsVideo): Promise<void> {
if (!video) return video if (!video) return video
if (!video.pluginData) video.pluginData = {} if (!video.pluginData) video.pluginData = {}
if (!video.id) return if (!video.id) return

View File

@ -72,16 +72,10 @@ async function isUserAdmin (options: RegisterServerOptions, res: Response): Prom
return true return true
} }
// 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 Unpack<T> = T extends Promise<infer U | undefined> ? U : T
type AuthUser = Unpack<ReturnType<PeerTubeHelpers['user']['getAuthUser']>> type AuthUser = Unpack<ReturnType<PeerTubeHelpers['user']['getAuthUser']>>
interface AuthUserFixed extends AuthUser {
Account?: {
name: string
}
}
async function getUserNickname (options: RegisterServerOptions, user: AuthUserFixed): Promise<string | undefined> { async function getUserNickname (options: RegisterServerOptions, user: AuthUser): Promise<string | undefined> {
const peertubeHelpers = options.peertubeHelpers const peertubeHelpers = options.peertubeHelpers
const logger = peertubeHelpers.logger const logger = peertubeHelpers.logger

View File

@ -87,6 +87,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
} }
res.json(roomDefaults) res.json(roomDefaults)
} else { } else {
// FIXME: @peertube/peertype-types@4.2.2: wrongly considere video as MVideoThumbnail.
const video = await peertubeHelpers.videos.loadByIdOrUUID(jid) const video = await peertubeHelpers.videos.loadByIdOrUUID(jid)
if (!video) { if (!video) {
logger.warn(`Video ${jid} not found`) logger.warn(`Video ${jid} not found`)