Fix #751: Peertube v8.0.0 compatibility.
This commit is contained in:
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
### Minor changes and fixes
|
### Minor changes and fixes
|
||||||
|
|
||||||
|
* Peertube v8.0.0 compatibility.
|
||||||
* Translations updates.
|
* Translations updates.
|
||||||
|
* Dependencies updates.
|
||||||
|
|
||||||
## 14.0.1
|
## 14.0.1
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||||
|
import { getPeertubeVersion } from '../helpers'
|
||||||
|
|
||||||
async function getChannelNameById (options: RegisterServerOptions, channelId: number): Promise<string | null> {
|
async function getChannelNameById (options: RegisterServerOptions, channelId: number): Promise<string | null> {
|
||||||
if (!channelId) {
|
if (!channelId) {
|
||||||
@ -12,11 +13,19 @@ async function getChannelNameById (options: RegisterServerOptions, channelId: nu
|
|||||||
throw new Error('Invalid channelId: not an integer')
|
throw new Error('Invalid channelId: not an integer')
|
||||||
}
|
}
|
||||||
const [results] = await options.peertubeHelpers.database.query(
|
const [results] = await options.peertubeHelpers.database.query(
|
||||||
|
getPeertubeVersion().major >= 8
|
||||||
|
? (
|
||||||
|
'SELECT "actor"."preferredUsername"' +
|
||||||
|
' FROM "actor"' +
|
||||||
|
' WHERE "videoChannelId" = ' + channelId.toString()
|
||||||
|
)
|
||||||
|
: (
|
||||||
'SELECT "actor"."preferredUsername"' +
|
'SELECT "actor"."preferredUsername"' +
|
||||||
' FROM "videoChannel"' +
|
' FROM "videoChannel"' +
|
||||||
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
|
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
|
||||||
' WHERE "videoChannel"."id" = ' + channelId.toString()
|
' WHERE "videoChannel"."id" = ' + channelId.toString()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if (!Array.isArray(results)) {
|
if (!Array.isArray(results)) {
|
||||||
throw new Error('getChannelNameById: query result is not an array.')
|
throw new Error('getChannelNameById: query result is not an array.')
|
||||||
}
|
}
|
||||||
@ -70,6 +79,22 @@ async function getChannelInfosById (
|
|||||||
throw new Error('Invalid channelId: not an integer')
|
throw new Error('Invalid channelId: not an integer')
|
||||||
}
|
}
|
||||||
const [results] = await options.peertubeHelpers.database.query(
|
const [results] = await options.peertubeHelpers.database.query(
|
||||||
|
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' +
|
'SELECT' +
|
||||||
' "actor"."preferredUsername" as "channelName",' +
|
' "actor"."preferredUsername" as "channelName",' +
|
||||||
' "videoChannel"."id" as "channelId",' +
|
' "videoChannel"."id" as "channelId",' +
|
||||||
@ -83,6 +108,7 @@ async function getChannelInfosById (
|
|||||||
: ''
|
: ''
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if (!Array.isArray(results)) {
|
if (!Array.isArray(results)) {
|
||||||
throw new Error('getChannelInfosById: query result is not an array.')
|
throw new Error('getChannelInfosById: query result is not an array.')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,6 +107,42 @@ async function getUserNickname (options: RegisterServerOptions, user: AuthUser):
|
|||||||
return undefined
|
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 {
|
export {
|
||||||
RegisterServerOptionsV5,
|
RegisterServerOptionsV5,
|
||||||
getBaseRouterRoute,
|
getBaseRouterRoute,
|
||||||
@ -118,5 +154,7 @@ export {
|
|||||||
pluginName,
|
pluginName,
|
||||||
pluginShortName,
|
pluginShortName,
|
||||||
pluginVersionRegexp,
|
pluginVersionRegexp,
|
||||||
pluginVersionWordBreakRegex
|
pluginVersionWordBreakRegex,
|
||||||
|
initPeertubeversion,
|
||||||
|
getPeertubeVersion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import { updateForbidSpecialCharsHandler } from './lib/prosody/migration/migrate
|
|||||||
import { mustMigrateV14 } from './lib/prosody/migration/migratev14'
|
import { mustMigrateV14 } from './lib/prosody/migration/migratev14'
|
||||||
import { Emojis } from './lib/emojis'
|
import { Emojis } from './lib/emojis'
|
||||||
import { LivechatProsodyAuth } from './lib/prosody/auth'
|
import { LivechatProsodyAuth } from './lib/prosody/auth'
|
||||||
|
import { initPeertubeversion } from './lib/helpers'
|
||||||
import decache from 'decache'
|
import decache from 'decache'
|
||||||
|
|
||||||
// FIXME: Peertube unregister don't have any parameter.
|
// 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.')
|
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.
|
// First: load languages files, so we can localize strings.
|
||||||
await loadLoc()
|
await loadLoc()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user