Custom channel emoticons WIP (#130): federation
This commit is contained in:
parent
3c65aa3fd3
commit
200d21d5a6
@ -1,5 +1,4 @@
|
|||||||
TODO: tag conversejs livechat branch, and replace commit ID in build-converse.js
|
TODO: tag conversejs livechat branch, and replace commit ID in build-converse.js
|
||||||
TODO: handle custom emojis url for remote video.
|
|
||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
@ -272,7 +272,10 @@ async function _connectionInfos (
|
|||||||
}
|
}
|
||||||
roomJID = remoteConnectionInfos.roomJID
|
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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
roomJID = await _localRoomJID(
|
roomJID = await _localRoomJID(
|
||||||
|
@ -16,6 +16,7 @@ import { getBoshUri, getWSUri, getWSS2SUri, getPublicChatUri } from '../uri/webc
|
|||||||
import { canonicalizePluginUri } from '../uri/canonicalize'
|
import { canonicalizePluginUri } from '../uri/canonicalize'
|
||||||
import { getProsodyDomain } from '../prosody/config/domain'
|
import { getProsodyDomain } from '../prosody/config/domain'
|
||||||
import { fillVideoCustomFields } from '../custom-fields'
|
import { fillVideoCustomFields } from '../custom-fields'
|
||||||
|
import { Emojis } from '../emojis'
|
||||||
import { loc } from '../loc'
|
import { loc } from '../loc'
|
||||||
import { isDebugMode } from '../debug'
|
import { isDebugMode } from '../debug'
|
||||||
|
|
||||||
@ -153,7 +154,8 @@ async function videoBuildJSONLD (
|
|||||||
type: 'xmpp',
|
type: 'xmpp',
|
||||||
jid: roomJID,
|
jid: roomJID,
|
||||||
links,
|
links,
|
||||||
xmppserver: serverInfos
|
xmppserver: serverInfos,
|
||||||
|
customEmojisUrl: await Emojis.singletonSafe()?.channelCustomEmojisUrl(video.channelId)
|
||||||
}
|
}
|
||||||
Object.assign(videoJsonld, {
|
Object.assign(videoJsonld, {
|
||||||
peertubeLiveChat
|
peertubeLiveChat
|
||||||
|
@ -41,10 +41,16 @@ function sanitizePeertubeLiveChatInfos (
|
|||||||
const xmppserver = sanitizePeertubeLiveChatServerInfos(options, chatInfos.xmppserver, referenceUrl)
|
const xmppserver = sanitizePeertubeLiveChatServerInfos(options, chatInfos.xmppserver, referenceUrl)
|
||||||
if (!xmppserver) { return false }
|
if (!xmppserver) { return false }
|
||||||
|
|
||||||
|
let customEmojisUrl: string | undefined
|
||||||
|
if (('customEmojisUrl' in chatInfos) && chatInfos.customEmojisUrl) {
|
||||||
|
customEmojisUrl = sanitizeCustomEmojisUrl(options, chatInfos.customEmojisUrl, referenceUrl)
|
||||||
|
}
|
||||||
|
|
||||||
const r: LiveChatJSONLDAttributeV1 = {
|
const r: LiveChatJSONLDAttributeV1 = {
|
||||||
type: chatInfos.type,
|
type: chatInfos.type,
|
||||||
jid: chatInfos.jid,
|
jid: chatInfos.jid,
|
||||||
xmppserver
|
xmppserver,
|
||||||
|
customEmojisUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
@ -152,6 +158,48 @@ function sanitizePeertubeLiveChatServerInfos (
|
|||||||
return r
|
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 {
|
interface URLConstraints {
|
||||||
protocol: 'http.' | 'ws.'
|
protocol: 'http.' | 'ws.'
|
||||||
noSearchParams: boolean
|
noSearchParams: boolean
|
||||||
|
@ -55,6 +55,7 @@ interface LiveChatJSONLDInfosV1 {
|
|||||||
type: 'xmpp'
|
type: 'xmpp'
|
||||||
jid: string // room JID
|
jid: string // room JID
|
||||||
xmppserver: PeertubeXMPPServerInfos
|
xmppserver: PeertubeXMPPServerInfos
|
||||||
|
customEmojisUrl?: string // this comes with plugin v10.1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// LiveChatJSONLDInfosV1CompatV0 is a mix of both interface.
|
// LiveChatJSONLDInfosV1CompatV0 is a mix of both interface.
|
||||||
|
@ -42,6 +42,7 @@ export async function initEmojisRouter (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Note: CORS is handled by Peertube.
|
||||||
router.get(
|
router.get(
|
||||||
'/emojis/channel/:channelId/files/:fileName',
|
'/emojis/channel/:channelId/files/:fileName',
|
||||||
asyncMiddleware(async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
asyncMiddleware(async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user