00b4e8852451d638474ab5b389092c7e6eeb1129
[oweals/peertube.git] / server / lib / activitypub / url.ts
1 import { CONFIG } from '../../initializers'
2 import { AccountModel } from '../../models/account/account'
3 import { AccountFollowModel } from '../../models/account/account-follow'
4 import { VideoModel } from '../../models/video/video'
5 import { VideoAbuseModel } from '../../models/video/video-abuse'
6 import { VideoChannelModel } from '../../models/video/video-channel'
7
8 function getVideoActivityPubUrl (video: VideoModel) {
9   return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
10 }
11
12 function getVideoChannelActivityPubUrl (videoChannel: VideoChannelModel) {
13   return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid
14 }
15
16 function getAccountActivityPubUrl (accountName: string) {
17   return CONFIG.WEBSERVER.URL + '/account/' + accountName
18 }
19
20 function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) {
21   return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
22 }
23
24 function getVideoViewActivityPubUrl (byAccount: AccountModel, video: VideoModel) {
25   return video.url + '/views/' + byAccount.uuid + '/' + new Date().toISOString()
26 }
27
28 function getVideoLikeActivityPubUrl (byAccount: AccountModel, video: VideoModel) {
29   return byAccount.url + '/likes/' + video.id
30 }
31
32 function getVideoDislikeActivityPubUrl (byAccount: AccountModel, video: VideoModel) {
33   return byAccount.url + '/dislikes/' + video.id
34 }
35
36 function getAccountFollowActivityPubUrl (accountFollow: AccountFollowModel) {
37   const me = accountFollow.AccountFollower
38   const following = accountFollow.AccountFollowing
39
40   return me.url + '/follows/' + following.id
41 }
42
43 function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowModel) {
44   const follower = accountFollow.AccountFollower
45   const me = accountFollow.AccountFollowing
46
47   return follower.url + '/accepts/follows/' + me.id
48 }
49
50 function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountModel) {
51   return originalUrl + '/announces/' + byAccount.id
52 }
53
54 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
55   return originalUrl + '/updates/' + updatedAt
56 }
57
58 function getUndoActivityPubUrl (originalUrl: string) {
59   return originalUrl + '/undo'
60 }
61
62 export {
63   getVideoActivityPubUrl,
64   getVideoChannelActivityPubUrl,
65   getAccountActivityPubUrl,
66   getVideoAbuseActivityPubUrl,
67   getAccountFollowActivityPubUrl,
68   getAccountFollowAcceptActivityPubUrl,
69   getAnnounceActivityPubUrl,
70   getUpdateActivityPubUrl,
71   getUndoActivityPubUrl,
72   getVideoViewActivityPubUrl,
73   getVideoLikeActivityPubUrl,
74   getVideoDislikeActivityPubUrl
75 }