Fix #751: Peertube v8.0.0 compatibility.

This commit is contained in:
John Livingston
2025-12-12 15:12:24 +01:00
parent 5ef5b86b39
commit ef78658f4c
4 changed files with 86 additions and 17 deletions

View File

@ -4,7 +4,9 @@
### Minor changes and fixes
* Peertube v8.0.0 compatibility.
* Translations updates.
* Dependencies updates.
## 14.0.1

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import type { RegisterServerOptions } from '@peertube/peertube-types'
import { getPeertubeVersion } from '../helpers'
async function getChannelNameById (options: RegisterServerOptions, channelId: number): Promise<string | null> {
if (!channelId) {
@ -12,10 +13,18 @@ async function getChannelNameById (options: RegisterServerOptions, channelId: nu
throw new Error('Invalid channelId: not an integer')
}
const [results] = await options.peertubeHelpers.database.query(
'SELECT "actor"."preferredUsername"' +
' FROM "videoChannel"' +
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
' WHERE "videoChannel"."id" = ' + channelId.toString()
getPeertubeVersion().major >= 8
? (
'SELECT "actor"."preferredUsername"' +
' FROM "actor"' +
' WHERE "videoChannelId" = ' + channelId.toString()
)
: (
'SELECT "actor"."preferredUsername"' +
' FROM "videoChannel"' +
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
' WHERE "videoChannel"."id" = ' + channelId.toString()
)
)
if (!Array.isArray(results)) {
throw new Error('getChannelNameById: query result is not an array.')
@ -70,18 +79,35 @@ async function getChannelInfosById (
throw new Error('Invalid channelId: not an integer')
}
const [results] = await options.peertubeHelpers.database.query(
'SELECT' +
' "actor"."preferredUsername" as "channelName",' +
' "videoChannel"."id" as "channelId",' +
' "videoChannel"."name" as "channelDisplayName",' +
' "videoChannel"."accountId" as "ownerAccountId"' +
' FROM "videoChannel"' +
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
' WHERE "videoChannel"."id" = ' + channelId.toString() +
(restrictToLocalChannels
? ' AND "serverId" is null '
: ''
)
getPeertubeVersion().major >= 8
? (
'SELECT' +
' "actor"."preferredUsername" as "channelName",' +
' "videoChannel"."id" as "channelId",' +
' "videoChannel"."name" as "channelDisplayName",' +
' "videoChannel"."accountId" as "ownerAccountId"' +
' FROM "videoChannel"' +
' INNER JOIN "actor" ON "actor"."videoChannelId" = "videoChannel"."id"' +
' WHERE "videoChannel"."id" = ' + channelId.toString() +
(restrictToLocalChannels
? ' AND "serverId" is null '
: ''
)
)
: (
'SELECT' +
' "actor"."preferredUsername" as "channelName",' +
' "videoChannel"."id" as "channelId",' +
' "videoChannel"."name" as "channelDisplayName",' +
' "videoChannel"."accountId" as "ownerAccountId"' +
' FROM "videoChannel"' +
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
' WHERE "videoChannel"."id" = ' + channelId.toString() +
(restrictToLocalChannels
? ' AND "serverId" is null '
: ''
)
)
)
if (!Array.isArray(results)) {
throw new Error('getChannelInfosById: query result is not an array.')

View File

@ -107,6 +107,42 @@ async function getUserNickname (options: RegisterServerOptions, user: AuthUser):
return undefined
}
interface PeertubeVersion {
version: string
major: number
minor: number
patch: number
}
let peertubeVersion: PeertubeVersion
async function initPeertubeversion (options: RegisterServerOptions): Promise<void> {
const v = (await options.peertubeHelpers.config.getServerConfig()).serverVersion
const m = v.match(/^(\d+)\.(\d+)\.(\d+)/) // don't use $, in case we have something special like 8.0.0-patchX
if (!m) {
options.peertubeHelpers.logger.error('Cant decode the peertube version (' + v + '), will use 0.0.0.')
peertubeVersion = {
version: '0.0.0',
major: 0,
minor: 0,
patch: 0
}
return
}
peertubeVersion = {
version: v,
major: parseInt(m[1]),
minor: parseInt(m[2]),
patch: parseInt(m[3])
}
}
function getPeertubeVersion (): PeertubeVersion {
if (peertubeVersion === undefined) {
throw new Error('Calling getPeertubeVersion before initPeertubeversion')
}
return peertubeVersion
}
export {
RegisterServerOptionsV5,
getBaseRouterRoute,
@ -118,5 +154,7 @@ export {
pluginName,
pluginShortName,
pluginVersionRegexp,
pluginVersionWordBreakRegex
pluginVersionWordBreakRegex,
initPeertubeversion,
getPeertubeVersion
}

View File

@ -23,6 +23,7 @@ import { updateForbidSpecialCharsHandler } from './lib/prosody/migration/migrate
import { mustMigrateV14 } from './lib/prosody/migration/migratev14'
import { Emojis } from './lib/emojis'
import { LivechatProsodyAuth } from './lib/prosody/auth'
import { initPeertubeversion } from './lib/helpers'
import decache from 'decache'
// FIXME: Peertube unregister don't have any parameter.
@ -38,6 +39,8 @@ async function register (options: RegisterServerOptions): Promise<any> {
throw new Error('Your peertube version is not correct. This plugin is not compatible with Peertube < 3.2.0.')
}
await initPeertubeversion(options)
// First: load languages files, so we can localize strings.
await loadLoc()