Custom channel emoticons WIP (#130): federation

This commit is contained in:
John Livingston 2024-06-06 18:04:17 +02:00
parent 3c65aa3fd3
commit 200d21d5a6
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
6 changed files with 58 additions and 4 deletions

View File

@ -1,5 +1,4 @@
TODO: tag conversejs livechat branch, and replace commit ID in build-converse.js
TODO: handle custom emojis url for remote video.
# Changelog

View File

@ -272,7 +272,10 @@ async function _connectionInfos (
}
roomJID = remoteConnectionInfos.roomJID
// TODO: fill customEmojisUrl (how to get the info? is the remote livechat compatible?)
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (remoteChatInfos && remoteChatInfos.customEmojisUrl) {
customEmojisUrl = remoteChatInfos.customEmojisUrl
}
} else {
try {
roomJID = await _localRoomJID(

View File

@ -16,6 +16,7 @@ import { getBoshUri, getWSUri, getWSS2SUri, getPublicChatUri } from '../uri/webc
import { canonicalizePluginUri } from '../uri/canonicalize'
import { getProsodyDomain } from '../prosody/config/domain'
import { fillVideoCustomFields } from '../custom-fields'
import { Emojis } from '../emojis'
import { loc } from '../loc'
import { isDebugMode } from '../debug'
@ -153,7 +154,8 @@ async function videoBuildJSONLD (
type: 'xmpp',
jid: roomJID,
links,
xmppserver: serverInfos
xmppserver: serverInfos,
customEmojisUrl: await Emojis.singletonSafe()?.channelCustomEmojisUrl(video.channelId)
}
Object.assign(videoJsonld, {
peertubeLiveChat

View File

@ -41,10 +41,16 @@ function sanitizePeertubeLiveChatInfos (
const xmppserver = sanitizePeertubeLiveChatServerInfos(options, chatInfos.xmppserver, referenceUrl)
if (!xmppserver) { return false }
let customEmojisUrl: string | undefined
if (('customEmojisUrl' in chatInfos) && chatInfos.customEmojisUrl) {
customEmojisUrl = sanitizeCustomEmojisUrl(options, chatInfos.customEmojisUrl, referenceUrl)
}
const r: LiveChatJSONLDAttributeV1 = {
type: chatInfos.type,
jid: chatInfos.jid,
xmppserver
xmppserver,
customEmojisUrl
}
return r
@ -152,6 +158,48 @@ function sanitizePeertubeLiveChatServerInfos (
return r
}
/**
* Use this function for incoming custom emojis definition url.
* It will sanitize them, by checking everything is ok.
*
* @param options server options
* @param customEmojisUrl the value to test.
* @param referenceUrl optional url string. If given, we must check that urls are on the same domain, to avoid spoofing.
* @returns the url if valid, else undefined.
*/
function sanitizeCustomEmojisUrl (
options: RegisterServerOptions,
customEmojisUrl: any,
referenceUrl?: string
): string | undefined {
let checkHost: undefined | string
if (referenceUrl) {
checkHost = _readReferenceUrl(referenceUrl)
if (!checkHost) {
options.peertubeHelpers.logger.error(
'sanitizeCustomEmojisUrl: got an invalid referenceUrl: ' + referenceUrl
)
return undefined
}
}
if ((typeof customEmojisUrl) !== 'string') { return undefined }
if (
!_validUrl(customEmojisUrl, {
noSearchParams: true,
protocol: 'http.',
domain: checkHost
})
) {
return undefined
}
// No further verification. The frontend must use this url carefully (should only get JSON data).
return customEmojisUrl
}
interface URLConstraints {
protocol: 'http.' | 'ws.'
noSearchParams: boolean

View File

@ -55,6 +55,7 @@ interface LiveChatJSONLDInfosV1 {
type: 'xmpp'
jid: string // room JID
xmppserver: PeertubeXMPPServerInfos
customEmojisUrl?: string // this comes with plugin v10.1.0
}
// LiveChatJSONLDInfosV1CompatV0 is a mix of both interface.

View File

@ -42,6 +42,7 @@ export async function initEmojisRouter (
})
)
// Note: CORS is handled by Peertube.
router.get(
'/emojis/channel/:channelId/files/:fileName',
asyncMiddleware(async (req: Request, res: Response, _next: NextFunction): Promise<void> => {