Add hooks documentation
[oweals/peertube.git] / shared / models / plugins / server-hook.model.ts
1 // {hookType}:{api?}.{location}.{subLocation?}.{actionType}.{target}
2
3 export const serverFilterHookObject = {
4   // Filter params/result used to list videos for the REST API
5   // (used by the trending page, recently-added page, local page etc)
6   'filter:api.videos.list.params': true,
7   'filter:api.videos.list.result': true,
8   // Filter the result of the get function
9   // Used to get detailed video information (video watch page for example)
10   'filter:api.video.get.result': true,
11
12   // Filter the result of the accept upload function
13   // If this function returns false then the upload is aborted with an error
14   'filter:api.video.upload.accept.result': true,
15   // Filter the result of the accept comment (thread or reply) functions
16   // If the functions return false then the user cannot post its comment
17   'filter:api.video-thread.create.accept.result': true,
18   'filter:api.video-comment-reply.create.accept.result': true,
19
20   // Filter params/result used to list threads of a specific video
21   // (used by the video watch page)
22   'filter:api.video-threads.list.params': true,
23   'filter:api.video-threads.list.result': true,
24
25   // Filter params/result used to list replies of a specific thread
26   // (used by the video watch page when we click on the "View replies" button)
27   'filter:api.video-thread-comments.list.params': true,
28   'filter:api.video-thread-comments.list.result': true,
29
30   // Filter result used to check if we need to auto blacklist a video
31   // (fired when a local or remote video is created or updated)
32   'filter:video.auto-blacklist.result': true
33 }
34
35 export type ServerFilterHookName = keyof typeof serverFilterHookObject
36
37 export const serverActionHookObject = {
38   // Fired when the application has been loaded and is listening HTTP requests
39   'action:application.listening': true,
40
41   // Fired when a local video is updated
42   'action:api.video.updated': true,
43   // Fired when a local video is deleted
44   'action:api.video.deleted': true,
45   // Fired when a local video is uploaded
46   'action:api.video.uploaded': true,
47   // Fired when a local video is viewed
48   'action:api.video.viewed': true,
49
50   // Fired when a thread is created
51   'action:api.video-thread.created': true,
52   // Fired when a reply to a thread is created
53   'action:api.video-comment-reply.created': true,
54   // Fired when a comment (thread or reply) is deleted
55   'action:api.video-comment.deleted': true
56 }
57
58 export type ServerActionHookName = keyof typeof serverActionHookObject
59
60 export const serverHookObject = Object.assign({}, serverFilterHookObject, serverActionHookObject)
61 export type ServerHookName = keyof typeof serverHookObject
62
63 export interface ServerHook {
64   runHook <T> (hookName: ServerHookName, result?: T, params?: any): Promise<T>
65 }