PeerTube/packages/tests/fixtures/peertube-plugin-test/main.js

527 lines
14 KiB
JavaScript
Raw Permalink Normal View History

2019-07-19 17:30:41 +02:00
async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
2023-03-16 10:36:33 +01:00
{
registerSetting({
name: 'unique-setting',
label: 'Unique setting',
type: 'select',
options: []
})
registerSetting({
name: 'unique-setting',
label: 'Unique setting',
type: 'select',
options: [
{
value: 1,
label: 'One'
}
]
})
2024-07-10 12:12:07 +02:00
registerSetting({
label: 'Unnamed 1',
type: 'input'
})
registerSetting({
label: 'Unnamed 2',
type: 'input'
})
2023-03-16 10:36:33 +01:00
const actionHooks = [
'action:application.listening',
'action:notifier.notification.created',
'action:api.video.updated',
'action:api.video.deleted',
'action:api.video.uploaded',
'action:api.video.viewed',
2023-07-25 15:17:58 +02:00
'action:api.video.file-updated',
2023-03-16 10:36:33 +01:00
'action:api.video-channel.created',
'action:api.video-channel.updated',
'action:api.video-channel.deleted',
'action:api.live-video.created',
Add Podcast RSS feeds (#5487) * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Add correct feed image to RSS channel * Prefer HLS videos for podcast RSS Remove video/stream titles, add optional height attribute to podcast RSS * Prefix podcast RSS images with root server URL * Add optional video query support to include captions * Add transcripts & person images to podcast RSS feed * Prefer webseed/webtorrent files over HLS fragmented mp4s * Experimentally adding podcast fields to basic config page * Add validation for new basic config fields * Don't include "content" in podcast feed, use full description for "description" * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Add correct feed image to RSS channel * Prefer HLS videos for podcast RSS Remove video/stream titles, add optional height attribute to podcast RSS * Prefix podcast RSS images with root server URL * Add optional video query support to include captions * Add transcripts & person images to podcast RSS feed * Prefer webseed/webtorrent files over HLS fragmented mp4s * Experimentally adding podcast fields to basic config page * Add validation for new basic config fields * Don't include "content" in podcast feed, use full description for "description" * Add medium/socialInteract to podcast RSS feeds. Use HTML for description * Change base production image to bullseye, install prosody in image * Add liveItem and trackers to Podcast RSS feeds Remove height from alternateEnclosure, replaced with title. * Clear Podcast RSS feed cache when live streams start/end * Upgrade to Node 16 * Refactor clearCacheRoute to use ApiCache * Remove unnecessary type hint * Update dockerfile to node 16, install python-is-python2 * Use new file paths for captions/playlists * Fix legacy videos in RSS after migration to object storage * Improve method of identifying non-fragmented mp4s in podcast RSS feeds * Don't include fragmented MP4s in podcast RSS feeds * Add experimental support for podcast:categories on the podcast RSS item * Fix undefined category when no videos exist Allows for empty feeds to exist (important for feeds that might only go live) * Add support for podcast:locked -- user has to opt in to show their email * Use comma for podcast:categories delimiter * Make cache clearing async * Fix merge, temporarily test with pfeed-podcast * Syntax changes * Add EXT_MIMETYPE constants for captions * Update & fix tests, fix enclosure mimetypes, remove admin email * Add test for podacst:socialInteract * Add filters hooks for podcast customTags * Remove showdown, updated to pfeed-podcast 6.1.2 * Add 'action:api.live-video.state.updated' hook * Avoid assigning undefined category to podcast feeds * Remove nvmrc * Remove comment * Remove unused podcast config * Remove more unused podcast config * Fix MChannelAccountDefault type hint missed in merge * Remove extra line * Re-add newline in config * Fix lint errors for isEmailPublic * Fix thumbnails in podcast feeds * Requested changes based on review * Provide podcast rss 2.0 only on video channels * Misc cleanup for a less messy PR * Lint fixes * Remove pfeed-podcast * Add peertube version to new hooks * Don't use query include, remove TODO * Remove film medium hack * Clear podcast rss cache before video/channel update hooks * Clear podcast rss cache before video uploaded/deleted hooks * Refactor podcast feed cache clearing * Set correct person name from video channel * Styling * Fix tests --------- Co-authored-by: Chocobozzz <me@florianbigard.com>
2023-05-22 16:00:05 +02:00
'action:live.video.state.updated',
2023-03-16 10:36:33 +01:00
'action:api.video-thread.created',
'action:api.video-comment-reply.created',
'action:api.video-comment.deleted',
'action:api.video-caption.created',
'action:api.video-caption.deleted',
'action:api.user.blocked',
'action:api.user.unblocked',
'action:api.user.registered',
'action:api.user.created',
'action:api.user.deleted',
'action:api.user.updated',
'action:api.user.oauth2-got-token',
'action:api.video-playlist-element.created'
]
for (const h of actionHooks) {
registerHook({
target: h,
handler: () => peertubeHelpers.logger.debug('Run hook %s.', h)
})
}
for (const h of [ 'action:activity-pub.remote-video.created', 'action:activity-pub.remote-video.updated' ]) {
registerHook({
target: h,
handler: ({ video, videoAPObject }) => {
peertubeHelpers.logger.debug('Run hook %s - AP %s - video %s.', h, video.name, videoAPObject.name )
}
})
}
2019-07-19 17:30:41 +02:00
}
2019-07-19 10:37:35 +02:00
registerHook({
2019-07-19 17:30:41 +02:00
target: 'filter:api.videos.list.params',
handler: obj => addToCount(obj)
2019-07-19 10:37:35 +02:00
})
2019-07-19 17:30:41 +02:00
registerHook({
target: 'filter:api.videos.list.result',
2019-07-22 11:14:58 +02:00
handler: obj => addToTotal(obj)
2019-07-19 10:37:35 +02:00
})
registerHook({
target: 'filter:api.video-playlist.videos.list.params',
handler: obj => addToCount(obj)
})
registerHook({
target: 'filter:api.video-playlist.videos.list.result',
handler: obj => addToTotal(obj)
})
registerHook({
target: 'filter:api.accounts.videos.list.params',
handler: obj => addToCount(obj)
})
registerHook({
target: 'filter:api.accounts.videos.list.result',
handler: obj => addToTotal(obj, 2)
})
registerHook({
target: 'filter:api.video-channels.videos.list.params',
handler: obj => addToCount(obj, 3)
})
registerHook({
target: 'filter:api.video-channels.videos.list.result',
handler: obj => addToTotal(obj, 3)
})
2021-01-20 15:28:34 +01:00
registerHook({
target: 'filter:api.user.me.videos.list.params',
handler: obj => addToCount(obj, 4)
})
registerHook({
target: 'filter:api.user.me.videos.list.result',
handler: obj => addToTotal(obj, 4)
})
registerHook({
target: 'filter:api.user.me.get.result',
handler: (result) => {
result.customParam = 'Customized'
return result
}
})
registerHook({
target: 'filter:api.user.me.subscription-videos.list.params',
handler: obj => addToCount(obj)
})
registerHook({
target: 'filter:api.user.me.subscription-videos.list.result',
handler: obj => addToTotal(obj, 4)
})
2019-07-19 17:30:41 +02:00
registerHook({
target: 'filter:api.video.get.result',
handler: video => {
video.name += ' <3'
2019-07-19 10:37:35 +02:00
2019-07-19 17:30:41 +02:00
return video
}
})
2022-08-03 11:17:57 +02:00
// ---------------------------------------------------------------------------
registerHook({
target: 'filter:api.video-channels.list.params',
handler: obj => addToCount(obj, 1)
})
registerHook({
target: 'filter:api.video-channels.list.result',
handler: obj => addToTotal(obj, 1)
})
registerHook({
target: 'filter:api.video-channel.get.result',
handler: channel => {
channel.name += ' <3'
return channel
}
})
// ---------------------------------------------------------------------------
2020-11-06 13:59:50 +01:00
for (const hook of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
registerHook({
target: hook,
handler: ({ accepted }, { videoBody, liveVideoBody }) => {
if (!accepted) return { accepted: false }
2020-11-06 13:59:50 +01:00
const name = videoBody
? videoBody.name
: liveVideoBody.name
if (name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
return { accepted: true }
}
})
}
2023-07-25 15:17:58 +02:00
registerHook({
target: 'filter:api.video.update-file.accept.result',
handler: ({ accepted }, { videoFile }) => {
if (!accepted) return { accepted: false }
if (videoFile.filename.includes('webm')) return { accepted: false, errorMessage: 'no webm' }
return { accepted: true }
}
})
registerHook({
target: 'filter:api.video.pre-import-url.accept.result',
handler: ({ accepted }, { videoImportBody }) => {
if (!accepted) return { accepted: false }
if (videoImportBody.targetUrl.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
return { accepted: true }
}
})
registerHook({
target: 'filter:api.video.pre-import-torrent.accept.result',
handler: ({ accepted }, { videoImportBody }) => {
if (!accepted) return { accepted: false }
if (videoImportBody.name.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
return { accepted: true }
}
})
registerHook({
target: 'filter:api.video.post-import-url.accept.result',
handler: ({ accepted }, { video }) => {
if (!accepted) return { accepted: false }
if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
return { accepted: true }
}
})
registerHook({
target: 'filter:api.video.post-import-torrent.accept.result',
handler: ({ accepted }, { video }) => {
if (!accepted) return { accepted: false }
if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
2019-07-19 17:30:41 +02:00
return { accepted: true }
}
})
2019-07-22 11:14:58 +02:00
2024-02-12 10:49:45 +01:00
registerHook({
target: 'filter:api.video.user-import.accept.result',
handler: ({ accepted }, { videoBody }) => {
if (!accepted) return { accepted: false }
if (videoBody.name === 'video 1') return { accepted: false, errorMessage: 'bad word' }
return { accepted: true }
}
})
2022-09-23 11:38:18 +02:00
// ---------------------------------------------------------------------------
2019-07-22 11:14:58 +02:00
registerHook({
target: 'filter:api.video-thread.create.accept.result',
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
})
registerHook({
target: 'filter:api.video-comment-reply.create.accept.result',
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
})
2022-09-23 11:38:18 +02:00
registerHook({
target: 'filter:activity-pub.remote-video-comment.create.accept.result',
handler: ({ accepted }, { comment }) => checkCommentBadWord(accepted, comment)
})
// ---------------------------------------------------------------------------
2023-03-10 15:08:56 +01:00
registerHook({
target: 'filter:activity-pub.activity.context.build.result',
2024-08-19 10:27:27 +02:00
handler: context => context.concat([ { recordedAt: 'https://schema.org/recordedAt', videoName: 'https://schema.org/name' } ])
2023-03-10 15:08:56 +01:00
})
registerHook({
target: 'filter:activity-pub.video.json-ld.build.result',
handler: (jsonld, { video }) => ({ ...jsonld, videoName: video.name })
})
// ---------------------------------------------------------------------------
2019-07-22 11:14:58 +02:00
registerHook({
target: 'filter:api.video-threads.list.params',
handler: obj => addToCount(obj)
})
registerHook({
target: 'filter:api.video-threads.list.result',
handler: obj => addToTotal(obj)
})
registerHook({
target: 'filter:api.video-thread-comments.list.result',
handler: obj => {
obj.data.forEach(c => c.text += ' <3')
return obj
}
})
registerHook({
target: 'filter:video.auto-blacklist.result',
handler: (blacklisted, { video }) => {
if (blacklisted) return true
if (video.name.includes('please blacklist me')) return true
return false
}
})
2019-10-25 13:54:32 +02:00
2023-01-19 09:28:29 +01:00
{
registerHook({
target: 'filter:api.user.signup.allowed.result',
handler: (result, params) => {
if (params && params.body && params.body.email && params.body.email.includes('jma 1')) {
return { allowed: false, errorMessage: 'No jma 1' }
}
return result
2019-10-25 13:54:32 +02:00
}
2023-01-19 09:28:29 +01:00
})
2019-10-25 13:54:32 +02:00
2023-01-19 09:28:29 +01:00
registerHook({
target: 'filter:api.user.request-signup.allowed.result',
handler: (result, params) => {
if (params && params.body && params.body.email && params.body.email.includes('jma 2')) {
return { allowed: false, errorMessage: 'No jma 2' }
}
return result
}
})
}
2021-03-23 11:54:08 +01:00
registerHook({
target: 'filter:api.download.torrent.allowed.result',
handler: (result, params) => {
if (params && params.downloadName.includes('bad torrent')) {
return { allowed: false, errorMessage: 'Liu Bei' }
}
return result
}
})
registerHook({
target: 'filter:api.download.video.allowed.result',
handler: async (result, params) => {
const loggedInUser = await peertubeHelpers.user.getAuthUser(params.res)
if (loggedInUser) return { allowed: true }
2021-03-23 11:54:08 +01:00
if (params && !params.streamingPlaylist && params.video.name.includes('bad file')) {
return { allowed: false, errorMessage: 'Cao Cao' }
}
if (params && params.streamingPlaylist && params.video.name.includes('bad playlist file')) {
return { allowed: false, errorMessage: 'Sun Jian' }
}
return result
}
})
2021-03-23 17:18:18 +01:00
// ---------------------------------------------------------------------------
2021-03-23 17:18:18 +01:00
registerHook({
target: 'filter:html.embed.video.allowed.result',
handler: (result, params) => {
return {
allowed: false,
html: 'Lu Bu'
}
}
})
registerHook({
target: 'filter:html.embed.video-playlist.allowed.result',
handler: (result, params) => {
return {
allowed: false,
html: 'Diao Chan'
}
}
})
2021-03-24 09:16:48 +01:00
// ---------------------------------------------------------------------------
registerHook({
target: 'filter:html.client.json-ld.result',
handler: (jsonld, context) => {
if (!context || !context.video) return jsonld
return Object.assign(jsonld, { recordedAt: 'http://example.com/recordedAt' })
}
})
// ---------------------------------------------------------------------------
registerHook({
target: 'filter:api.server.stats.get.result',
handler: (result) => {
return { ...result, customStats: 14 }
}
})
2022-08-02 15:29:00 +02:00
registerHook({
target: 'filter:job-queue.process.params',
handler: (object, context) => {
if (context.type !== 'video-studio-edition') return object
object.data.tasks = [
{
name: 'cut',
options: {
start: 0,
end: 1
}
}
]
return object
}
})
registerHook({
2022-08-05 13:40:56 +02:00
target: 'filter:transcoding.auto.resolutions-to-transcode.result',
handler: (object, context) => {
if (context.video.name.includes('transcode-filter')) {
object = [ 100 ]
}
return object
}
})
// Upload/import/live attributes
for (const target of [
'filter:api.video.upload.video-attribute.result',
'filter:api.video.import-url.video-attribute.result',
'filter:api.video.import-torrent.video-attribute.result',
2024-02-12 10:49:45 +01:00
'filter:api.video.live.video-attribute.result',
'filter:api.video.user-import.video-attribute.result'
]) {
registerHook({
target,
handler: (result) => {
return { ...result, description: result.description + ' - ' + target }
}
})
}
2021-03-24 09:16:48 +01:00
{
2021-07-21 16:13:20 +02:00
const filterHooks = [
2021-03-24 09:16:48 +01:00
'filter:api.search.videos.local.list.params',
'filter:api.search.videos.local.list.result',
'filter:api.search.videos.index.list.params',
'filter:api.search.videos.index.list.result',
'filter:api.search.video-channels.local.list.params',
'filter:api.search.video-channels.local.list.result',
'filter:api.search.video-channels.index.list.params',
'filter:api.search.video-channels.index.list.result',
2021-06-17 16:02:38 +02:00
'filter:api.search.video-playlists.local.list.params',
'filter:api.search.video-playlists.local.list.result',
'filter:api.search.video-playlists.index.list.params',
2021-07-21 16:13:20 +02:00
'filter:api.search.video-playlists.index.list.result',
'filter:api.overviews.videos.list.params',
2022-08-02 15:29:00 +02:00
'filter:api.overviews.videos.list.result',
'filter:job-queue.process.params',
'filter:job-queue.process.result'
2021-03-24 09:16:48 +01:00
]
2021-07-21 16:13:20 +02:00
for (const h of filterHooks) {
2021-03-24 09:16:48 +01:00
registerHook({
target: h,
handler: (obj) => {
peertubeHelpers.logger.debug('Run hook %s.', h)
return obj
}
})
}
}
2019-07-19 10:37:35 +02:00
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ############################################################################
function addToCount (obj, amount = 1) {
return Object.assign({}, obj, { count: obj.count + amount })
2019-07-19 10:37:35 +02:00
}
2019-07-22 11:14:58 +02:00
function addToTotal (result, amount = 1) {
2019-07-22 11:14:58 +02:00
return {
data: result.data,
total: result.total + amount
2019-07-22 11:14:58 +02:00
}
}
function checkCommentBadWord (accepted, commentBody) {
if (!accepted) return { accepted: false }
if (commentBody.text.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
return { accepted: true }
}