Activity Pub improvements
[oweals/peertube.git] / server / lib / activitypub / url.ts
1 import { CONFIG } from '../../initializers'
2 import { ActorModel } from '../../models/activitypub/actor'
3 import { ActorFollowModel } from '../../models/activitypub/actor-follow'
4 import { VideoModel } from '../../models/video/video'
5 import { VideoAbuseModel } from '../../models/video/video-abuse'
6 import { VideoCommentModel } from '../../models/video/video-comment'
7
8 function getVideoActivityPubUrl (video: VideoModel) {
9   return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
10 }
11
12 function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) {
13   return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
14 }
15
16 function getVideoChannelActivityPubUrl (videoChannelUUID: string) {
17   return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelUUID
18 }
19
20 function getAccountActivityPubUrl (accountName: string) {
21   return CONFIG.WEBSERVER.URL + '/accounts/' + accountName
22 }
23
24 function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) {
25   return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
26 }
27
28 function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) {
29   return video.url + '/views/' + byActor.uuid + '/' + new Date().toISOString()
30 }
31
32 function getVideoLikeActivityPubUrl (byActor: ActorModel, video: VideoModel) {
33   return byActor.url + '/likes/' + video.id
34 }
35
36 function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel) {
37   return byActor.url + '/dislikes/' + video.id
38 }
39
40 function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) {
41   const me = actorFollow.ActorFollower
42   const following = actorFollow.ActorFollowing
43
44   return me.url + '/follows/' + following.id
45 }
46
47 function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) {
48   const follower = actorFollow.ActorFollower
49   const me = actorFollow.ActorFollowing
50
51   return follower.url + '/accepts/follows/' + me.id
52 }
53
54 function getAnnounceActivityPubUrl (originalUrl: string, byActor: ActorModel) {
55   return originalUrl + '/announces/' + byActor.id
56 }
57
58 function getDeleteActivityPubUrl (originalUrl: string) {
59   return originalUrl + '/delete'
60 }
61
62 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
63   return originalUrl + '/updates/' + updatedAt
64 }
65
66 function getUndoActivityPubUrl (originalUrl: string) {
67   return originalUrl + '/undo'
68 }
69
70 export {
71   getVideoActivityPubUrl,
72   getVideoChannelActivityPubUrl,
73   getAccountActivityPubUrl,
74   getVideoAbuseActivityPubUrl,
75   getActorFollowActivityPubUrl,
76   getActorFollowAcceptActivityPubUrl,
77   getAnnounceActivityPubUrl,
78   getUpdateActivityPubUrl,
79   getUndoActivityPubUrl,
80   getVideoViewActivityPubUrl,
81   getVideoLikeActivityPubUrl,
82   getVideoDislikeActivityPubUrl,
83   getVideoCommentActivityPubUrl,
84   getDeleteActivityPubUrl
85 }