aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-23 14:24:50 +0100
committerChocobozzz <me@florianbigard.com>2022-03-23 14:24:50 +0100
commit7e98a7df7d04e19ba67163a86c7b876d78d76839 (patch)
tree080c9bf63d2b00b43dca94e3c67cdc2a768308fc /server/lib
parent5302f77d095c2188859ee463128aa59eec20ea88 (diff)
downloadPeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.gz
PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.zst
PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.zip
Remove activitypub helper
Put functions in lib/activitypub instead
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/activity.ts21
-rw-r--r--server/lib/activitypub/actors/get.ts4
-rw-r--r--server/lib/activitypub/actors/shared/url-to-object.ts3
-rw-r--r--server/lib/activitypub/collection.ts62
-rw-r--r--server/lib/activitypub/context.ts137
-rw-r--r--server/lib/activitypub/playlists/create-update.ts4
-rw-r--r--server/lib/activitypub/playlists/get.ts2
-rw-r--r--server/lib/activitypub/playlists/shared/url-to-object.ts2
-rw-r--r--server/lib/activitypub/process/process-announce.ts10
-rw-r--r--server/lib/activitypub/process/process-flag.ts2
-rw-r--r--server/lib/activitypub/process/process-follow.ts2
-rw-r--r--server/lib/activitypub/process/process-like.ts2
-rw-r--r--server/lib/activitypub/process/process.ts3
-rw-r--r--server/lib/activitypub/share.ts4
-rw-r--r--server/lib/activitypub/url.ts31
-rw-r--r--server/lib/activitypub/video-comments.ts2
-rw-r--r--server/lib/activitypub/videos/get.ts2
-rw-r--r--server/lib/activitypub/videos/shared/abstract-builder.ts2
-rw-r--r--server/lib/activitypub/videos/shared/trackers.ts2
-rw-r--r--server/lib/activitypub/videos/shared/url-to-object.ts2
-rw-r--r--server/lib/job-queue/handlers/activitypub-cleaner.ts2
-rw-r--r--server/lib/job-queue/handlers/utils/activitypub-http-utils.ts2
22 files changed, 274 insertions, 29 deletions
diff --git a/server/lib/activitypub/activity.ts b/server/lib/activitypub/activity.ts
new file mode 100644
index 000000000..215b50b69
--- /dev/null
+++ b/server/lib/activitypub/activity.ts
@@ -0,0 +1,21 @@
1import { signJsonLDObject } from '@server/helpers/peertube-crypto'
2import { MActor } from '@server/types/models'
3import { ContextType } from '@shared/models'
4import { activityPubContextify } from './context'
5
6function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: ContextType) {
7 const activity = activityPubContextify(data, contextType)
8
9 return signJsonLDObject(byActor, activity)
10}
11
12function getAPId (object: string | { id: string }) {
13 if (typeof object === 'string') return object
14
15 return object.id
16}
17
18export {
19 buildSignedActivity,
20 getAPId
21}
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index 4200ddb4d..d2b651082 100644
--- a/server/lib/activitypub/actors/get.ts
+++ b/server/lib/activitypub/actors/get.ts
@@ -1,11 +1,11 @@
1
2import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub'
3import { retryTransactionWrapper } from '@server/helpers/database-utils' 1import { retryTransactionWrapper } from '@server/helpers/database-utils'
4import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
5import { JobQueue } from '@server/lib/job-queue' 3import { JobQueue } from '@server/lib/job-queue'
6import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders' 4import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders'
7import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' 5import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models'
8import { ActivityPubActor } from '@shared/models' 6import { ActivityPubActor } from '@shared/models'
7import { getAPId } from '../activity'
8import { checkUrlsSameHost } from '../url'
9import { refreshActorIfNeeded } from './refresh' 9import { refreshActorIfNeeded } from './refresh'
10import { APActorCreator, fetchRemoteActor } from './shared' 10import { APActorCreator, fetchRemoteActor } from './shared'
11 11
diff --git a/server/lib/activitypub/actors/shared/url-to-object.ts b/server/lib/activitypub/actors/shared/url-to-object.ts
index f4f16b044..982d52b79 100644
--- a/server/lib/activitypub/actors/shared/url-to-object.ts
+++ b/server/lib/activitypub/actors/shared/url-to-object.ts
@@ -1,9 +1,8 @@
1
2import { checkUrlsSameHost } from '@server/helpers/activitypub'
3import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor' 1import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor'
4import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
5import { doJSONRequest } from '@server/helpers/requests' 3import { doJSONRequest } from '@server/helpers/requests'
6import { ActivityPubActor, ActivityPubOrderedCollection } from '@shared/models' 4import { ActivityPubActor, ActivityPubOrderedCollection } from '@shared/models'
5import { checkUrlsSameHost } from '../../url'
7 6
8async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode: number, actorObject: ActivityPubActor }> { 7async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode: number, actorObject: ActivityPubActor }> {
9 logger.info('Fetching remote actor %s.', actorUrl) 8 logger.info('Fetching remote actor %s.', actorUrl)
diff --git a/server/lib/activitypub/collection.ts b/server/lib/activitypub/collection.ts
new file mode 100644
index 000000000..43a704aa4
--- /dev/null
+++ b/server/lib/activitypub/collection.ts
@@ -0,0 +1,62 @@
1import Bluebird from 'bluebird'
2import validator from 'validator'
3import { pageToStartAndCount } from '@server/helpers/core-utils'
4import { ACTIVITY_PUB } from '@server/initializers/constants'
5import { ResultList } from '@shared/models'
6
7type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
8
9async function activityPubCollectionPagination (
10 baseUrl: string,
11 handler: ActivityPubCollectionPaginationHandler,
12 page?: any,
13 size = ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE
14) {
15 if (!page || !validator.isInt(page)) {
16 // We just display the first page URL, we only need the total items
17 const result = await handler(0, 1)
18
19 return {
20 id: baseUrl,
21 type: 'OrderedCollectionPage',
22 totalItems: result.total,
23 first: result.data.length === 0
24 ? undefined
25 : baseUrl + '?page=1'
26 }
27 }
28
29 const { start, count } = pageToStartAndCount(page, size)
30 const result = await handler(start, count)
31
32 let next: string | undefined
33 let prev: string | undefined
34
35 // Assert page is a number
36 page = parseInt(page, 10)
37
38 // There are more results
39 if (result.total > page * size) {
40 next = baseUrl + '?page=' + (page + 1)
41 }
42
43 if (page > 1) {
44 prev = baseUrl + '?page=' + (page - 1)
45 }
46
47 return {
48 id: baseUrl + '?page=' + page,
49 type: 'OrderedCollectionPage',
50 prev,
51 next,
52 partOf: baseUrl,
53 orderedItems: result.data,
54 totalItems: result.total
55 }
56}
57
58// ---------------------------------------------------------------------------
59
60export {
61 activityPubCollectionPagination
62}
diff --git a/server/lib/activitypub/context.ts b/server/lib/activitypub/context.ts
new file mode 100644
index 000000000..71f08da80
--- /dev/null
+++ b/server/lib/activitypub/context.ts
@@ -0,0 +1,137 @@
1import { ContextType } from '@shared/models'
2
3function getContextData (type: ContextType) {
4 const context: any[] = [
5 'https://www.w3.org/ns/activitystreams',
6 'https://w3id.org/security/v1',
7 {
8 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
9 }
10 ]
11
12 if (type !== 'View' && type !== 'Announce') {
13 const additional = {
14 pt: 'https://joinpeertube.org/ns#',
15 sc: 'http://schema.org#'
16 }
17
18 if (type === 'CacheFile') {
19 Object.assign(additional, {
20 expires: 'sc:expires',
21 CacheFile: 'pt:CacheFile'
22 })
23 } else {
24 Object.assign(additional, {
25 Hashtag: 'as:Hashtag',
26 uuid: 'sc:identifier',
27 category: 'sc:category',
28 licence: 'sc:license',
29 subtitleLanguage: 'sc:subtitleLanguage',
30 sensitive: 'as:sensitive',
31 language: 'sc:inLanguage',
32
33 // TODO: remove in a few versions, introduced in 4.2
34 icons: 'as:icon',
35
36 isLiveBroadcast: 'sc:isLiveBroadcast',
37 liveSaveReplay: {
38 '@type': 'sc:Boolean',
39 '@id': 'pt:liveSaveReplay'
40 },
41 permanentLive: {
42 '@type': 'sc:Boolean',
43 '@id': 'pt:permanentLive'
44 },
45 latencyMode: {
46 '@type': 'sc:Number',
47 '@id': 'pt:latencyMode'
48 },
49
50 Infohash: 'pt:Infohash',
51 Playlist: 'pt:Playlist',
52 PlaylistElement: 'pt:PlaylistElement',
53
54 originallyPublishedAt: 'sc:datePublished',
55 views: {
56 '@type': 'sc:Number',
57 '@id': 'pt:views'
58 },
59 state: {
60 '@type': 'sc:Number',
61 '@id': 'pt:state'
62 },
63 size: {
64 '@type': 'sc:Number',
65 '@id': 'pt:size'
66 },
67 fps: {
68 '@type': 'sc:Number',
69 '@id': 'pt:fps'
70 },
71 startTimestamp: {
72 '@type': 'sc:Number',
73 '@id': 'pt:startTimestamp'
74 },
75 stopTimestamp: {
76 '@type': 'sc:Number',
77 '@id': 'pt:stopTimestamp'
78 },
79 position: {
80 '@type': 'sc:Number',
81 '@id': 'pt:position'
82 },
83 commentsEnabled: {
84 '@type': 'sc:Boolean',
85 '@id': 'pt:commentsEnabled'
86 },
87 downloadEnabled: {
88 '@type': 'sc:Boolean',
89 '@id': 'pt:downloadEnabled'
90 },
91 waitTranscoding: {
92 '@type': 'sc:Boolean',
93 '@id': 'pt:waitTranscoding'
94 },
95 support: {
96 '@type': 'sc:Text',
97 '@id': 'pt:support'
98 },
99 likes: {
100 '@id': 'as:likes',
101 '@type': '@id'
102 },
103 dislikes: {
104 '@id': 'as:dislikes',
105 '@type': '@id'
106 },
107 playlists: {
108 '@id': 'pt:playlists',
109 '@type': '@id'
110 },
111 shares: {
112 '@id': 'as:shares',
113 '@type': '@id'
114 },
115 comments: {
116 '@id': 'as:comments',
117 '@type': '@id'
118 }
119 })
120 }
121
122 context.push(additional)
123 }
124
125 return {
126 '@context': context
127 }
128}
129
130function activityPubContextify <T> (data: T, type: ContextType = 'All') {
131 return Object.assign({}, data, getContextData(type))
132}
133
134export {
135 getContextData,
136 activityPubContextify
137}
diff --git a/server/lib/activitypub/playlists/create-update.ts b/server/lib/activitypub/playlists/create-update.ts
index ef572c803..c28700be6 100644
--- a/server/lib/activitypub/playlists/create-update.ts
+++ b/server/lib/activitypub/playlists/create-update.ts
@@ -1,5 +1,4 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { getAPId } from '@server/helpers/activitypub'
3import { isArray } from '@server/helpers/custom-validators/misc' 2import { isArray } from '@server/helpers/custom-validators/misc'
4import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
5import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants' 4import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants'
@@ -9,8 +8,9 @@ import { VideoPlaylistModel } from '@server/models/video/video-playlist'
9import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' 8import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
10import { FilteredModelAttributes } from '@server/types' 9import { FilteredModelAttributes } from '@server/types'
11import { MThumbnail, MVideoPlaylist, MVideoPlaylistFull, MVideoPlaylistVideosLength } from '@server/types/models' 10import { MThumbnail, MVideoPlaylist, MVideoPlaylistFull, MVideoPlaylistVideosLength } from '@server/types/models'
12import { AttributesOnly } from '@shared/typescript-utils'
13import { PlaylistObject } from '@shared/models' 11import { PlaylistObject } from '@shared/models'
12import { AttributesOnly } from '@shared/typescript-utils'
13import { getAPId } from '../activity'
14import { getOrCreateAPActor } from '../actors' 14import { getOrCreateAPActor } from '../actors'
15import { crawlCollectionPage } from '../crawl' 15import { crawlCollectionPage } from '../crawl'
16import { getOrCreateAPVideo } from '../videos' 16import { getOrCreateAPVideo } from '../videos'
diff --git a/server/lib/activitypub/playlists/get.ts b/server/lib/activitypub/playlists/get.ts
index be8456b19..bfaf52cc9 100644
--- a/server/lib/activitypub/playlists/get.ts
+++ b/server/lib/activitypub/playlists/get.ts
@@ -1,7 +1,7 @@
1import { getAPId } from '@server/helpers/activitypub'
2import { VideoPlaylistModel } from '@server/models/video/video-playlist' 1import { VideoPlaylistModel } from '@server/models/video/video-playlist'
3import { MVideoPlaylistFullSummary } from '@server/types/models' 2import { MVideoPlaylistFullSummary } from '@server/types/models'
4import { APObject } from '@shared/models' 3import { APObject } from '@shared/models'
4import { getAPId } from '../activity'
5import { createOrUpdateVideoPlaylist } from './create-update' 5import { createOrUpdateVideoPlaylist } from './create-update'
6import { scheduleRefreshIfNeeded } from './refresh' 6import { scheduleRefreshIfNeeded } from './refresh'
7import { fetchRemoteVideoPlaylist } from './shared' 7import { fetchRemoteVideoPlaylist } from './shared'
diff --git a/server/lib/activitypub/playlists/shared/url-to-object.ts b/server/lib/activitypub/playlists/shared/url-to-object.ts
index ec8c01255..f895db587 100644
--- a/server/lib/activitypub/playlists/shared/url-to-object.ts
+++ b/server/lib/activitypub/playlists/shared/url-to-object.ts
@@ -1,9 +1,9 @@
1import { isArray } from 'lodash' 1import { isArray } from 'lodash'
2import { checkUrlsSameHost } from '@server/helpers/activitypub'
3import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist' 2import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist'
4import { logger, loggerTagsFactory } from '@server/helpers/logger' 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
5import { doJSONRequest } from '@server/helpers/requests' 4import { doJSONRequest } from '@server/helpers/requests'
6import { PlaylistElementObject, PlaylistObject } from '@shared/models' 5import { PlaylistElementObject, PlaylistObject } from '@shared/models'
6import { checkUrlsSameHost } from '../../url'
7 7
8async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> { 8async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> {
9 const lTags = loggerTagsFactory('ap', 'video-playlist', playlistUrl) 9 const lTags = loggerTagsFactory('ap', 'video-playlist', playlistUrl)
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 200f8ce11..9cc87ee27 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -1,14 +1,14 @@
1import { getAPId } from '@server/lib/activitypub/activity'
1import { ActivityAnnounce } from '../../../../shared/models/activitypub' 2import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger'
3import { sequelizeTypescript } from '../../../initializers/database' 5import { sequelizeTypescript } from '../../../initializers/database'
4import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
5import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
6import { getOrCreateAPVideo } from '../videos'
7import { Notifier } from '../../notifier'
8import { logger } from '../../../helpers/logger'
9import { APProcessorOptions } from '../../../types/activitypub-processor.model' 7import { APProcessorOptions } from '../../../types/activitypub-processor.model'
10import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' 8import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
11import { getAPId } from '@server/helpers/activitypub' 9import { Notifier } from '../../notifier'
10import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
11import { getOrCreateAPVideo } from '../videos'
12 12
13async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { 13async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
14 const { activity, byActor: actorAnnouncer } = options 14 const { activity, byActor: actorAnnouncer } = options
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts
index a15d07a62..10f58ef27 100644
--- a/server/lib/activitypub/process/process-flag.ts
+++ b/server/lib/activitypub/process/process-flag.ts
@@ -4,10 +4,10 @@ import { VideoModel } from '@server/models/video/video'
4import { VideoCommentModel } from '@server/models/video/video-comment' 4import { VideoCommentModel } from '@server/models/video/video-comment'
5import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' 5import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
6import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '@shared/models' 6import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '@shared/models'
7import { getAPId } from '../../../helpers/activitypub'
8import { retryTransactionWrapper } from '../../../helpers/database-utils' 7import { retryTransactionWrapper } from '../../../helpers/database-utils'
9import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
10import { sequelizeTypescript } from '../../../initializers/database' 9import { sequelizeTypescript } from '../../../initializers/database'
10import { getAPId } from '../../../lib/activitypub/activity'
11import { APProcessorOptions } from '../../../types/activitypub-processor.model' 11import { APProcessorOptions } from '../../../types/activitypub-processor.model'
12import { MAccountDefault, MActorSignature, MCommentOwnerVideo } from '../../../types/models' 12import { MAccountDefault, MActorSignature, MCommentOwnerVideo } from '../../../types/models'
13 13
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index e44590ffc..93df7e191 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -1,10 +1,10 @@
1import { getServerActor } from '@server/models/application/application' 1import { getServerActor } from '@server/models/application/application'
2import { ActivityFollow } from '../../../../shared/models/activitypub' 2import { ActivityFollow } from '../../../../shared/models/activitypub'
3import { getAPId } from '../../../helpers/activitypub'
4import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
5import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
6import { CONFIG } from '../../../initializers/config' 5import { CONFIG } from '../../../initializers/config'
7import { sequelizeTypescript } from '../../../initializers/database' 6import { sequelizeTypescript } from '../../../initializers/database'
7import { getAPId } from '../../../lib/activitypub/activity'
8import { ActorModel } from '../../../models/actor/actor' 8import { ActorModel } from '../../../models/actor/actor'
9import { ActorFollowModel } from '../../../models/actor/actor-follow' 9import { ActorFollowModel } from '../../../models/actor/actor-follow'
10import { APProcessorOptions } from '../../../types/activitypub-processor.model' 10import { APProcessorOptions } from '../../../types/activitypub-processor.model'
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index 93afb5edf..1aee756d8 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,8 +1,8 @@
1import { VideoModel } from '@server/models/video/video' 1import { VideoModel } from '@server/models/video/video'
2import { ActivityLike } from '../../../../shared/models/activitypub' 2import { ActivityLike } from '../../../../shared/models/activitypub'
3import { getAPId } from '../../../helpers/activitypub'
4import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
5import { sequelizeTypescript } from '../../../initializers/database' 4import { sequelizeTypescript } from '../../../initializers/database'
5import { getAPId } from '../../../lib/activitypub/activity'
6import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 6import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
7import { APProcessorOptions } from '../../../types/activitypub-processor.model' 7import { APProcessorOptions } from '../../../types/activitypub-processor.model'
8import { MActorSignature } from '../../../types/models' 8import { MActorSignature } from '../../../types/models'
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts
index 02a23d098..2bc3dce03 100644
--- a/server/lib/activitypub/process/process.ts
+++ b/server/lib/activitypub/process/process.ts
@@ -1,10 +1,11 @@
1import { StatsManager } from '@server/lib/stat-manager' 1import { StatsManager } from '@server/lib/stat-manager'
2import { Activity, ActivityType } from '../../../../shared/models/activitypub' 2import { Activity, ActivityType } from '../../../../shared/models/activitypub'
3import { checkUrlsSameHost, getAPId } from '../../../helpers/activitypub'
4import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
5import { APProcessorOptions } from '../../../types/activitypub-processor.model' 4import { APProcessorOptions } from '../../../types/activitypub-processor.model'
6import { MActorDefault, MActorSignature } from '../../../types/models' 5import { MActorDefault, MActorSignature } from '../../../types/models'
6import { getAPId } from '../activity'
7import { getOrCreateAPActor } from '../actors' 7import { getOrCreateAPActor } from '../actors'
8import { checkUrlsSameHost } from '../url'
8import { processAcceptActivity } from './process-accept' 9import { processAcceptActivity } from './process-accept'
9import { processAnnounceActivity } from './process-announce' 10import { processAnnounceActivity } from './process-announce'
10import { processCreateActivity } from './process-create' 11import { processCreateActivity } from './process-create'
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index b18761174..0fefcbbc5 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -1,15 +1,15 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { Transaction } from 'sequelize' 2import { Transaction } from 'sequelize'
3import { getServerActor } from '@server/models/application/application' 3import { getServerActor } from '@server/models/application/application'
4import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
5import { logger, loggerTagsFactory } from '../../helpers/logger' 4import { logger, loggerTagsFactory } from '../../helpers/logger'
6import { doJSONRequest } from '../../helpers/requests' 5import { doJSONRequest } from '../../helpers/requests'
7import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' 6import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
8import { VideoShareModel } from '../../models/video/video-share' 7import { VideoShareModel } from '../../models/video/video-share'
9import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video' 8import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video'
9import { getAPId } from './activity'
10import { getOrCreateAPActor } from './actors' 10import { getOrCreateAPActor } from './actors'
11import { sendUndoAnnounce, sendVideoAnnounce } from './send' 11import { sendUndoAnnounce, sendVideoAnnounce } from './send'
12import { getLocalVideoAnnounceActivityPubUrl } from './url' 12import { checkUrlsSameHost, getLocalVideoAnnounceActivityPubUrl } from './url'
13 13
14const lTags = loggerTagsFactory('share') 14const lTags = loggerTagsFactory('share')
15 15
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 338398f2b..50be4fac9 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -1,4 +1,4 @@
1import { WEBSERVER } from '../../initializers/constants' 1import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
2import { 2import {
3 MAbuseFull, 3 MAbuseFull,
4 MAbuseId, 4 MAbuseId,
@@ -10,7 +10,8 @@ import {
10 MVideoId, 10 MVideoId,
11 MVideoPlaylistElement, 11 MVideoPlaylistElement,
12 MVideoUrl, 12 MVideoUrl,
13 MVideoUUID 13 MVideoUUID,
14 MVideoWithHost
14} from '../../types/models' 15} from '../../types/models'
15import { MVideoFileVideoUUID } from '../../types/models/video/video-file' 16import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
16import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' 17import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
@@ -121,6 +122,27 @@ function getAbuseTargetUrl (abuse: MAbuseFull) {
121 abuse.FlaggedAccount.Actor.url 122 abuse.FlaggedAccount.Actor.url
122} 123}
123 124
125// ---------------------------------------------------------------------------
126
127function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
128 if (!scheme) scheme = REMOTE_SCHEME.HTTP
129
130 const host = video.VideoChannel.Actor.Server.host
131
132 return scheme + '://' + host + path
133}
134
135// ---------------------------------------------------------------------------
136
137function checkUrlsSameHost (url1: string, url2: string) {
138 const idHost = new URL(url1).host
139 const actorHost = new URL(url2).host
140
141 return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
142}
143
144// ---------------------------------------------------------------------------
145
124export { 146export {
125 getLocalVideoActivityPubUrl, 147 getLocalVideoActivityPubUrl,
126 getLocalVideoPlaylistActivityPubUrl, 148 getLocalVideoPlaylistActivityPubUrl,
@@ -145,5 +167,8 @@ export {
145 getLocalVideoCommentsActivityPubUrl, 167 getLocalVideoCommentsActivityPubUrl,
146 getLocalVideoLikesActivityPubUrl, 168 getLocalVideoLikesActivityPubUrl,
147 getLocalVideoDislikesActivityPubUrl, 169 getLocalVideoDislikesActivityPubUrl,
148 getAbuseTargetUrl 170
171 getAbuseTargetUrl,
172 checkUrlsSameHost,
173 buildRemoteVideoBaseUrl
149} 174}
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts
index 2c7da3e00..911c7cd30 100644
--- a/server/lib/activitypub/video-comments.ts
+++ b/server/lib/activitypub/video-comments.ts
@@ -1,5 +1,4 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { checkUrlsSameHost } from '../../helpers/activitypub'
3import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments' 2import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments'
4import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
5import { doJSONRequest } from '../../helpers/requests' 4import { doJSONRequest } from '../../helpers/requests'
@@ -7,6 +6,7 @@ import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/cons
7import { VideoCommentModel } from '../../models/video/video-comment' 6import { VideoCommentModel } from '../../models/video/video-comment'
8import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video' 7import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video'
9import { getOrCreateAPActor } from './actors' 8import { getOrCreateAPActor } from './actors'
9import { checkUrlsSameHost } from './url'
10import { getOrCreateAPVideo } from './videos' 10import { getOrCreateAPVideo } from './videos'
11 11
12type ResolveThreadParams = { 12type ResolveThreadParams = {
diff --git a/server/lib/activitypub/videos/get.ts b/server/lib/activitypub/videos/get.ts
index b13c6ceeb..d7500c71a 100644
--- a/server/lib/activitypub/videos/get.ts
+++ b/server/lib/activitypub/videos/get.ts
@@ -1,9 +1,9 @@
1import { getAPId } from '@server/helpers/activitypub'
2import { retryTransactionWrapper } from '@server/helpers/database-utils' 1import { retryTransactionWrapper } from '@server/helpers/database-utils'
3import { JobQueue } from '@server/lib/job-queue' 2import { JobQueue } from '@server/lib/job-queue'
4import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders' 3import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders'
5import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' 4import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models'
6import { APObject } from '@shared/models' 5import { APObject } from '@shared/models'
6import { getAPId } from '../activity'
7import { refreshVideoIfNeeded } from './refresh' 7import { refreshVideoIfNeeded } from './refresh'
8import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' 8import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
9 9
diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts
index 788223b48..f299ba4fd 100644
--- a/server/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/lib/activitypub/videos/shared/abstract-builder.ts
@@ -1,5 +1,4 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { checkUrlsSameHost } from '@server/helpers/activitypub'
3import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' 2import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils'
4import { logger, LoggerTagsFn } from '@server/helpers/logger' 3import { logger, LoggerTagsFn } from '@server/helpers/logger'
5import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' 4import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail'
@@ -11,6 +10,7 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin
11import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models' 10import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models'
12import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models' 11import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models'
13import { getOrCreateAPActor } from '../../actors' 12import { getOrCreateAPActor } from '../../actors'
13import { checkUrlsSameHost } from '../../url'
14import { 14import {
15 getCaptionAttributesFromObject, 15 getCaptionAttributesFromObject,
16 getFileAttributesFromUrl, 16 getFileAttributesFromUrl,
diff --git a/server/lib/activitypub/videos/shared/trackers.ts b/server/lib/activitypub/videos/shared/trackers.ts
index 1c5fc4f84..2418f45c2 100644
--- a/server/lib/activitypub/videos/shared/trackers.ts
+++ b/server/lib/activitypub/videos/shared/trackers.ts
@@ -1,11 +1,11 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
3import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos' 2import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos'
4import { isArray } from '@server/helpers/custom-validators/misc' 3import { isArray } from '@server/helpers/custom-validators/misc'
5import { REMOTE_SCHEME } from '@server/initializers/constants' 4import { REMOTE_SCHEME } from '@server/initializers/constants'
6import { TrackerModel } from '@server/models/server/tracker' 5import { TrackerModel } from '@server/models/server/tracker'
7import { MVideo, MVideoWithHost } from '@server/types/models' 6import { MVideo, MVideoWithHost } from '@server/types/models'
8import { ActivityTrackerUrlObject, VideoObject } from '@shared/models' 7import { ActivityTrackerUrlObject, VideoObject } from '@shared/models'
8import { buildRemoteVideoBaseUrl } from '../../url'
9 9
10function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { 10function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
11 let wsFound = false 11 let wsFound = false
diff --git a/server/lib/activitypub/videos/shared/url-to-object.ts b/server/lib/activitypub/videos/shared/url-to-object.ts
index dba3e9480..5b7007530 100644
--- a/server/lib/activitypub/videos/shared/url-to-object.ts
+++ b/server/lib/activitypub/videos/shared/url-to-object.ts
@@ -1,8 +1,8 @@
1import { checkUrlsSameHost } from '@server/helpers/activitypub'
2import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' 1import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
3import { logger, loggerTagsFactory } from '@server/helpers/logger' 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
4import { doJSONRequest } from '@server/helpers/requests' 3import { doJSONRequest } from '@server/helpers/requests'
5import { VideoObject } from '@shared/models' 4import { VideoObject } from '@shared/models'
5import { checkUrlsSameHost } from '../../url'
6 6
7const lTags = loggerTagsFactory('ap', 'video') 7const lTags = loggerTagsFactory('ap', 'video')
8 8
diff --git a/server/lib/job-queue/handlers/activitypub-cleaner.ts b/server/lib/job-queue/handlers/activitypub-cleaner.ts
index 07dd908cd..123aeac03 100644
--- a/server/lib/job-queue/handlers/activitypub-cleaner.ts
+++ b/server/lib/job-queue/handlers/activitypub-cleaner.ts
@@ -1,6 +1,5 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { Job } from 'bull' 2import { Job } from 'bull'
3import { checkUrlsSameHost } from '@server/helpers/activitypub'
4import { 3import {
5 isAnnounceActivityValid, 4 isAnnounceActivityValid,
6 isDislikeActivityValid, 5 isDislikeActivityValid,
@@ -9,6 +8,7 @@ import {
9import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments' 8import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments'
10import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests' 9import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests'
11import { AP_CLEANER } from '@server/initializers/constants' 10import { AP_CLEANER } from '@server/initializers/constants'
11import { checkUrlsSameHost } from '@server/lib/activitypub/url'
12import { Redis } from '@server/lib/redis' 12import { Redis } from '@server/lib/redis'
13import { VideoModel } from '@server/models/video/video' 13import { VideoModel } from '@server/models/video/video'
14import { VideoCommentModel } from '@server/models/video/video-comment' 14import { VideoCommentModel } from '@server/models/video/video-comment'
diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
index 37e7c1fad..2a03325b7 100644
--- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
+++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
@@ -1,7 +1,7 @@
1import { buildDigest } from '@server/helpers/peertube-crypto' 1import { buildDigest } from '@server/helpers/peertube-crypto'
2import { buildSignedActivity } from '@server/lib/activitypub/activity'
2import { getServerActor } from '@server/models/application/application' 3import { getServerActor } from '@server/models/application/application'
3import { ContextType } from '@shared/models/activitypub/context' 4import { ContextType } from '@shared/models/activitypub/context'
4import { buildSignedActivity } from '../../../../helpers/activitypub'
5import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants' 5import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants'
6import { ActorModel } from '../../../../models/actor/actor' 6import { ActorModel } from '../../../../models/actor/actor'
7import { MActor } from '../../../../types/models' 7import { MActor } from '../../../../types/models'