diff --git a/CHANGELOG.md b/CHANGELOG.md index a389ca13..bf9e2206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ ### Minor changes and fixes +* Peertube v8.0.0 compatibility. * Translations updates. +* Dependencies updates. ## 14.0.1 diff --git a/server/lib/database/channel.ts b/server/lib/database/channel.ts index 66e2009a..53d86615 100644 --- a/server/lib/database/channel.ts +++ b/server/lib/database/channel.ts @@ -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 { 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.') diff --git a/server/lib/helpers.ts b/server/lib/helpers.ts index cd88874c..8f4e6e2a 100644 --- a/server/lib/helpers.ts +++ b/server/lib/helpers.ts @@ -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 { + 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 } diff --git a/server/main.ts b/server/main.ts index f8a56395..4e3d0a23 100644 --- a/server/main.ts +++ b/server/main.ts @@ -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 { 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()