Add new client hooks

This commit is contained in:
Chocobozzz 2019-07-22 15:38:26 +02:00
parent 5336129c36
commit 954b9c5fbc
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 111 additions and 1 deletions

View File

@ -3,6 +3,75 @@ function register ({ registerHook, peertubeHelpers }) {
target: 'action:application.init',
handler: () => onApplicationInit(peertubeHelpers)
})
// Videos list
registerHook({
target: 'filter:api.videos.list.trending.params',
handler: params => Object.assign({}, params, { sort: '-views' })
})
registerHook({
target: 'filter:api.videos.list.trending.result',
handler: result => addSymbolToVideoNameResult(result, '<3')
})
registerHook({
target: 'filter:api.videos.list.local.params',
handler: params => Object.assign({}, params, { sort: '-views' })
})
registerHook({
target: 'filter:api.videos.list.local.result',
handler: result => addSymbolToVideoNameResult(result, ':)')
})
registerHook({
target: 'filter:api.videos.list.recently-added.params',
handler: params => Object.assign({}, params, { filter: 'all-local' })
})
registerHook({
target: 'filter:api.videos.list.recently-added.result',
handler: result => addSymbolToVideoNameResult(result, 'o/')
})
registerHook({
target: 'filter:api.videos.list.user-subscriptions.params',
handler: params => Object.assign({}, params, { sort: '-views' })
})
registerHook({
target: 'filter:api.videos.list.user-subscriptions.result',
handler: result => addSymbolToVideoNameResult(result, ':D')
})
// Search list
registerHook({
target: 'filter:api.search.videos.list.result',
handler: result => {
result.data.forEach(v => v.name += ' SEARCH')
return {
total: result.total,
data: result.data
}
}
})
registerHook({
target: 'filter:api.search.video-channels.list.result',
handler: result => {
result.data.forEach(v => v.displayName += ' :p')
return {
total: result.total,
data: result.data
}
}
})
}
export {
@ -19,3 +88,12 @@ function onApplicationInit (peertubeHelpers) {
topLeftBlock.style.backgroundImage = 'url(' + imageUrl + ')'
}
function addSymbolToVideoNameResult (result, symbol) {
result.data.forEach(v => v.name += ' ' + symbol)
return {
data: result.data,
total: result.total
}
}

View File

@ -3,6 +3,38 @@ function register ({ registerHook, peertubeHelpers }) {
target: 'action:video-watch.init',
handler: () => console.log('Hello video watch world')
})
registerHook({
target: 'action:video-watch.video.loaded',
handler: () => 'video loaded'
})
registerHook({
target: 'filter:api.video-watch.video.get.result',
handler: video => {
video.name += ' \o/'
return video
}
})
registerHook({
target: 'filter:api.video-watch.video-threads.list.result',
handler: result => {
result.comments.forEach(c => c.text += ' THREAD')
return result
}
})
registerHook({
target: 'filter:api.video-watch.video-thread-replies.list.result',
handler: result => {
result.children.forEach(c => c.comment.text += ' REPLY DEEP 1')
return result
}
})
}
export {

View File

@ -1,6 +1,6 @@
{
"name": "peertube-plugin-hello-world",
"version": "0.0.9",
"version": "0.0.10",
"description": "Hello world PeerTube plugin example",
"engine": {
"peertube": ">=1.3.0"