diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 09:43:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 54141398354e6e7b94aa3065a705a1251390111c (patch) | |
tree | 8d30d1b9ea8acbe04f6d404125b04fc0c9897b70 /server/helpers/activitypub.ts | |
parent | eb8b27c93e61a896a08923dc1ca3c87ba8cf4948 (diff) | |
download | PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.gz PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.zst PeerTube-54141398354e6e7b94aa3065a705a1251390111c.zip |
Refractor activity pub lib/helpers
Diffstat (limited to 'server/helpers/activitypub.ts')
-rw-r--r-- | server/helpers/activitypub.ts | 65 |
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 | |||
9 | import { ResultList } from '../../shared/models/result-list.model' | 9 | import { ResultList } from '../../shared/models/result-list.model' |
10 | import { database as db, REMOTE_SCHEME } from '../initializers' | 10 | import { database as db, REMOTE_SCHEME } from '../initializers' |
11 | import { ACTIVITY_PUB, CONFIG, STATIC_PATHS } from '../initializers/constants' | 11 | import { ACTIVITY_PUB, CONFIG, STATIC_PATHS } from '../initializers/constants' |
12 | import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/misc' | 12 | import { videoChannelActivityObjectToDBAttributes } from '../lib/activitypub/process/misc' |
13 | import { sendVideoAnnounce } from '../lib/activitypub/send-request' | 13 | import { sendVideoAnnounce } from '../lib/activitypub/send/send-announce' |
14 | import { sendVideoChannelAnnounce } from '../lib/index' | 14 | import { sendVideoChannelAnnounce } from '../lib/index' |
15 | import { AccountFollowInstance } from '../models/account/account-follow-interface' | ||
15 | import { AccountInstance } from '../models/account/account-interface' | 16 | import { AccountInstance } from '../models/account/account-interface' |
17 | import { VideoAbuseInstance } from '../models/video/video-abuse-interface' | ||
16 | import { VideoChannelInstance } from '../models/video/video-channel-interface' | 18 | import { VideoChannelInstance } from '../models/video/video-channel-interface' |
17 | import { VideoInstance } from '../models/video/video-interface' | 19 | import { VideoInstance } from '../models/video/video-interface' |
18 | import { isRemoteAccountValid } from './custom-validators' | 20 | import { isRemoteAccountValid } from './custom-validators' |
19 | import { isVideoChannelObjectValid } from './custom-validators/activitypub/videos' | ||
20 | import { logger } from './logger' | 21 | import { logger } from './logger' |
21 | import { signObject } from './peertube-crypto' | 22 | import { signObject } from './peertube-crypto' |
22 | import { doRequest, doRequestAndSaveToFile } from './requests' | 23 | import { doRequest, doRequestAndSaveToFile } from './requests' |
23 | import { getServerAccount } from './utils' | 24 | import { getServerAccount } from './utils' |
25 | import { isVideoChannelObjectValid } from './custom-validators/activitypub/video-channels' | ||
24 | 26 | ||
25 | function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { | 27 | function 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 | ||
58 | function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) { | 60 | function 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 | 64 | function getVideoChannelActivityPubUrl (videoChannel: VideoChannelInstance) { |
65 | return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid | ||
66 | } | ||
67 | |||
68 | function getAccountActivityPubUrl (accountName: string) { | ||
69 | return CONFIG.WEBSERVER.URL + '/account/' + accountName | ||
70 | } | ||
71 | |||
72 | function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseInstance) { | ||
73 | return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id | ||
74 | } | ||
75 | |||
76 | function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) { | ||
77 | const me = accountFollow.AccountFollower | ||
78 | const following = accountFollow.AccountFollowing | ||
79 | |||
80 | return me.url + '#follows/' + following.id | ||
81 | } | ||
82 | |||
83 | function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) { | ||
84 | const follower = accountFollow.AccountFollower | ||
85 | const me = accountFollow.AccountFollowing | ||
86 | |||
87 | return follower.url + '#accepts/follows/' + me.id | ||
88 | } | ||
89 | |||
90 | function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountInstance) { | ||
91 | return originalUrl + '#announces/' + byAccount.id | ||
92 | } | ||
93 | |||
94 | function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) { | ||
95 | return originalUrl + '#updates/' + updatedAt | ||
96 | } | ||
63 | 97 | ||
64 | return '' | 98 | function getUndoActivityPubUrl (originalUrl: string) { |
99 | return originalUrl + '/undo' | ||
65 | } | 100 | } |
66 | 101 | ||
67 | async function getOrCreateAccount (accountUrl: string) { | 102 | async 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 | // --------------------------------------------------------------------------- |