]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/actors/get.ts
Fix schema.org context
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / actors / get.ts
index d7cf2b678a388dc1fedf88d963caf6dc5eaa9926..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'
 
@@ -68,9 +68,28 @@ async function getOrCreateAPActor (
   return actorRefreshed
 }
 
+function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
+  const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
+  if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
+
+  if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
+    throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
+  }
+
+  try {
+    // Don't recurse another time
+    const recurseIfNeeded = false
+    return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
+  } catch (err) {
+    logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
+    throw new Error(err)
+  }
+}
+
 // ---------------------------------------------------------------------------
 
 export {
+  getOrCreateAPOwner,
   getOrCreateAPActor
 }
 
@@ -88,24 +107,6 @@ async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType)
   return actor
 }
 
-function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
-  const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
-  if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
-
-  if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
-    throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
-  }
-
-  try {
-    // Don't recurse another time
-    const recurseIfNeeded = false
-    return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
-  } catch (err) {
-    logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
-    throw new Error(err)
-  }
-}
-
 async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) {
   if ((created === true || refreshed === true) && updateCollections === true) {
     const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }
@@ -116,7 +117,7 @@ async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, ref
 async function schedulePlaylistFetchIfNeeded (actor: MActorAccountId, created: boolean, accountPlaylistsUrl: string) {
   // We created a new account: fetch the playlists
   if (created === true && actor.Account && accountPlaylistsUrl) {
-    const payload = { uri: accountPlaylistsUrl, accountId: actor.Account.id, type: 'account-playlists' as 'account-playlists' }
+    const payload = { uri: accountPlaylistsUrl, type: 'account-playlists' as 'account-playlists' }
     await JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })
   }
 }