aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/activitypub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/activitypub.ts')
-rw-r--r--server/helpers/activitypub.ts65
1 files changed, 54 insertions, 11 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index aff58515a..9622a1801 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -9,18 +9,20 @@ import { VideoChannelObject } from '../../shared/models/activitypub/objects/vide
9import { ResultList } from '../../shared/models/result-list.model' 9import { ResultList } from '../../shared/models/result-list.model'
10import { database as db, REMOTE_SCHEME } from '../initializers' 10import { database as db, REMOTE_SCHEME } from '../initializers'
11import { ACTIVITY_PUB, CONFIG, STATIC_PATHS } from '../initializers/constants' 11import { ACTIVITY_PUB, CONFIG, STATIC_PATHS } from '../initializers/constants'
12import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/misc' 12import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/process/misc'
13import { sendVideoAnnounce } from '../lib/activitypub/send-request' 13import { sendVideoAnnounce } from '../lib/activitypub/send/send-announce'
14import { sendVideoChannelAnnounce } from '../lib/index' 14import { sendVideoChannelAnnounce } from '../lib/index'
15import { AccountFollowInstance } from '../models/account/account-follow-interface'
15import { AccountInstance } from '../models/account/account-interface' 16import { AccountInstance } from '../models/account/account-interface'
17import { VideoAbuseInstance } from '../models/video/video-abuse-interface'
16import { VideoChannelInstance } from '../models/video/video-channel-interface' 18import { VideoChannelInstance } from '../models/video/video-channel-interface'
17import { VideoInstance } from '../models/video/video-interface' 19import { VideoInstance } from '../models/video/video-interface'
18import { isRemoteAccountValid } from './custom-validators' 20import { isRemoteAccountValid } from './custom-validators'
19import { isVideoChannelObjectValid } from './custom-validators/activitypub/videos'
20import { logger } from './logger' 21import { logger } from './logger'
21import { signObject } from './peertube-crypto' 22import { signObject } from './peertube-crypto'
22import { doRequest, doRequestAndSaveToFile } from './requests' 23import { doRequest, doRequestAndSaveToFile } from './requests'
23import { getServerAccount } from './utils' 24import { getServerAccount } from './utils'
25import { isVideoChannelObjectValid } from './custom-validators/activitypub/video-channels'
24 26
25function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { 27function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) {
26 const thumbnailName = video.getThumbnailName() 28 const thumbnailName = video.getThumbnailName()
@@ -55,13 +57,46 @@ async function shareVideoByServer (video: VideoInstance, t: Sequelize.Transactio
55 return sendVideoAnnounce(serverAccount, video, t) 57 return sendVideoAnnounce(serverAccount, video, t)
56} 58}
57 59
58function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) { 60function getVideoActivityPubUrl (video: VideoInstance) {
59 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + id 61 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
60 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + id 62}
61 else if (type === 'account') return CONFIG.WEBSERVER.URL + '/account/' + id 63
62 else if (type === 'videoAbuse') return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + id 64function getVideoChannelActivityPubUrl (videoChannel: VideoChannelInstance) {
65 return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid
66}
67
68function getAccountActivityPubUrl (accountName: string) {
69 return CONFIG.WEBSERVER.URL + '/account/' + accountName
70}
71
72function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseInstance) {
73 return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
74}
75
76function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) {
77 const me = accountFollow.AccountFollower
78 const following = accountFollow.AccountFollowing
79
80 return me.url + '#follows/' + following.id
81}
82
83function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) {
84 const follower = accountFollow.AccountFollower
85 const me = accountFollow.AccountFollowing
86
87 return follower.url + '#accepts/follows/' + me.id
88}
89
90function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountInstance) {
91 return originalUrl + '#announces/' + byAccount.id
92}
93
94function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
95 return originalUrl + '#updates/' + updatedAt
96}
63 97
64 return '' 98function getUndoActivityPubUrl (originalUrl: string) {
99 return originalUrl + '/undo'
65} 100}
66 101
67async function getOrCreateAccount (accountUrl: string) { 102async function getOrCreateAccount (accountUrl: string) {
@@ -257,7 +292,6 @@ export {
257 fetchRemoteAccountAndCreateServer, 292 fetchRemoteAccountAndCreateServer,
258 activityPubContextify, 293 activityPubContextify,
259 activityPubCollectionPagination, 294 activityPubCollectionPagination,
260 getActivityPubUrl,
261 generateThumbnailFromUrl, 295 generateThumbnailFromUrl,
262 getOrCreateAccount, 296 getOrCreateAccount,
263 fetchRemoteVideoPreview, 297 fetchRemoteVideoPreview,
@@ -265,7 +299,16 @@ export {
265 shareVideoChannelByServer, 299 shareVideoChannelByServer,
266 shareVideoByServer, 300 shareVideoByServer,
267 getOrCreateVideoChannel, 301 getOrCreateVideoChannel,
268 buildSignedActivity 302 buildSignedActivity,
303 getVideoActivityPubUrl,
304 getVideoChannelActivityPubUrl,
305 getAccountActivityPubUrl,
306 getVideoAbuseActivityPubUrl,
307 getAccountFollowActivityPubUrl,
308 getAccountFollowAcceptActivityPubUrl,
309 getAnnounceActivityPubUrl,
310 getUpdateActivityPubUrl,
311 getUndoActivityPubUrl
269} 312}
270 313
271// --------------------------------------------------------------------------- 314// ---------------------------------------------------------------------------