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:
parent
ed3f236120
commit
901d1e96ab
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,5 +1,21 @@
|
||||
# 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
|
||||
|
||||
### Breaking changes
|
||||
|
2594
package-lock.json
generated
2594
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "peertube-plugin-livechat",
|
||||
"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",
|
||||
"author": {
|
||||
"name": "John Livingston",
|
||||
@ -40,7 +40,7 @@
|
||||
"validate-color": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@peertube/peertube-types": "^4.0.0-beta.3",
|
||||
"@peertube/peertube-types": "^4.2.2",
|
||||
"@purtuga/esm-webpack-plugin": "^1.5.0",
|
||||
"@tsconfig/node12": "^1.0.9",
|
||||
"@types/async": "^3.2.9",
|
||||
@ -71,7 +71,7 @@
|
||||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"engine": {
|
||||
"peertube": ">=3.2.0"
|
||||
"peertube": ">=4.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=7"
|
||||
|
@ -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> {
|
||||
const registerHook = options.registerHook
|
||||
const storageManager = options.storageManager
|
||||
@ -10,7 +10,7 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
|
||||
logger.debug('Saving a video, checking for custom fields')
|
||||
|
||||
const body: any = params.body
|
||||
const video: MVideoThumbnail | undefined = params.video
|
||||
const video: Video | undefined = params.video
|
||||
if (!video || !video.id) {
|
||||
return
|
||||
}
|
||||
@ -18,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 as string}`)
|
||||
await storageManager.storeData(`livechat-active-${video.id as string}`, true)
|
||||
logger.info(`Saving livechat-active=true for video ${video.id.toString()}`)
|
||||
await storageManager.storeData(`livechat-active-${video.id.toString()}`, true)
|
||||
} else if (value === false || value === 'false' || value === 'null') {
|
||||
logger.info(`Saving livechat-active=false for video ${video.id as string}`)
|
||||
await storageManager.storeData(`livechat-active-${video.id as string}`, false)
|
||||
logger.info(`Saving livechat-active=false for video ${video.id.toString()}`)
|
||||
await storageManager.storeData(`livechat-active-${video.id.toString()}`, false)
|
||||
} else {
|
||||
logger.error('Unknown value ' + JSON.stringify(value) + ' for livechat-active field.')
|
||||
}
|
||||
@ -31,7 +31,7 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
|
||||
|
||||
registerHook({
|
||||
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')
|
||||
await fillVideoCustomFields(options, 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?
|
||||
interface MVideoThumbnailLiveChat extends MVideoThumbnail {
|
||||
// FIXME: @peertube/peertype-types@4.2.2: wrongly thinks that loadByIdOrUUID return a MVideoThumbnail.
|
||||
// So we create this custom interface for fillVideoCustomFields to accept Video and MVideoThumbnail types.
|
||||
interface LiveChatCustomFieldsVideo {
|
||||
id?: number | string
|
||||
isLive: boolean
|
||||
pluginData?: {
|
||||
'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.pluginData) video.pluginData = {}
|
||||
if (!video.id) return
|
||||
|
@ -72,16 +72,10 @@ async function isUserAdmin (options: RegisterServerOptions, res: Response): Prom
|
||||
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 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 logger = peertubeHelpers.logger
|
||||
|
||||
|
@ -87,6 +87,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
}
|
||||
res.json(roomDefaults)
|
||||
} else {
|
||||
// FIXME: @peertube/peertype-types@4.2.2: wrongly considere video as MVideoThumbnail.
|
||||
const video = await peertubeHelpers.videos.loadByIdOrUUID(jid)
|
||||
if (!video) {
|
||||
logger.warn(`Video ${jid} not found`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user