Basic video redundancy implementation
[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 import { VideoFileModel } from '../../models/video/video-file'
8
9 function getVideoActivityPubUrl (video: VideoModel) {
10   return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
11 }
12
13 function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) {
14   const suffixFPS = videoFile.fps ? '-' + videoFile.fps : ''
15
16   return `${CONFIG.WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
17 }
18
19 function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) {
20   return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
21 }
22
23 function getVideoChannelActivityPubUrl (videoChannelName: string) {
24   return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName
25 }
26
27 function getAccountActivityPubUrl (accountName: string) {
28   return CONFIG.WEBSERVER.URL + '/accounts/' + accountName
29 }
30
31 function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) {
32   return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
33 }
34
35 function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) {
36   return video.url + '/views/' + byActor.uuid + '/' + new Date().toISOString()
37 }
38
39 function getVideoLikeActivityPubUrl (byActor: ActorModel, video: VideoModel) {
40   return byActor.url + '/likes/' + video.id
41 }
42
43 function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel) {
44   return byActor.url + '/dislikes/' + video.id
45 }
46
47 function getVideoSharesActivityPubUrl (video: VideoModel) {
48   return video.url + '/announces'
49 }
50
51 function getVideoCommentsActivityPubUrl (video: VideoModel) {
52   return video.url + '/comments'
53 }
54
55 function getVideoLikesActivityPubUrl (video: VideoModel) {
56   return video.url + '/likes'
57 }
58
59 function getVideoDislikesActivityPubUrl (video: VideoModel) {
60   return video.url + '/dislikes'
61 }
62
63 function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) {
64   const me = actorFollow.ActorFollower
65   const following = actorFollow.ActorFollowing
66
67   return me.url + '/follows/' + following.id
68 }
69
70 function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) {
71   const follower = actorFollow.ActorFollower
72   const me = actorFollow.ActorFollowing
73
74   return follower.url + '/accepts/follows/' + me.id
75 }
76
77 function getAnnounceActivityPubUrl (originalUrl: string, byActor: ActorModel) {
78   return originalUrl + '/announces/' + byActor.id
79 }
80
81 function getDeleteActivityPubUrl (originalUrl: string) {
82   return originalUrl + '/delete'
83 }
84
85 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
86   return originalUrl + '/updates/' + updatedAt
87 }
88
89 function getUndoActivityPubUrl (originalUrl: string) {
90   return originalUrl + '/undo'
91 }
92
93 export {
94   getVideoActivityPubUrl,
95   getVideoChannelActivityPubUrl,
96   getAccountActivityPubUrl,
97   getVideoAbuseActivityPubUrl,
98   getActorFollowActivityPubUrl,
99   getActorFollowAcceptActivityPubUrl,
100   getAnnounceActivityPubUrl,
101   getUpdateActivityPubUrl,
102   getUndoActivityPubUrl,
103   getVideoViewActivityPubUrl,
104   getVideoLikeActivityPubUrl,
105   getVideoDislikeActivityPubUrl,
106   getVideoCommentActivityPubUrl,
107   getDeleteActivityPubUrl,
108   getVideoSharesActivityPubUrl,
109   getVideoCommentsActivityPubUrl,
110   getVideoLikesActivityPubUrl,
111   getVideoDislikesActivityPubUrl,
112   getVideoCacheFileActivityPubUrl
113 }