]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-create.ts
Move config in its own file
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-create.ts
index 5f4d793a5746db35d9ae3312616bc76afb15b20f..e882669ceea30cb6954e99ce9d286ebc2c9cf43e 100644 (file)
@@ -12,6 +12,8 @@ import { Notifier } from '../../notifier'
 import { processViewActivity } from './process-view'
 import { processDislikeActivity } from './process-dislike'
 import { processFlagActivity } from './process-flag'
+import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
+import { createOrUpdateVideoPlaylist } from '../playlist'
 
 async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
   const activityObject = activity.object
@@ -38,7 +40,11 @@ async function processCreateActivity (activity: ActivityCreate, byActor: ActorMo
   }
 
   if (activityType === 'CacheFile') {
-    return retryTransactionWrapper(processCacheFile, activity, byActor)
+    return retryTransactionWrapper(processCreateCacheFile, activity, byActor)
+  }
+
+  if (activityType === 'Playlist') {
+    return retryTransactionWrapper(processCreatePlaylist, activity, byActor)
   }
 
   logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
@@ -63,7 +69,7 @@ async function processCreateVideo (activity: ActivityCreate) {
   return video
 }
 
-async function processCacheFile (activity: ActivityCreate, byActor: ActorModel) {
+async function processCreateCacheFile (activity: ActivityCreate, byActor: ActorModel) {
   const cacheFile = activity.object as CacheFileObject
 
   const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
@@ -98,3 +104,12 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: Act
 
   if (created === true) Notifier.Instance.notifyOnNewComment(comment)
 }
+
+async function processCreatePlaylist (activity: ActivityCreate, byActor: ActorModel) {
+  const playlistObject = activity.object as PlaylistObject
+  const byAccount = byActor.Account
+
+  if (!byAccount) throw new Error('Cannot create video playlist with the non account actor ' + byActor.url)
+
+  await createOrUpdateVideoPlaylist(playlistObject, byAccount, activity.to)
+}