]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Remove activitypub helper
authorChocobozzz <me@florianbigard.com>
Wed, 23 Mar 2022 13:24:50 +0000 (14:24 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 23 Mar 2022 13:24:50 +0000 (14:24 +0100)
Put functions in lib/activitypub instead

31 files changed:
server/controllers/activitypub/client.ts
server/controllers/activitypub/outbox.ts
server/lib/activitypub/activity.ts [new file with mode: 0644]
server/lib/activitypub/actors/get.ts
server/lib/activitypub/actors/shared/url-to-object.ts
server/lib/activitypub/collection.ts [new file with mode: 0644]
server/lib/activitypub/context.ts [moved from server/helpers/activitypub.ts with 54% similarity]
server/lib/activitypub/playlists/create-update.ts
server/lib/activitypub/playlists/get.ts
server/lib/activitypub/playlists/shared/url-to-object.ts
server/lib/activitypub/process/process-announce.ts
server/lib/activitypub/process/process-flag.ts
server/lib/activitypub/process/process-follow.ts
server/lib/activitypub/process/process-like.ts
server/lib/activitypub/process/process.ts
server/lib/activitypub/share.ts
server/lib/activitypub/url.ts
server/lib/activitypub/video-comments.ts
server/lib/activitypub/videos/get.ts
server/lib/activitypub/videos/shared/abstract-builder.ts
server/lib/activitypub/videos/shared/trackers.ts
server/lib/activitypub/videos/shared/url-to-object.ts
server/lib/job-queue/handlers/activitypub-cleaner.ts
server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
server/middlewares/activitypub.ts
server/models/actor/actor.ts
server/models/video/video-file.ts
server/models/video/video-playlist.ts
server/tests/api/activitypub/helpers.ts
server/tests/api/activitypub/security.ts
server/tests/shared/requests.ts

index fc27ebbe8eb03f52295993f83586e7ad93ef4c8f..99637dbab1eccf73fcc0edb2a584926e0fcc76fd 100644 (file)
@@ -1,10 +1,11 @@
 import cors from 'cors'
 import express from 'express'
+import { activityPubCollectionPagination } from '@server/lib/activitypub/collection'
+import { activityPubContextify } from '@server/lib/activitypub/context'
 import { getServerActor } from '@server/models/application/application'
 import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models'
 import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
 import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants'
 import { audiencify, getAudience } from '../../lib/activitypub/audience'
 import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send'
@@ -400,7 +401,7 @@ function videoPlaylistElementController (req: express.Request, res: express.Resp
 
 // ---------------------------------------------------------------------------
 
-async function actorFollowing (req: express.Request, actor: MActorId) {
+function actorFollowing (req: express.Request, actor: MActorId) {
   const handler = (start: number, count: number) => {
     return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
   }
@@ -408,7 +409,7 @@ async function actorFollowing (req: express.Request, actor: MActorId) {
   return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
 }
 
-async function actorFollowers (req: express.Request, actor: MActorId) {
+function actorFollowers (req: express.Request, actor: MActorId) {
   const handler = (start: number, count: number) => {
     return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count)
   }
@@ -416,7 +417,7 @@ async function actorFollowers (req: express.Request, actor: MActorId) {
   return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
 }
 
-async function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) {
+function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) {
   const handler = (start: number, count: number) => {
     return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count)
   }
index cdef8e9699b495825b5e80cbac60f2272abb939f..4e7a3afeb746e4984ad8a81b11ca7845eaec13ec 100644 (file)
@@ -1,8 +1,9 @@
 import express from 'express'
+import { activityPubCollectionPagination } from '@server/lib/activitypub/collection'
+import { activityPubContextify } from '@server/lib/activitypub/context'
 import { MActorLight } from '@server/types/models'
 import { Activity } from '../../../shared/models/activitypub/activity'
 import { VideoPrivacy } from '../../../shared/models/videos'
-import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
 import { logger } from '../../helpers/logger'
 import { buildAudience } from '../../lib/activitypub/audience'
 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 (file)
index 0000000..215b50b
--- /dev/null
@@ -0,0 +1,21 @@
+import { signJsonLDObject } from '@server/helpers/peertube-crypto'
+import { MActor } from '@server/types/models'
+import { ContextType } from '@shared/models'
+import { activityPubContextify } from './context'
+
+function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: ContextType) {
+  const activity = activityPubContextify(data, contextType)
+
+  return signJsonLDObject(byActor, activity)
+}
+
+function getAPId (object: string | { id: string }) {
+  if (typeof object === 'string') return object
+
+  return object.id
+}
+
+export {
+  buildSignedActivity,
+  getAPId
+}
index 4200ddb4df4e6e49b8c0114ea8ee04c3ba0e5068..d2b651082478f19f7817c3e27422294596fead17 100644 (file)
@@ -1,11 +1,11 @@
-
-import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub'
 import { retryTransactionWrapper } from '@server/helpers/database-utils'
 import { logger } from '@server/helpers/logger'
 import { JobQueue } from '@server/lib/job-queue'
 import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders'
 import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models'
 import { ActivityPubActor } from '@shared/models'
+import { getAPId } from '../activity'
+import { checkUrlsSameHost } from '../url'
 import { refreshActorIfNeeded } from './refresh'
 import { APActorCreator, fetchRemoteActor } from './shared'
 
index f4f16b04407655eb6833aa717130109977d3cbcd..982d52b79a60069f8c9b7d37cbbf7781cd33d522 100644 (file)
@@ -1,9 +1,8 @@
-
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
 import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor'
 import { logger } from '@server/helpers/logger'
 import { doJSONRequest } from '@server/helpers/requests'
 import { ActivityPubActor, ActivityPubOrderedCollection } from '@shared/models'
+import { checkUrlsSameHost } from '../../url'
 
 async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode: number, actorObject: ActivityPubActor }> {
   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 (file)
index 0000000..43a704a
--- /dev/null
@@ -0,0 +1,62 @@
+import Bluebird from 'bluebird'
+import validator from 'validator'
+import { pageToStartAndCount } from '@server/helpers/core-utils'
+import { ACTIVITY_PUB } from '@server/initializers/constants'
+import { ResultList } from '@shared/models'
+
+type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
+
+async function activityPubCollectionPagination (
+  baseUrl: string,
+  handler: ActivityPubCollectionPaginationHandler,
+  page?: any,
+  size = ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE
+) {
+  if (!page || !validator.isInt(page)) {
+    // We just display the first page URL, we only need the total items
+    const result = await handler(0, 1)
+
+    return {
+      id: baseUrl,
+      type: 'OrderedCollectionPage',
+      totalItems: result.total,
+      first: result.data.length === 0
+        ? undefined
+        : baseUrl + '?page=1'
+    }
+  }
+
+  const { start, count } = pageToStartAndCount(page, size)
+  const result = await handler(start, count)
+
+  let next: string | undefined
+  let prev: string | undefined
+
+  // Assert page is a number
+  page = parseInt(page, 10)
+
+  // There are more results
+  if (result.total > page * size) {
+    next = baseUrl + '?page=' + (page + 1)
+  }
+
+  if (page > 1) {
+    prev = baseUrl + '?page=' + (page - 1)
+  }
+
+  return {
+    id: baseUrl + '?page=' + page,
+    type: 'OrderedCollectionPage',
+    prev,
+    next,
+    partOf: baseUrl,
+    orderedItems: result.data,
+    totalItems: result.total
+  }
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+  activityPubCollectionPagination
+}
similarity index 54%
rename from server/helpers/activitypub.ts
rename to server/lib/activitypub/context.ts
index 9d6d8b2fac74806f4c446ff69885c8bdfba29e2d..71f08da80052953c1a0b1fd74be1cd1c107c895f 100644 (file)
@@ -1,12 +1,4 @@
-import Bluebird from 'bluebird'
-import { URL } from 'url'
-import validator from 'validator'
-import { ContextType } from '@shared/models/activitypub/context'
-import { ResultList } from '../../shared/models'
-import { ACTIVITY_PUB, REMOTE_SCHEME } from '../initializers/constants'
-import { MActor, MVideoWithHost } from '../types/models'
-import { pageToStartAndCount } from './core-utils'
-import { signJsonLDObject } from './peertube-crypto'
+import { ContextType } from '@shared/models'
 
 function getContextData (type: ContextType) {
   const context: any[] = [
@@ -139,91 +131,7 @@ function activityPubContextify <T> (data: T, type: ContextType = 'All') {
   return Object.assign({}, data, getContextData(type))
 }
 
-type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>>
-async function activityPubCollectionPagination (
-  baseUrl: string,
-  handler: ActivityPubCollectionPaginationHandler,
-  page?: any,
-  size = ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE
-) {
-  if (!page || !validator.isInt(page)) {
-    // We just display the first page URL, we only need the total items
-    const result = await handler(0, 1)
-
-    return {
-      id: baseUrl,
-      type: 'OrderedCollectionPage',
-      totalItems: result.total,
-      first: result.data.length === 0
-        ? undefined
-        : baseUrl + '?page=1'
-    }
-  }
-
-  const { start, count } = pageToStartAndCount(page, size)
-  const result = await handler(start, count)
-
-  let next: string | undefined
-  let prev: string | undefined
-
-  // Assert page is a number
-  page = parseInt(page, 10)
-
-  // There are more results
-  if (result.total > page * size) {
-    next = baseUrl + '?page=' + (page + 1)
-  }
-
-  if (page > 1) {
-    prev = baseUrl + '?page=' + (page - 1)
-  }
-
-  return {
-    id: baseUrl + '?page=' + page,
-    type: 'OrderedCollectionPage',
-    prev,
-    next,
-    partOf: baseUrl,
-    orderedItems: result.data,
-    totalItems: result.total
-  }
-
-}
-
-function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: ContextType) {
-  const activity = activityPubContextify(data, contextType)
-
-  return signJsonLDObject(byActor, activity)
-}
-
-function getAPId (object: string | { id: string }) {
-  if (typeof object === 'string') return object
-
-  return object.id
-}
-
-function checkUrlsSameHost (url1: string, url2: string) {
-  const idHost = new URL(url1).host
-  const actorHost = new URL(url2).host
-
-  return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
-}
-
-function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
-  if (!scheme) scheme = REMOTE_SCHEME.HTTP
-
-  const host = video.VideoChannel.Actor.Server.host
-
-  return scheme + '://' + host + path
-}
-
-// ---------------------------------------------------------------------------
-
 export {
-  checkUrlsSameHost,
-  getAPId,
-  activityPubContextify,
-  activityPubCollectionPagination,
-  buildSignedActivity,
-  buildRemoteVideoBaseUrl
+  getContextData,
+  activityPubContextify
 }
index ef572c803451f0bd6ae9205b0983ec6bb5cd88b2..c28700be687349d3deb348637afd8b4c0e5b136a 100644 (file)
@@ -1,5 +1,4 @@
 import { map } from 'bluebird'
-import { getAPId } from '@server/helpers/activitypub'
 import { isArray } from '@server/helpers/custom-validators/misc'
 import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants'
@@ -9,8 +8,9 @@ import { VideoPlaylistModel } from '@server/models/video/video-playlist'
 import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
 import { FilteredModelAttributes } from '@server/types'
 import { MThumbnail, MVideoPlaylist, MVideoPlaylistFull, MVideoPlaylistVideosLength } from '@server/types/models'
-import { AttributesOnly } from '@shared/typescript-utils'
 import { PlaylistObject } from '@shared/models'
+import { AttributesOnly } from '@shared/typescript-utils'
+import { getAPId } from '../activity'
 import { getOrCreateAPActor } from '../actors'
 import { crawlCollectionPage } from '../crawl'
 import { getOrCreateAPVideo } from '../videos'
index be8456b19bcad284d494f9d0140901a48380e96d..bfaf52cc9ffa2795d1501e22c28a898c7f7c0897 100644 (file)
@@ -1,7 +1,7 @@
-import { getAPId } from '@server/helpers/activitypub'
 import { VideoPlaylistModel } from '@server/models/video/video-playlist'
 import { MVideoPlaylistFullSummary } from '@server/types/models'
 import { APObject } from '@shared/models'
+import { getAPId } from '../activity'
 import { createOrUpdateVideoPlaylist } from './create-update'
 import { scheduleRefreshIfNeeded } from './refresh'
 import { fetchRemoteVideoPlaylist } from './shared'
index ec8c0125503751696fa06503f9b01a76de33f14e..f895db587a763874f666f40af12abddf07a0e19c 100644 (file)
@@ -1,9 +1,9 @@
 import { isArray } from 'lodash'
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
 import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist'
 import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { doJSONRequest } from '@server/helpers/requests'
 import { PlaylistElementObject, PlaylistObject } from '@shared/models'
+import { checkUrlsSameHost } from '../../url'
 
 async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> {
   const lTags = loggerTagsFactory('ap', 'video-playlist', playlistUrl)
index 200f8ce11f2a30e4a87be9285e07d20cb513b7df..9cc87ee27a13fc60a5aa60efa0d323685c1bcc6f 100644 (file)
@@ -1,14 +1,14 @@
+import { getAPId } from '@server/lib/activitypub/activity'
 import { ActivityAnnounce } from '../../../../shared/models/activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
+import { logger } from '../../../helpers/logger'
 import { sequelizeTypescript } from '../../../initializers/database'
 import { VideoShareModel } from '../../../models/video/video-share'
-import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
-import { getOrCreateAPVideo } from '../videos'
-import { Notifier } from '../../notifier'
-import { logger } from '../../../helpers/logger'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
 import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
-import { getAPId } from '@server/helpers/activitypub'
+import { Notifier } from '../../notifier'
+import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
+import { getOrCreateAPVideo } from '../videos'
 
 async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
   const { activity, byActor: actorAnnouncer } = options
index a15d07a628bb7ef9c77d78902e8122d9c0a5a023..10f58ef27be981d833e6a8291f4fc7caf7d0f25f 100644 (file)
@@ -4,10 +4,10 @@ import { VideoModel } from '@server/models/video/video'
 import { VideoCommentModel } from '@server/models/video/video-comment'
 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
 import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '@shared/models'
-import { getAPId } from '../../../helpers/activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
 import { sequelizeTypescript } from '../../../initializers/database'
+import { getAPId } from '../../../lib/activitypub/activity'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
 import { MAccountDefault, MActorSignature, MCommentOwnerVideo } from '../../../types/models'
 
index e44590ffc52317f3e3982267e94046b37d97ad79..93df7e191e2a7f6b3c2061a4290c98e86b998905 100644 (file)
@@ -1,10 +1,10 @@
 import { getServerActor } from '@server/models/application/application'
 import { ActivityFollow } from '../../../../shared/models/activitypub'
-import { getAPId } from '../../../helpers/activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
 import { CONFIG } from '../../../initializers/config'
 import { sequelizeTypescript } from '../../../initializers/database'
+import { getAPId } from '../../../lib/activitypub/activity'
 import { ActorModel } from '../../../models/actor/actor'
 import { ActorFollowModel } from '../../../models/actor/actor-follow'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
index 93afb5edfabf9a3c8caa526f9586e94e6fc7c4a5..1aee756d86d32b5d93b58dabfc30db8b7676ff6c 100644 (file)
@@ -1,8 +1,8 @@
 import { VideoModel } from '@server/models/video/video'
 import { ActivityLike } from '../../../../shared/models/activitypub'
-import { getAPId } from '../../../helpers/activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { sequelizeTypescript } from '../../../initializers/database'
+import { getAPId } from '../../../lib/activitypub/activity'
 import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
 import { MActorSignature } from '../../../types/models'
index 02a23d098193bd1c8b9a4d97e47b163e428559b4..2bc3dce03e0c543e9b4c61dbeecb6257d73c90c9 100644 (file)
@@ -1,10 +1,11 @@
 import { StatsManager } from '@server/lib/stat-manager'
 import { Activity, ActivityType } from '../../../../shared/models/activitypub'
-import { checkUrlsSameHost, getAPId } from '../../../helpers/activitypub'
 import { logger } from '../../../helpers/logger'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
 import { MActorDefault, MActorSignature } from '../../../types/models'
+import { getAPId } from '../activity'
 import { getOrCreateAPActor } from '../actors'
+import { checkUrlsSameHost } from '../url'
 import { processAcceptActivity } from './process-accept'
 import { processAnnounceActivity } from './process-announce'
 import { processCreateActivity } from './process-create'
index b18761174ffdc02a2044c7747be8971c8cab0f07..0fefcbbc560fdfafb0febaa0d611ae9365803bc8 100644 (file)
@@ -1,15 +1,15 @@
 import { map } from 'bluebird'
 import { Transaction } from 'sequelize'
 import { getServerActor } from '@server/models/application/application'
-import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
 import { logger, loggerTagsFactory } from '../../helpers/logger'
 import { doJSONRequest } from '../../helpers/requests'
 import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
 import { VideoShareModel } from '../../models/video/video-share'
 import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video'
+import { getAPId } from './activity'
 import { getOrCreateAPActor } from './actors'
 import { sendUndoAnnounce, sendVideoAnnounce } from './send'
-import { getLocalVideoAnnounceActivityPubUrl } from './url'
+import { checkUrlsSameHost, getLocalVideoAnnounceActivityPubUrl } from './url'
 
 const lTags = loggerTagsFactory('share')
 
index 338398f2b0bf37cb88e4aad5c63d4d828c69d7c6..50be4fac9772716b7ff68252ba33f55113382794 100644 (file)
@@ -1,4 +1,4 @@
-import { WEBSERVER } from '../../initializers/constants'
+import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
 import {
   MAbuseFull,
   MAbuseId,
@@ -10,7 +10,8 @@ import {
   MVideoId,
   MVideoPlaylistElement,
   MVideoUrl,
-  MVideoUUID
+  MVideoUUID,
+  MVideoWithHost
 } from '../../types/models'
 import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
 import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
@@ -121,6 +122,27 @@ function getAbuseTargetUrl (abuse: MAbuseFull) {
     abuse.FlaggedAccount.Actor.url
 }
 
+// ---------------------------------------------------------------------------
+
+function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
+  if (!scheme) scheme = REMOTE_SCHEME.HTTP
+
+  const host = video.VideoChannel.Actor.Server.host
+
+  return scheme + '://' + host + path
+}
+
+// ---------------------------------------------------------------------------
+
+function checkUrlsSameHost (url1: string, url2: string) {
+  const idHost = new URL(url1).host
+  const actorHost = new URL(url2).host
+
+  return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
+}
+
+// ---------------------------------------------------------------------------
+
 export {
   getLocalVideoActivityPubUrl,
   getLocalVideoPlaylistActivityPubUrl,
@@ -145,5 +167,8 @@ export {
   getLocalVideoCommentsActivityPubUrl,
   getLocalVideoLikesActivityPubUrl,
   getLocalVideoDislikesActivityPubUrl,
-  getAbuseTargetUrl
+
+  getAbuseTargetUrl,
+  checkUrlsSameHost,
+  buildRemoteVideoBaseUrl
 }
index 2c7da3e0086bf22f08f47c9355e74e37f38d461b..911c7cd3020b5f334215bd4950095273d9d0d547 100644 (file)
@@ -1,5 +1,4 @@
 import { map } from 'bluebird'
-import { checkUrlsSameHost } from '../../helpers/activitypub'
 import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments'
 import { logger } from '../../helpers/logger'
 import { doJSONRequest } from '../../helpers/requests'
@@ -7,6 +6,7 @@ import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/cons
 import { VideoCommentModel } from '../../models/video/video-comment'
 import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video'
 import { getOrCreateAPActor } from './actors'
+import { checkUrlsSameHost } from './url'
 import { getOrCreateAPVideo } from './videos'
 
 type ResolveThreadParams = {
index b13c6ceeb1e876d55df7f15f3ecf1726c73a8b16..d7500c71a5e5f5c317a4631f467c6130aef94e52 100644 (file)
@@ -1,9 +1,9 @@
-import { getAPId } from '@server/helpers/activitypub'
 import { retryTransactionWrapper } from '@server/helpers/database-utils'
 import { JobQueue } from '@server/lib/job-queue'
 import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders'
 import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models'
 import { APObject } from '@shared/models'
+import { getAPId } from '../activity'
 import { refreshVideoIfNeeded } from './refresh'
 import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
 
index 788223b48d9a549dcd06a70c9240abdfcfca0fad..f299ba4fd736b6530893feae9d9b6cb49cf45958 100644 (file)
@@ -1,5 +1,4 @@
 import { Transaction } from 'sequelize/types'
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
 import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils'
 import { logger, LoggerTagsFn } from '@server/helpers/logger'
 import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail'
@@ -11,6 +10,7 @@ import { VideoStreamingPlaylistModel } from '@server/models/video/video-streamin
 import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models'
 import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models'
 import { getOrCreateAPActor } from '../../actors'
+import { checkUrlsSameHost } from '../../url'
 import {
   getCaptionAttributesFromObject,
   getFileAttributesFromUrl,
index 1c5fc4f84dc9730ce2f5cf8a3a4ea38cc9a7bb12..2418f45c2d12e3e329b9b472abc13cf561405ec3 100644 (file)
@@ -1,11 +1,11 @@
 import { Transaction } from 'sequelize/types'
-import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
 import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos'
 import { isArray } from '@server/helpers/custom-validators/misc'
 import { REMOTE_SCHEME } from '@server/initializers/constants'
 import { TrackerModel } from '@server/models/server/tracker'
 import { MVideo, MVideoWithHost } from '@server/types/models'
 import { ActivityTrackerUrlObject, VideoObject } from '@shared/models'
+import { buildRemoteVideoBaseUrl } from '../../url'
 
 function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
   let wsFound = false
index dba3e948079a8f5407b1a2bbe164e8ec9686675e..5b7007530f274bd3202fc1fb3bdc42793995ff1c 100644 (file)
@@ -1,8 +1,8 @@
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
 import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
 import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { doJSONRequest } from '@server/helpers/requests'
 import { VideoObject } from '@shared/models'
+import { checkUrlsSameHost } from '../../url'
 
 const lTags = loggerTagsFactory('ap', 'video')
 
index 07dd908cdff6b269b1de10ca8f77263a2617a5a2..123aeac032825ec5e67fe42bfcd670fefecd256f 100644 (file)
@@ -1,6 +1,5 @@
 import { map } from 'bluebird'
 import { Job } from 'bull'
-import { checkUrlsSameHost } from '@server/helpers/activitypub'
 import {
   isAnnounceActivityValid,
   isDislikeActivityValid,
@@ -9,6 +8,7 @@ import {
 import { sanitizeAndCheckVideoCommentObject } from '@server/helpers/custom-validators/activitypub/video-comments'
 import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests'
 import { AP_CLEANER } from '@server/initializers/constants'
+import { checkUrlsSameHost } from '@server/lib/activitypub/url'
 import { Redis } from '@server/lib/redis'
 import { VideoModel } from '@server/models/video/video'
 import { VideoCommentModel } from '@server/models/video/video-comment'
index 37e7c1fad4be2fa43687274d505ab532be7a6fb9..2a03325b7f8d5a9fcfd845b84385e1248603a6fa 100644 (file)
@@ -1,7 +1,7 @@
 import { buildDigest } from '@server/helpers/peertube-crypto'
+import { buildSignedActivity } from '@server/lib/activitypub/activity'
 import { getServerActor } from '@server/models/application/application'
 import { ContextType } from '@shared/models/activitypub/context'
-import { buildSignedActivity } from '../../../../helpers/activitypub'
 import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants'
 import { ActorModel } from '../../../../models/actor/actor'
 import { MActor } from '../../../../types/models'
index 86d3c1d6ccf377aa3eee8a8a4ee708d5f045f78a..2a2d86a24ffa56553759e9b5cce6ee945ac90ac2 100644 (file)
@@ -1,6 +1,6 @@
 import { NextFunction, Request, Response } from 'express'
-import { getAPId } from '@server/helpers/activitypub'
 import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
+import { getAPId } from '@server/lib/activitypub/activity'
 import { ActivityDelete, ActivityPubSignature, HttpStatusCode } from '@shared/models'
 import { logger } from '../helpers/logger'
 import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
index 08cb2fd2406bb9020c19d901e26751bbf82732ff..fad2070ea345d91027f55843b583a65a540535d6 100644 (file)
@@ -16,12 +16,12 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
+import { activityPubContextify } from '@server/lib/activitypub/context'
 import { getBiggestActorImage } from '@server/lib/actor-image'
 import { ModelCache } from '@server/models/model-cache'
 import { getLowercaseExtension } from '@shared/core-utils'
 import { ActivityIconObject, ActivityPubActorType, ActorImageType } from '@shared/models'
 import { AttributesOnly } from '@shared/typescript-utils'
-import { activityPubContextify } from '../../helpers/activitypub'
 import {
   isActorFollowersCountValid,
   isActorFollowingCountValid,
index fae76c6f29ce3ab104b3a954843174d77b9c0a22..4aaee1ffadbf7827814a73777b1d7dc572eccf3c 100644 (file)
@@ -19,9 +19,9 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import validator from 'validator'
-import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
 import { logger } from '@server/helpers/logger'
 import { extractVideo } from '@server/helpers/video'
+import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url'
 import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage'
 import { getFSTorrentFilePath } from '@server/lib/paths'
 import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
index ae5e237ec3f9b78687ec6756c30236f689244040..8fb3d5f153539ac910174b3506985edb3db78dec 100644 (file)
@@ -17,6 +17,7 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
+import { activityPubCollectionPagination } from '@server/lib/activitypub/collection'
 import { MAccountId, MChannelId } from '@server/types/models'
 import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils'
 import { buildUUID, uuidToShort } from '@shared/extra-utils'
@@ -26,7 +27,6 @@ import { PlaylistObject } from '../../../shared/models/activitypub/objects/playl
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
 import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model'
 import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model'
-import { activityPubCollectionPagination } from '../../helpers/activitypub'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import {
   isVideoPlaylistDescriptionValid,
index 25e1d982343b34c7805cd92d72af1459ea01fee9..e516cf49e8ce03c1f21c5b849cf8e646c0f0b468 100644 (file)
@@ -5,8 +5,8 @@ import { expect } from 'chai'
 import { cloneDeep } from 'lodash'
 import { buildRequestStub } from '@server/tests/shared'
 import { buildAbsoluteFixturePath } from '@shared/core-utils'
-import { buildSignedActivity } from '../../../helpers/activitypub'
 import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
+import { buildSignedActivity } from '../../../lib/activitypub/activity'
 
 describe('Test activity pub helpers', function () {
   describe('When checking the Linked Signature', function () {
index c4cb5ea0daa8c38cf1eaa87896b6861313db269e..da9880d7d3237e96461bc137888f5b57c061396f 100644 (file)
@@ -2,9 +2,10 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { activityPubContextify, buildSignedActivity } from '@server/helpers/activitypub'
 import { buildDigest } from '@server/helpers/peertube-crypto'
 import { HTTP_SIGNATURE } from '@server/initializers/constants'
+import { buildSignedActivity } from '@server/lib/activitypub/activity'
+import { activityPubContextify } from '@server/lib/activitypub/context'
 import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils'
 import { makeFollowRequest, makePOSTAPRequest } from '@server/tests/shared'
 import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
index 7f1acc0e1333cd88f487903a54e5314c931f04e4..d7aedf82f22b092c143af733d65fa000e8b116e4 100644 (file)
@@ -1,7 +1,7 @@
-import { activityPubContextify } from '@server/helpers/activitypub'
 import { buildDigest } from '@server/helpers/peertube-crypto'
 import { doRequest } from '@server/helpers/requests'
 import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants'
+import { activityPubContextify } from '@server/lib/activitypub/context'
 
 export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
   const options = {