mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Handle announces in inbox
This commit is contained in:
parent
8e10cf1a5a
commit
d846501818
17 changed files with 264 additions and 23 deletions
|
@ -1,4 +1,9 @@
|
|||
export * from './process-accept'
|
||||
export * from './process-add'
|
||||
export * from './process-announce'
|
||||
export * from './process-create'
|
||||
export * from './process-delete'
|
||||
export * from './process-flag'
|
||||
export * from './process-follow'
|
||||
export * from './process-update'
|
||||
export * from './send-request'
|
||||
|
|
|
@ -39,7 +39,7 @@ function processAddVideo (account: AccountInstance, videoChannelUrl: string, vid
|
|||
async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string, videoToCreateData: VideoTorrentObject) {
|
||||
logger.debug('Adding remote video %s.', videoToCreateData.url)
|
||||
|
||||
await db.sequelize.transaction(async t => {
|
||||
return db.sequelize.transaction(async t => {
|
||||
const sequelizeOptions = {
|
||||
transaction: t
|
||||
}
|
||||
|
@ -66,7 +66,10 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
|
|||
const tags = videoToCreateData.tag.map(t => t.name)
|
||||
const tagInstances = await db.Tag.findOrCreateTags(tags, t)
|
||||
await videoCreated.setTags(tagInstances, sequelizeOptions)
|
||||
|
||||
logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
|
||||
|
||||
return videoCreated
|
||||
})
|
||||
|
||||
logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
|
||||
}
|
||||
|
|
52
server/lib/activitypub/process-announce.ts
Normal file
52
server/lib/activitypub/process-announce.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { ActivityAnnounce } from '../../../shared/models/activitypub/activity'
|
||||
import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
|
||||
import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { processAddActivity } from './process-add'
|
||||
import { processCreateActivity } from './process-create'
|
||||
import { database as db } from '../../initializers/index'
|
||||
import { getOrCreateAccount } from '../../helpers/activitypub'
|
||||
import { VideoChannelInstance } from '../../models/video/video-channel-interface'
|
||||
import { VideoInstance } from '../../models/index'
|
||||
|
||||
async function processAnnounceActivity (activity: ActivityAnnounce) {
|
||||
const activityType = activity.object.type
|
||||
const accountAnnouncer = await getOrCreateAccount(activity.actor)
|
||||
|
||||
if (activityType === 'VideoChannel') {
|
||||
const activityCreate = Object.assign(activity, {
|
||||
type: 'Create' as 'Create',
|
||||
actor: activity.object.actor,
|
||||
object: activity.object as VideoChannelObject
|
||||
})
|
||||
|
||||
// Add share entry
|
||||
const videoChannel: VideoChannelInstance = await processCreateActivity(activityCreate)
|
||||
await db.VideoChannelShare.create({
|
||||
accountId: accountAnnouncer.id,
|
||||
videoChannelId: videoChannel.id
|
||||
})
|
||||
} else if (activityType === 'Video') {
|
||||
const activityAdd = Object.assign(activity, {
|
||||
type: 'Add' as 'Add',
|
||||
actor: activity.object.actor,
|
||||
object: activity.object as VideoTorrentObject
|
||||
})
|
||||
|
||||
// Add share entry
|
||||
const video: VideoInstance = await processAddActivity(activityAdd)
|
||||
await db.VideoShare.create({
|
||||
accountId: accountAnnouncer.id,
|
||||
videoId: video.id
|
||||
})
|
||||
}
|
||||
|
||||
logger.warn('Unknown activity object type %s when announcing activity.', activityType, { activity: activity.id })
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
processAnnounceActivity
|
||||
}
|
|
@ -40,7 +40,7 @@ function processCreateVideoChannel (account: AccountInstance, videoChannelToCrea
|
|||
async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) {
|
||||
logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid)
|
||||
|
||||
await db.sequelize.transaction(async t => {
|
||||
return db.sequelize.transaction(async t => {
|
||||
let videoChannel = await db.VideoChannel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t)
|
||||
if (videoChannel) throw new Error('Video channel with this URL/UUID already exists.')
|
||||
|
||||
|
@ -57,10 +57,11 @@ async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCr
|
|||
videoChannel = db.VideoChannel.build(videoChannelData)
|
||||
videoChannel.url = getActivityPubUrl('videoChannel', videoChannel.uuid)
|
||||
|
||||
await videoChannel.save({ transaction: t })
|
||||
})
|
||||
videoChannel = await videoChannel.save({ transaction: t })
|
||||
logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid)
|
||||
|
||||
logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid)
|
||||
return videoChannel
|
||||
})
|
||||
}
|
||||
|
||||
function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue