Removing a hack:

* replacing loadByUrl by loadByIdOrUuid
* breaks compatibility with peertube 3.0.1
* simpler webchat route
* fix uuid escaping in iframe uri
This commit is contained in:
John Livingston 2021-04-30 17:39:27 +02:00
parent fbfd86aab0
commit 9dc0ce6383
5 changed files with 14 additions and 28 deletions

View File

@ -2,6 +2,12 @@
## ???
### Important Notes
* This version requires at least Peertube version 3.1.0. It is no more compatible with Peertube 3.0.1.
### Features
* Builtin Prosody: use mod_muc_http_defaults to set rooms properties and prevent unauthorized room creation.
## v2.0.3

View File

@ -43,16 +43,10 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
let iframeUri = ''
if (settings['chat-use-prosody'] || settings['chat-use-builtin']) {
// Using the builtin converseJS
// FIXME: with Peertube 3.0.1 there is no loadByIdOrUUID method,
// we need to pass the complete url.
const video = videoCache[uuid]
if (video) {
const url: string = video.originInstanceUrl + '/videos/watch/' + uuid
iframeUri = getBaseRoute() + '/webchat?url=' + encodeURIComponent(url)
}
iframeUri = getBaseRoute() + '/webchat/room/' + encodeURIComponent(uuid)
} else if (!settings['chat-use-builtin']) {
iframeUri = settings['chat-uri'] || ''
iframeUri = iframeUri.replace(/{{VIDEO_UUID}}/g, uuid)
iframeUri = iframeUri.replace(/{{VIDEO_UUID}}/g, encodeURIComponent(uuid))
if (!/^https?:\/\//.test(iframeUri)) {
logger.error('The webchaturi must begin with https://')
return null

View File

@ -51,7 +51,7 @@
"webpack-cli": "^3.3.10"
},
"engine": {
"peertube": ">=3.0.1"
"peertube": ">=3.1.0"
},
"homepage": "https://github.com/JohnXLivingston/peertube-plugin-livechat",
"keywords": [

View File

@ -57,7 +57,7 @@ interface PeerTubeHelpers {
videos: {
loadByUrl: (url: string) => Promise<MVideoThumbnail>
// NB: loadByIdOrUUID was introduced in v3.1.0
loadByIdOrUUID?: (id: number | string) => Promise<MVideoThumbnail>
loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail>
removeVideo: (videoId: number) => Promise<void>
}
config: {

View File

@ -20,7 +20,7 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
const router: Router = getRouter()
// eslint-disable-next-line @typescript-eslint/no-misused-promises
router.get('/', async (req: Request, res: Response, next: NextFunction): Promise<void> => {
router.get('/room/:videoUUID', async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
const settings = await settingsManager.getSettings([
'chat-use-prosody', 'chat-use-builtin', 'chat-room', 'chat-server',
@ -54,29 +54,15 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
throw new Error('Builtin chat disabled.')
}
// FIXME: with Peertube 3.0.1 the following method is not available...
// When loadByIdOrUUID is available, change the entry point to
// be /webchat/:videoId
// const id = req.param('videoId')
// const video = await peertubeHelpers.videos.loadByIdOrUUID(id)
let url: string = req.query.url as string || ''
if (!url) {
throw new Error('Missing url parameter)')
}
let video = await peertubeHelpers.videos.loadByUrl(url)
if (!video) {
// FIXME: remove this when loadByIdOrUUID will be available...
// This is a dirty Hack for dev environnements...
url = url.replace(/^https:/, 'http:')
video = await peertubeHelpers.videos.loadByUrl(url)
}
const uuid = req.params.videoUUID
const video = await peertubeHelpers.videos.loadByIdOrUUID(uuid)
if (!video) {
throw new Error('Video not found')
}
let page = '' + (converseJSIndex as string)
// FIXME: Peertube should provide the static folder path. For now:
const staticRelative = '../static'
const staticRelative = '../../../static'
page = page.replace(/{{BASE_STATIC_URL}}/g, staticRelative)
page = page.replace(/{{JID}}/g, server)
room = room.replace(/{{VIDEO_UUID}}/g, video.uuid)