diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-23 14:24:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-23 14:24:50 +0100 |
commit | 7e98a7df7d04e19ba67163a86c7b876d78d76839 (patch) | |
tree | 080c9bf63d2b00b43dca94e3c67cdc2a768308fc /server/lib/activitypub | |
parent | 5302f77d095c2188859ee463128aa59eec20ea88 (diff) | |
download | PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.gz PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.zst PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.zip |
Remove activitypub helper
Put functions in lib/activitypub instead
Diffstat (limited to 'server/lib/activitypub')
20 files changed, 272 insertions, 27 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 @@ | |||
1 | import { signJsonLDObject } from '@server/helpers/peertube-crypto' | ||
2 | import { MActor } from '@server/types/models' | ||
3 | import { ContextType } from '@shared/models' | ||
4 | import { activityPubContextify } from './context' | ||
5 | |||
6 | function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: ContextType) { | ||
7 | const activity = activityPubContextify(data, contextType) | ||
8 | |||
9 | return signJsonLDObject(byActor, activity) | ||
10 | } | ||
11 | |||
12 | function getAPId (object: string | { id: string }) { | ||
13 | if (typeof object === 'string') return object | ||
14 | |||
15 | return object.id | ||
16 | } | ||
17 | |||
18 | export { | ||
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 | |||
2 | import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' | ||
3 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | 1 | import { retryTransactionWrapper } from '@server/helpers/database-utils' |
4 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
5 | import { JobQueue } from '@server/lib/job-queue' | 3 | import { JobQueue } from '@server/lib/job-queue' |
6 | import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders' | 4 | import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders' |
7 | import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' | 5 | import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' |
8 | import { ActivityPubActor } from '@shared/models' | 6 | import { ActivityPubActor } from '@shared/models' |
7 | import { getAPId } from '../activity' | ||
8 | import { checkUrlsSameHost } from '../url' | ||
9 | import { refreshActorIfNeeded } from './refresh' | 9 | import { refreshActorIfNeeded } from './refresh' |
10 | import { APActorCreator, fetchRemoteActor } from './shared' | 10 | import { 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 | |||
2 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
3 | import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor' | 1 | import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor' |
4 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
5 | import { doJSONRequest } from '@server/helpers/requests' | 3 | import { doJSONRequest } from '@server/helpers/requests' |
6 | import { ActivityPubActor, ActivityPubOrderedCollection } from '@shared/models' | 4 | import { ActivityPubActor, ActivityPubOrderedCollection } from '@shared/models' |
5 | import { checkUrlsSameHost } from '../../url' | ||
7 | 6 | ||
8 | async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode: number, actorObject: ActivityPubActor }> { | 7 | async 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 @@ | |||
1 | import Bluebird from 'bluebird' | ||
2 | import validator from 'validator' | ||
3 | import { pageToStartAndCount } from '@server/helpers/core-utils' | ||
4 | import { ACTIVITY_PUB } from '@server/initializers/constants' | ||
5 | import { ResultList } from '@shared/models' | ||
6 | |||
7 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> | ||
8 | |||
9 | async 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 | |||
60 | export { | ||
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 @@ | |||
1 | import { ContextType } from '@shared/models' | ||
2 | |||
3 | function 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 | |||
130 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { | ||
131 | return Object.assign({}, data, getContextData(type)) | ||
132 | } | ||
133 | |||
134 | export { | ||
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 @@ | |||
1 | import { map } from 'bluebird' | 1 | import { map } from 'bluebird' |
2 | import { getAPId } from '@server/helpers/activitypub' | ||
3 | import { isArray } from '@server/helpers/custom-validators/misc' | 2 | import { isArray } from '@server/helpers/custom-validators/misc' |
4 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
5 | import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants' | 4 | import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants' |
@@ -9,8 +8,9 @@ import { VideoPlaylistModel } from '@server/models/video/video-playlist' | |||
9 | import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' | 8 | import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' |
10 | import { FilteredModelAttributes } from '@server/types' | 9 | import { FilteredModelAttributes } from '@server/types' |
11 | import { MThumbnail, MVideoPlaylist, MVideoPlaylistFull, MVideoPlaylistVideosLength } from '@server/types/models' | 10 | import { MThumbnail, MVideoPlaylist, MVideoPlaylistFull, MVideoPlaylistVideosLength } from '@server/types/models' |
12 | import { AttributesOnly } from '@shared/typescript-utils' | ||
13 | import { PlaylistObject } from '@shared/models' | 11 | import { PlaylistObject } from '@shared/models' |
12 | import { AttributesOnly } from '@shared/typescript-utils' | ||
13 | import { getAPId } from '../activity' | ||
14 | import { getOrCreateAPActor } from '../actors' | 14 | import { getOrCreateAPActor } from '../actors' |
15 | import { crawlCollectionPage } from '../crawl' | 15 | import { crawlCollectionPage } from '../crawl' |
16 | import { getOrCreateAPVideo } from '../videos' | 16 | import { 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 @@ | |||
1 | import { getAPId } from '@server/helpers/activitypub' | ||
2 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 1 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
3 | import { MVideoPlaylistFullSummary } from '@server/types/models' | 2 | import { MVideoPlaylistFullSummary } from '@server/types/models' |
4 | import { APObject } from '@shared/models' | 3 | import { APObject } from '@shared/models' |
4 | import { getAPId } from '../activity' | ||
5 | import { createOrUpdateVideoPlaylist } from './create-update' | 5 | import { createOrUpdateVideoPlaylist } from './create-update' |
6 | import { scheduleRefreshIfNeeded } from './refresh' | 6 | import { scheduleRefreshIfNeeded } from './refresh' |
7 | import { fetchRemoteVideoPlaylist } from './shared' | 7 | import { 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 @@ | |||
1 | import { isArray } from 'lodash' | 1 | import { isArray } from 'lodash' |
2 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
3 | import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist' | 2 | import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist' |
4 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
5 | import { doJSONRequest } from '@server/helpers/requests' | 4 | import { doJSONRequest } from '@server/helpers/requests' |
6 | import { PlaylistElementObject, PlaylistObject } from '@shared/models' | 5 | import { PlaylistElementObject, PlaylistObject } from '@shared/models' |
6 | import { checkUrlsSameHost } from '../../url' | ||
7 | 7 | ||
8 | async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> { | 8 | async 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 @@ | |||
1 | import { getAPId } from '@server/lib/activitypub/activity' | ||
1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' | 2 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers/database' | 5 | import { sequelizeTypescript } from '../../../initializers/database' |
4 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
5 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' | ||
6 | import { getOrCreateAPVideo } from '../videos' | ||
7 | import { Notifier } from '../../notifier' | ||
8 | import { logger } from '../../../helpers/logger' | ||
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
10 | import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' | 8 | import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' |
11 | import { getAPId } from '@server/helpers/activitypub' | 9 | import { Notifier } from '../../notifier' |
10 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' | ||
11 | import { getOrCreateAPVideo } from '../videos' | ||
12 | 12 | ||
13 | async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { | 13 | async 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' | |||
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | 4 | import { VideoCommentModel } from '@server/models/video/video-comment' |
5 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' | 5 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
6 | import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '@shared/models' | 6 | import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '@shared/models' |
7 | import { getAPId } from '../../../helpers/activitypub' | ||
8 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 7 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
9 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
10 | import { sequelizeTypescript } from '../../../initializers/database' | 9 | import { sequelizeTypescript } from '../../../initializers/database' |
10 | import { getAPId } from '../../../lib/activitypub/activity' | ||
11 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 11 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
12 | import { MAccountDefault, MActorSignature, MCommentOwnerVideo } from '../../../types/models' | 12 | import { 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 @@ | |||
1 | import { getServerActor } from '@server/models/application/application' | 1 | import { getServerActor } from '@server/models/application/application' |
2 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 2 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
3 | import { getAPId } from '../../../helpers/activitypub' | ||
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
5 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
6 | import { CONFIG } from '../../../initializers/config' | 5 | import { CONFIG } from '../../../initializers/config' |
7 | import { sequelizeTypescript } from '../../../initializers/database' | 6 | import { sequelizeTypescript } from '../../../initializers/database' |
7 | import { getAPId } from '../../../lib/activitypub/activity' | ||
8 | import { ActorModel } from '../../../models/actor/actor' | 8 | import { ActorModel } from '../../../models/actor/actor' |
9 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 9 | import { ActorFollowModel } from '../../../models/actor/actor-follow' |
10 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 10 | import { 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 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | 1 | import { VideoModel } from '@server/models/video/video' |
2 | import { ActivityLike } from '../../../../shared/models/activitypub' | 2 | import { ActivityLike } from '../../../../shared/models/activitypub' |
3 | import { getAPId } from '../../../helpers/activitypub' | ||
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
5 | import { sequelizeTypescript } from '../../../initializers/database' | 4 | import { sequelizeTypescript } from '../../../initializers/database' |
5 | import { getAPId } from '../../../lib/activitypub/activity' | ||
6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 7 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
8 | import { MActorSignature } from '../../../types/models' | 8 | import { 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 @@ | |||
1 | import { StatsManager } from '@server/lib/stat-manager' | 1 | import { StatsManager } from '@server/lib/stat-manager' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
3 | import { checkUrlsSameHost, getAPId } from '../../../helpers/activitypub' | ||
4 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
5 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 4 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
6 | import { MActorDefault, MActorSignature } from '../../../types/models' | 5 | import { MActorDefault, MActorSignature } from '../../../types/models' |
6 | import { getAPId } from '../activity' | ||
7 | import { getOrCreateAPActor } from '../actors' | 7 | import { getOrCreateAPActor } from '../actors' |
8 | import { checkUrlsSameHost } from '../url' | ||
8 | import { processAcceptActivity } from './process-accept' | 9 | import { processAcceptActivity } from './process-accept' |
9 | import { processAnnounceActivity } from './process-announce' | 10 | import { processAnnounceActivity } from './process-announce' |
10 | import { processCreateActivity } from './process-create' | 11 | import { 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 @@ | |||
1 | import { map } from 'bluebird' | 1 | import { map } from 'bluebird' |
2 | import { Transaction } from 'sequelize' | 2 | import { Transaction } from 'sequelize' |
3 | import { getServerActor } from '@server/models/application/application' | 3 | import { getServerActor } from '@server/models/application/application' |
4 | import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' | ||
5 | import { logger, loggerTagsFactory } from '../../helpers/logger' | 4 | import { logger, loggerTagsFactory } from '../../helpers/logger' |
6 | import { doJSONRequest } from '../../helpers/requests' | 5 | import { doJSONRequest } from '../../helpers/requests' |
7 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' | 6 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' |
8 | import { VideoShareModel } from '../../models/video/video-share' | 7 | import { VideoShareModel } from '../../models/video/video-share' |
9 | import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video' | 8 | import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video' |
9 | import { getAPId } from './activity' | ||
10 | import { getOrCreateAPActor } from './actors' | 10 | import { getOrCreateAPActor } from './actors' |
11 | import { sendUndoAnnounce, sendVideoAnnounce } from './send' | 11 | import { sendUndoAnnounce, sendVideoAnnounce } from './send' |
12 | import { getLocalVideoAnnounceActivityPubUrl } from './url' | 12 | import { checkUrlsSameHost, getLocalVideoAnnounceActivityPubUrl } from './url' |
13 | 13 | ||
14 | const lTags = loggerTagsFactory('share') | 14 | const 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 @@ | |||
1 | import { WEBSERVER } from '../../initializers/constants' | 1 | import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants' |
2 | import { | 2 | import { |
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' |
15 | import { MVideoFileVideoUUID } from '../../types/models/video/video-file' | 16 | import { MVideoFileVideoUUID } from '../../types/models/video/video-file' |
16 | import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' | 17 | import { 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 | |||
127 | function 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 | |||
137 | function 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 | |||
124 | export { | 146 | export { |
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 @@ | |||
1 | import { map } from 'bluebird' | 1 | import { map } from 'bluebird' |
2 | import { checkUrlsSameHost } from '../../helpers/activitypub' | ||
3 | import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments' | 2 | import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments' |
4 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
5 | import { doJSONRequest } from '../../helpers/requests' | 4 | import { doJSONRequest } from '../../helpers/requests' |
@@ -7,6 +6,7 @@ import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/cons | |||
7 | import { VideoCommentModel } from '../../models/video/video-comment' | 6 | import { VideoCommentModel } from '../../models/video/video-comment' |
8 | import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video' | 7 | import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video' |
9 | import { getOrCreateAPActor } from './actors' | 8 | import { getOrCreateAPActor } from './actors' |
9 | import { checkUrlsSameHost } from './url' | ||
10 | import { getOrCreateAPVideo } from './videos' | 10 | import { getOrCreateAPVideo } from './videos' |
11 | 11 | ||
12 | type ResolveThreadParams = { | 12 | type 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 @@ | |||
1 | import { getAPId } from '@server/helpers/activitypub' | ||
2 | import { retryTransactionWrapper } from '@server/helpers/database-utils' | 1 | import { retryTransactionWrapper } from '@server/helpers/database-utils' |
3 | import { JobQueue } from '@server/lib/job-queue' | 2 | import { JobQueue } from '@server/lib/job-queue' |
4 | import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders' | 3 | import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders' |
5 | import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' | 4 | import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' |
6 | import { APObject } from '@shared/models' | 5 | import { APObject } from '@shared/models' |
6 | import { getAPId } from '../activity' | ||
7 | import { refreshVideoIfNeeded } from './refresh' | 7 | import { refreshVideoIfNeeded } from './refresh' |
8 | import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' | 8 | import { 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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
3 | import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' | 2 | import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' |
4 | import { logger, LoggerTagsFn } from '@server/helpers/logger' | 3 | import { logger, LoggerTagsFn } from '@server/helpers/logger' |
5 | import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' | 4 | import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' |
@@ -11,6 +10,7 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin | |||
11 | import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models' | 10 | import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models' |
12 | import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models' | 11 | import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models' |
13 | import { getOrCreateAPActor } from '../../actors' | 12 | import { getOrCreateAPActor } from '../../actors' |
13 | import { checkUrlsSameHost } from '../../url' | ||
14 | import { | 14 | import { |
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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | ||
3 | import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos' | 2 | import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos' |
4 | import { isArray } from '@server/helpers/custom-validators/misc' | 3 | import { isArray } from '@server/helpers/custom-validators/misc' |
5 | import { REMOTE_SCHEME } from '@server/initializers/constants' | 4 | import { REMOTE_SCHEME } from '@server/initializers/constants' |
6 | import { TrackerModel } from '@server/models/server/tracker' | 5 | import { TrackerModel } from '@server/models/server/tracker' |
7 | import { MVideo, MVideoWithHost } from '@server/types/models' | 6 | import { MVideo, MVideoWithHost } from '@server/types/models' |
8 | import { ActivityTrackerUrlObject, VideoObject } from '@shared/models' | 7 | import { ActivityTrackerUrlObject, VideoObject } from '@shared/models' |
8 | import { buildRemoteVideoBaseUrl } from '../../url' | ||
9 | 9 | ||
10 | function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { | 10 | function 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 @@ | |||
1 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
2 | import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' | 1 | import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' |
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
4 | import { doJSONRequest } from '@server/helpers/requests' | 3 | import { doJSONRequest } from '@server/helpers/requests' |
5 | import { VideoObject } from '@shared/models' | 4 | import { VideoObject } from '@shared/models' |
5 | import { checkUrlsSameHost } from '../../url' | ||
6 | 6 | ||
7 | const lTags = loggerTagsFactory('ap', 'video') | 7 | const lTags = loggerTagsFactory('ap', 'video') |
8 | 8 | ||