diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/activitypub/videos/shared/creator.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/videos/updater.ts | 3 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 71 | ||||
-rw-r--r-- | server/tests/plugins/action-hooks.ts | 24 |
4 files changed, 71 insertions, 30 deletions
diff --git a/server/lib/activitypub/videos/shared/creator.ts b/server/lib/activitypub/videos/shared/creator.ts index 07252fea2..77321d8a5 100644 --- a/server/lib/activitypub/videos/shared/creator.ts +++ b/server/lib/activitypub/videos/shared/creator.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | 1 | ||
2 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' | 2 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' |
3 | import { sequelizeTypescript } from '@server/initializers/database' | 3 | import { sequelizeTypescript } from '@server/initializers/database' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | ||
4 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' | 5 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' |
5 | import { VideoModel } from '@server/models/video/video' | 6 | import { VideoModel } from '@server/models/video/video' |
6 | import { MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models' | 7 | import { MThumbnail, MVideoFullLight, MVideoThumbnail } from '@server/types/models' |
@@ -61,6 +62,8 @@ export class APVideoCreator extends APVideoAbstractBuilder { | |||
61 | 62 | ||
62 | logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags()) | 63 | logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags()) |
63 | 64 | ||
65 | Hooks.runAction('action:activity-pub.remote-video.created', { video: videoCreated, videoAPObject: this.videoObject }) | ||
66 | |||
64 | return { autoBlacklisted, videoCreated } | 67 | return { autoBlacklisted, videoCreated } |
65 | } catch (err) { | 68 | } catch (err) { |
66 | // FIXME: Use rollback hook when https://github.com/sequelize/sequelize/pull/13038 is released | 69 | // FIXME: Use rollback hook when https://github.com/sequelize/sequelize/pull/13038 is released |
diff --git a/server/lib/activitypub/videos/updater.ts b/server/lib/activitypub/videos/updater.ts index 0bf32f440..3677dc3bb 100644 --- a/server/lib/activitypub/videos/updater.ts +++ b/server/lib/activitypub/videos/updater.ts | |||
@@ -3,6 +3,7 @@ import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/h | |||
3 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' |
4 | import { Notifier } from '@server/lib/notifier' | 4 | import { Notifier } from '@server/lib/notifier' |
5 | import { PeerTubeSocket } from '@server/lib/peertube-socket' | 5 | import { PeerTubeSocket } from '@server/lib/peertube-socket' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | ||
6 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' | 7 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' |
7 | import { VideoLiveModel } from '@server/models/video/video-live' | 8 | import { VideoLiveModel } from '@server/models/video/video-live' |
8 | import { MActor, MChannelAccountLight, MChannelId, MVideoAccountLightBlacklistAllFiles, MVideoFullLight } from '@server/types/models' | 9 | import { MActor, MChannelAccountLight, MChannelId, MVideoAccountLightBlacklistAllFiles, MVideoFullLight } from '@server/types/models' |
@@ -81,6 +82,8 @@ export class APVideoUpdater extends APVideoAbstractBuilder { | |||
81 | PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated) | 82 | PeerTubeSocket.Instance.sendVideoLiveNewState(videoUpdated) |
82 | } | 83 | } |
83 | 84 | ||
85 | Hooks.runAction('action:activity-pub.remote-video.updated', { video: videoUpdated, videoAPObject: this.videoObject }) | ||
86 | |||
84 | logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags()) | 87 | logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags()) |
85 | 88 | ||
86 | return videoUpdated | 89 | return videoUpdated |
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index 5325e14c4..84b479548 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -1,42 +1,53 @@ | |||
1 | async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) { | 1 | async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) { |
2 | const actionHooks = [ | 2 | { |
3 | 'action:application.listening', | 3 | const actionHooks = [ |
4 | 'action:notifier.notification.created', | 4 | 'action:application.listening', |
5 | 'action:notifier.notification.created', | ||
5 | 6 | ||
6 | 'action:api.video.updated', | 7 | 'action:api.video.updated', |
7 | 'action:api.video.deleted', | 8 | 'action:api.video.deleted', |
8 | 'action:api.video.uploaded', | 9 | 'action:api.video.uploaded', |
9 | 'action:api.video.viewed', | 10 | 'action:api.video.viewed', |
10 | 11 | ||
11 | 'action:api.video-channel.created', | 12 | 'action:api.video-channel.created', |
12 | 'action:api.video-channel.updated', | 13 | 'action:api.video-channel.updated', |
13 | 'action:api.video-channel.deleted', | 14 | 'action:api.video-channel.deleted', |
14 | 15 | ||
15 | 'action:api.live-video.created', | 16 | 'action:api.live-video.created', |
16 | 17 | ||
17 | 'action:api.video-thread.created', | 18 | 'action:api.video-thread.created', |
18 | 'action:api.video-comment-reply.created', | 19 | 'action:api.video-comment-reply.created', |
19 | 'action:api.video-comment.deleted', | 20 | 'action:api.video-comment.deleted', |
20 | 21 | ||
21 | 'action:api.video-caption.created', | 22 | 'action:api.video-caption.created', |
22 | 'action:api.video-caption.deleted', | 23 | 'action:api.video-caption.deleted', |
23 | 24 | ||
24 | 'action:api.user.blocked', | 25 | 'action:api.user.blocked', |
25 | 'action:api.user.unblocked', | 26 | 'action:api.user.unblocked', |
26 | 'action:api.user.registered', | 27 | 'action:api.user.registered', |
27 | 'action:api.user.created', | 28 | 'action:api.user.created', |
28 | 'action:api.user.deleted', | 29 | 'action:api.user.deleted', |
29 | 'action:api.user.updated', | 30 | 'action:api.user.updated', |
30 | 'action:api.user.oauth2-got-token', | 31 | 'action:api.user.oauth2-got-token', |
31 | 32 | ||
32 | 'action:api.video-playlist-element.created' | 33 | 'action:api.video-playlist-element.created' |
33 | ] | 34 | ] |
34 | 35 | ||
35 | for (const h of actionHooks) { | 36 | for (const h of actionHooks) { |
36 | registerHook({ | 37 | registerHook({ |
37 | target: h, | 38 | target: h, |
38 | handler: () => peertubeHelpers.logger.debug('Run hook %s.', h) | 39 | handler: () => peertubeHelpers.logger.debug('Run hook %s.', h) |
39 | }) | 40 | }) |
41 | } | ||
42 | |||
43 | for (const h of [ 'action:activity-pub.remote-video.created', 'action:activity-pub.remote-video.updated' ]) { | ||
44 | registerHook({ | ||
45 | target: h, | ||
46 | handler: ({ video, videoAPObject }) => { | ||
47 | peertubeHelpers.logger.debug('Run hook %s - AP %s - video %s.', h, video.name, videoAPObject.name ) | ||
48 | } | ||
49 | }) | ||
50 | } | ||
40 | } | 51 | } |
41 | 52 | ||
42 | registerHook({ | 53 | registerHook({ |
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index a266ae7f1..98228f79d 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts | |||
@@ -4,6 +4,7 @@ import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/mode | |||
4 | import { | 4 | import { |
5 | cleanupTests, | 5 | cleanupTests, |
6 | createMultipleServers, | 6 | createMultipleServers, |
7 | doubleFollow, | ||
7 | killallServers, | 8 | killallServers, |
8 | PeerTubeServer, | 9 | PeerTubeServer, |
9 | PluginsCommand, | 10 | PluginsCommand, |
@@ -36,6 +37,8 @@ describe('Test plugin action hooks', function () { | |||
36 | enabled: true | 37 | enabled: true |
37 | } | 38 | } |
38 | }) | 39 | }) |
40 | |||
41 | await doubleFollow(servers[0], servers[1]) | ||
39 | }) | 42 | }) |
40 | 43 | ||
41 | describe('Application hooks', function () { | 44 | describe('Application hooks', function () { |
@@ -231,6 +234,27 @@ describe('Test plugin action hooks', function () { | |||
231 | }) | 234 | }) |
232 | }) | 235 | }) |
233 | 236 | ||
237 | describe('Activity Pub hooks', function () { | ||
238 | let videoUUID: string | ||
239 | |||
240 | it('Should run action:activity-pub.remote-video.created', async function () { | ||
241 | this.timeout(30000) | ||
242 | |||
243 | const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' }) | ||
244 | videoUUID = uuid | ||
245 | |||
246 | await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video') | ||
247 | }) | ||
248 | |||
249 | it('Should run action:activity-pub.remote-video.updated', async function () { | ||
250 | this.timeout(30000) | ||
251 | |||
252 | await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } }) | ||
253 | |||
254 | await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.updated - AP remote video - video remote video') | ||
255 | }) | ||
256 | }) | ||
257 | |||
234 | after(async function () { | 258 | after(async function () { |
235 | await cleanupTests(servers) | 259 | await cleanupTests(servers) |
236 | }) | 260 | }) |