Playlist server API

This commit is contained in:
Chocobozzz
2019-02-26 10:55:40 +01:00
committed by Chocobozzz
parent b427febb4d
commit 418d092afa
63 changed files with 2758 additions and 226 deletions

View 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)
}

View File

@@ -12,6 +12,8 @@ import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-vali
import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
import { createOrUpdateCacheFile } from '../cache-file'
import { forwardVideoRelatedActivity } from '../send/utils'
import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
import { createOrUpdateVideoPlaylist } from '../playlist'
async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorModel) {
const objectType = activity.object.type
@@ -32,6 +34,10 @@ async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorMo
return retryTransactionWrapper(processUpdateCacheFile, byActorFull, activity)
}
if (objectType === 'Playlist') {
return retryTransactionWrapper(processUpdatePlaylist, byActor, activity)
}
return undefined
}
@@ -135,3 +141,12 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate)
throw err
}
}
async function processUpdatePlaylist (byActor: ActorModel, activity: ActivityUpdate) {
const playlistObject = activity.object as PlaylistObject
const byAccount = byActor.Account
if (!byAccount) throw new Error('Cannot update video playlist with the non account actor ' + byActor.url)
await createOrUpdateVideoPlaylist(playlistObject, byAccount, activity.to)
}