diff options
31 files changed, 155 insertions, 136 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index fc27ebbe8..99637dbab 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import cors from 'cors' | 1 | import cors from 'cors' |
2 | import express from 'express' | 2 | import express from 'express' |
3 | import { activityPubCollectionPagination } from '@server/lib/activitypub/collection' | ||
4 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
3 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
4 | import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models' | 6 | import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models' |
5 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' | 7 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
6 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 8 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
7 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | ||
8 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants' | 9 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants' |
9 | import { audiencify, getAudience } from '../../lib/activitypub/audience' | 10 | import { audiencify, getAudience } from '../../lib/activitypub/audience' |
10 | import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send' | 11 | import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send' |
@@ -400,7 +401,7 @@ function videoPlaylistElementController (req: express.Request, res: express.Resp | |||
400 | 401 | ||
401 | // --------------------------------------------------------------------------- | 402 | // --------------------------------------------------------------------------- |
402 | 403 | ||
403 | async function actorFollowing (req: express.Request, actor: MActorId) { | 404 | function actorFollowing (req: express.Request, actor: MActorId) { |
404 | const handler = (start: number, count: number) => { | 405 | const handler = (start: number, count: number) => { |
405 | return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) | 406 | return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) |
406 | } | 407 | } |
@@ -408,7 +409,7 @@ async function actorFollowing (req: express.Request, actor: MActorId) { | |||
408 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) | 409 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
409 | } | 410 | } |
410 | 411 | ||
411 | async function actorFollowers (req: express.Request, actor: MActorId) { | 412 | function actorFollowers (req: express.Request, actor: MActorId) { |
412 | const handler = (start: number, count: number) => { | 413 | const handler = (start: number, count: number) => { |
413 | return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count) | 414 | return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count) |
414 | } | 415 | } |
@@ -416,7 +417,7 @@ async function actorFollowers (req: express.Request, actor: MActorId) { | |||
416 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) | 417 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
417 | } | 418 | } |
418 | 419 | ||
419 | async function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) { | 420 | function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) { |
420 | const handler = (start: number, count: number) => { | 421 | const handler = (start: number, count: number) => { |
421 | return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count) | 422 | return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count) |
422 | } | 423 | } |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index cdef8e969..4e7a3afeb 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { activityPubCollectionPagination } from '@server/lib/activitypub/collection' | ||
3 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
2 | import { MActorLight } from '@server/types/models' | 4 | import { MActorLight } from '@server/types/models' |
3 | import { Activity } from '../../../shared/models/activitypub/activity' | 5 | import { Activity } from '../../../shared/models/activitypub/activity' |
4 | import { VideoPrivacy } from '../../../shared/models/videos' | 6 | import { VideoPrivacy } from '../../../shared/models/videos' |
5 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | ||
6 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
7 | import { buildAudience } from '../../lib/activitypub/audience' | 8 | import { buildAudience } from '../../lib/activitypub/audience' |
8 | import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' | 9 | import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' |
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/helpers/activitypub.ts b/server/lib/activitypub/context.ts index 9d6d8b2fa..71f08da80 100644 --- a/server/helpers/activitypub.ts +++ b/server/lib/activitypub/context.ts | |||
@@ -1,12 +1,4 @@ | |||
1 | import Bluebird from 'bluebird' | 1 | import { ContextType } from '@shared/models' |
2 | import { URL } from 'url' | ||
3 | import validator from 'validator' | ||
4 | import { ContextType } from '@shared/models/activitypub/context' | ||
5 | import { ResultList } from '../../shared/models' | ||
6 | import { ACTIVITY_PUB, REMOTE_SCHEME } from '../initializers/constants' | ||
7 | import { MActor, MVideoWithHost } from '../types/models' | ||
8 | import { pageToStartAndCount } from './core-utils' | ||
9 | import { signJsonLDObject } from './peertube-crypto' | ||
10 | 2 | ||
11 | function getContextData (type: ContextType) { | 3 | function getContextData (type: ContextType) { |
12 | const context: any[] = [ | 4 | const context: any[] = [ |
@@ -139,91 +131,7 @@ function activityPubContextify <T> (data: T, type: ContextType = 'All') { | |||
139 | return Object.assign({}, data, getContextData(type)) | 131 | return Object.assign({}, data, getContextData(type)) |
140 | } | 132 | } |
141 | 133 | ||
142 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> | ||
143 | async function activityPubCollectionPagination ( | ||
144 | baseUrl: string, | ||
145 | handler: ActivityPubCollectionPaginationHandler, | ||
146 | page?: any, | ||
147 | size = ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE | ||
148 | ) { | ||
149 | if (!page || !validator.isInt(page)) { | ||
150 | // We just display the first page URL, we only need the total items | ||
151 | const result = await handler(0, 1) | ||
152 | |||
153 | return { | ||
154 | id: baseUrl, | ||
155 | type: 'OrderedCollectionPage', | ||
156 | totalItems: result.total, | ||
157 | first: result.data.length === 0 | ||
158 | ? undefined | ||
159 | : baseUrl + '?page=1' | ||
160 | } | ||
161 | } | ||
162 | |||
163 | const { start, count } = pageToStartAndCount(page, size) | ||
164 | const result = await handler(start, count) | ||
165 | |||
166 | let next: string | undefined | ||
167 | let prev: string | undefined | ||
168 | |||
169 | // Assert page is a number | ||
170 | page = parseInt(page, 10) | ||
171 | |||
172 | // There are more results | ||
173 | if (result.total > page * size) { | ||
174 | next = baseUrl + '?page=' + (page + 1) | ||
175 | } | ||
176 | |||
177 | if (page > 1) { | ||
178 | prev = baseUrl + '?page=' + (page - 1) | ||
179 | } | ||
180 | |||
181 | return { | ||
182 | id: baseUrl + '?page=' + page, | ||
183 | type: 'OrderedCollectionPage', | ||
184 | prev, | ||
185 | next, | ||
186 | partOf: baseUrl, | ||
187 | orderedItems: result.data, | ||
188 | totalItems: result.total | ||
189 | } | ||
190 | |||
191 | } | ||
192 | |||
193 | function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: ContextType) { | ||
194 | const activity = activityPubContextify(data, contextType) | ||
195 | |||
196 | return signJsonLDObject(byActor, activity) | ||
197 | } | ||
198 | |||
199 | function getAPId (object: string | { id: string }) { | ||
200 | if (typeof object === 'string') return object | ||
201 | |||
202 | return object.id | ||
203 | } | ||
204 | |||
205 | function checkUrlsSameHost (url1: string, url2: string) { | ||
206 | const idHost = new URL(url1).host | ||
207 | const actorHost = new URL(url2).host | ||
208 | |||
209 | return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase() | ||
210 | } | ||
211 | |||
212 | function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) { | ||
213 | if (!scheme) scheme = REMOTE_SCHEME.HTTP | ||
214 | |||
215 | const host = video.VideoChannel.Actor.Server.host | ||
216 | |||
217 | return scheme + '://' + host + path | ||
218 | } | ||
219 | |||
220 | // --------------------------------------------------------------------------- | ||
221 | |||
222 | export { | 134 | export { |
223 | checkUrlsSameHost, | 135 | getContextData, |
224 | getAPId, | 136 | activityPubContextify |
225 | activityPubContextify, | ||
226 | activityPubCollectionPagination, | ||
227 | buildSignedActivity, | ||
228 | buildRemoteVideoBaseUrl | ||
229 | } | 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 | ||
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 @@ | |||
1 | import { map } from 'bluebird' | 1 | import { map } from 'bluebird' |
2 | import { Job } from 'bull' | 2 | import { Job } from 'bull' |
3 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
4 | import { | 3 | import { |
5 | isAnnounceActivityValid, | 4 | isAnnounceActivityValid, |
6 | isDislikeActivityValid, | 5 | isDislikeActivityValid, |
@@ -9,6 +8,7 @@ import { | |||
9 | import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments' | 8 | import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments' |
10 | import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests' | 9 | import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests' |
11 | import { AP_CLEANER } from '@server/initializers/constants' | 10 | import { AP_CLEANER } from '@server/initializers/constants' |
11 | import { checkUrlsSameHost } from '@server/lib/activitypub/url' | ||
12 | import { Redis } from '@server/lib/redis' | 12 | import { Redis } from '@server/lib/redis' |
13 | import { VideoModel } from '@server/models/video/video' | 13 | import { VideoModel } from '@server/models/video/video' |
14 | import { VideoCommentModel } from '@server/models/video/video-comment' | 14 | import { 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 @@ | |||
1 | import { buildDigest } from '@server/helpers/peertube-crypto' | 1 | import { buildDigest } from '@server/helpers/peertube-crypto' |
2 | import { buildSignedActivity } from '@server/lib/activitypub/activity' | ||
2 | import { getServerActor } from '@server/models/application/application' | 3 | import { getServerActor } from '@server/models/application/application' |
3 | import { ContextType } from '@shared/models/activitypub/context' | 4 | import { ContextType } from '@shared/models/activitypub/context' |
4 | import { buildSignedActivity } from '../../../../helpers/activitypub' | ||
5 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants' | 5 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants' |
6 | import { ActorModel } from '../../../../models/actor/actor' | 6 | import { ActorModel } from '../../../../models/actor/actor' |
7 | import { MActor } from '../../../../types/models' | 7 | import { MActor } from '../../../../types/models' |
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 86d3c1d6c..2a2d86a24 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { NextFunction, Request, Response } from 'express' | 1 | import { NextFunction, Request, Response } from 'express' |
2 | import { getAPId } from '@server/helpers/activitypub' | ||
3 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' | 2 | import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' |
3 | import { getAPId } from '@server/lib/activitypub/activity' | ||
4 | import { ActivityDelete, ActivityPubSignature, HttpStatusCode } from '@shared/models' | 4 | import { ActivityDelete, ActivityPubSignature, HttpStatusCode } from '@shared/models' |
5 | import { logger } from '../helpers/logger' | 5 | import { logger } from '../helpers/logger' |
6 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' | 6 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' |
diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts index 08cb2fd24..fad2070ea 100644 --- a/server/models/actor/actor.ts +++ b/server/models/actor/actor.ts | |||
@@ -16,12 +16,12 @@ import { | |||
16 | Table, | 16 | Table, |
17 | UpdatedAt | 17 | UpdatedAt |
18 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
19 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
19 | import { getBiggestActorImage } from '@server/lib/actor-image' | 20 | import { getBiggestActorImage } from '@server/lib/actor-image' |
20 | import { ModelCache } from '@server/models/model-cache' | 21 | import { ModelCache } from '@server/models/model-cache' |
21 | import { getLowercaseExtension } from '@shared/core-utils' | 22 | import { getLowercaseExtension } from '@shared/core-utils' |
22 | import { ActivityIconObject, ActivityPubActorType, ActorImageType } from '@shared/models' | 23 | import { ActivityIconObject, ActivityPubActorType, ActorImageType } from '@shared/models' |
23 | import { AttributesOnly } from '@shared/typescript-utils' | 24 | import { AttributesOnly } from '@shared/typescript-utils' |
24 | import { activityPubContextify } from '../../helpers/activitypub' | ||
25 | import { | 25 | import { |
26 | isActorFollowersCountValid, | 26 | isActorFollowersCountValid, |
27 | isActorFollowingCountValid, | 27 | isActorFollowingCountValid, |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index fae76c6f2..4aaee1ffa 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -19,9 +19,9 @@ import { | |||
19 | UpdatedAt | 19 | UpdatedAt |
20 | } from 'sequelize-typescript' | 20 | } from 'sequelize-typescript' |
21 | import validator from 'validator' | 21 | import validator from 'validator' |
22 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | ||
23 | import { logger } from '@server/helpers/logger' | 22 | import { logger } from '@server/helpers/logger' |
24 | import { extractVideo } from '@server/helpers/video' | 23 | import { extractVideo } from '@server/helpers/video' |
24 | import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url' | ||
25 | import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' | 25 | import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' |
26 | import { getFSTorrentFilePath } from '@server/lib/paths' | 26 | import { getFSTorrentFilePath } from '@server/lib/paths' |
27 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' | 27 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index ae5e237ec..8fb3d5f15 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -17,6 +17,7 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { activityPubCollectionPagination } from '@server/lib/activitypub/collection' | ||
20 | import { MAccountId, MChannelId } from '@server/types/models' | 21 | import { MAccountId, MChannelId } from '@server/types/models' |
21 | import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' | 22 | import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' |
22 | import { buildUUID, uuidToShort } from '@shared/extra-utils' | 23 | import { buildUUID, uuidToShort } from '@shared/extra-utils' |
@@ -26,7 +27,6 @@ import { PlaylistObject } from '../../../shared/models/activitypub/objects/playl | |||
26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 27 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
27 | import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' | 28 | import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' |
28 | import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model' | 29 | import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model' |
29 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | ||
30 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 30 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
31 | import { | 31 | import { |
32 | isVideoPlaylistDescriptionValid, | 32 | isVideoPlaylistDescriptionValid, |
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts index 25e1d9823..e516cf49e 100644 --- a/server/tests/api/activitypub/helpers.ts +++ b/server/tests/api/activitypub/helpers.ts | |||
@@ -5,8 +5,8 @@ import { expect } from 'chai' | |||
5 | import { cloneDeep } from 'lodash' | 5 | import { cloneDeep } from 'lodash' |
6 | import { buildRequestStub } from '@server/tests/shared' | 6 | import { buildRequestStub } from '@server/tests/shared' |
7 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | 7 | import { buildAbsoluteFixturePath } from '@shared/core-utils' |
8 | import { buildSignedActivity } from '../../../helpers/activitypub' | ||
9 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' | 8 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' |
9 | import { buildSignedActivity } from '../../../lib/activitypub/activity' | ||
10 | 10 | ||
11 | describe('Test activity pub helpers', function () { | 11 | describe('Test activity pub helpers', function () { |
12 | describe('When checking the Linked Signature', function () { | 12 | describe('When checking the Linked Signature', function () { |
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index c4cb5ea0d..da9880d7d 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -2,9 +2,10 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { activityPubContextify, buildSignedActivity } from '@server/helpers/activitypub' | ||
6 | import { buildDigest } from '@server/helpers/peertube-crypto' | 5 | import { buildDigest } from '@server/helpers/peertube-crypto' |
7 | import { HTTP_SIGNATURE } from '@server/initializers/constants' | 6 | import { HTTP_SIGNATURE } from '@server/initializers/constants' |
7 | import { buildSignedActivity } from '@server/lib/activitypub/activity' | ||
8 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
8 | import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' | 9 | import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' |
9 | import { makeFollowRequest, makePOSTAPRequest } from '@server/tests/shared' | 10 | import { makeFollowRequest, makePOSTAPRequest } from '@server/tests/shared' |
10 | import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' | 11 | import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' |
diff --git a/server/tests/shared/requests.ts b/server/tests/shared/requests.ts index 7f1acc0e1..d7aedf82f 100644 --- a/server/tests/shared/requests.ts +++ b/server/tests/shared/requests.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { activityPubContextify } from '@server/helpers/activitypub' | ||
2 | import { buildDigest } from '@server/helpers/peertube-crypto' | 1 | import { buildDigest } from '@server/helpers/peertube-crypto' |
3 | import { doRequest } from '@server/helpers/requests' | 2 | import { doRequest } from '@server/helpers/requests' |
4 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants' | 3 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants' |
4 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
5 | 5 | ||
6 | export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { | 6 | export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { |
7 | const options = { | 7 | const options = { |