aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 17:56:21 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commitd846501818c2d29e66e6fd141789cb04fd55a437 (patch)
tree9b807a84459edd400fd36325c49c4adfbd6c4fd2 /server/lib
parent8e10cf1a5a438a00e5f7e0691cb830769867cffc (diff)
downloadPeerTube-d846501818c2d29e66e6fd141789cb04fd55a437.tar.gz
PeerTube-d846501818c2d29e66e6fd141789cb04fd55a437.tar.zst
PeerTube-d846501818c2d29e66e6fd141789cb04fd55a437.zip
Handle announces in inbox
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/index.ts5
-rw-r--r--server/lib/activitypub/process-add.ts7
-rw-r--r--server/lib/activitypub/process-announce.ts52
-rw-r--r--server/lib/activitypub/process-create.ts9
4 files changed, 67 insertions, 6 deletions
diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts
index f8d56528a..dca446fd4 100644
--- a/server/lib/activitypub/index.ts
+++ b/server/lib/activitypub/index.ts
@@ -1,4 +1,9 @@
1export * from './process-accept'
2export * from './process-add'
3export * from './process-announce'
1export * from './process-create' 4export * from './process-create'
5export * from './process-delete'
2export * from './process-flag' 6export * from './process-flag'
7export * from './process-follow'
3export * from './process-update' 8export * from './process-update'
4export * from './send-request' 9export * from './send-request'
diff --git a/server/lib/activitypub/process-add.ts b/server/lib/activitypub/process-add.ts
index 06d23a2ea..98e414dbb 100644
--- a/server/lib/activitypub/process-add.ts
+++ b/server/lib/activitypub/process-add.ts
@@ -39,7 +39,7 @@ function processAddVideo (account: AccountInstance, videoChannelUrl: string, vid
39async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string, videoToCreateData: VideoTorrentObject) { 39async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string, videoToCreateData: VideoTorrentObject) {
40 logger.debug('Adding remote video %s.', videoToCreateData.url) 40 logger.debug('Adding remote video %s.', videoToCreateData.url)
41 41
42 await db.sequelize.transaction(async t => { 42 return db.sequelize.transaction(async t => {
43 const sequelizeOptions = { 43 const sequelizeOptions = {
44 transaction: t 44 transaction: t
45 } 45 }
@@ -66,7 +66,10 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
66 const tags = videoToCreateData.tag.map(t => t.name) 66 const tags = videoToCreateData.tag.map(t => t.name)
67 const tagInstances = await db.Tag.findOrCreateTags(tags, t) 67 const tagInstances = await db.Tag.findOrCreateTags(tags, t)
68 await videoCreated.setTags(tagInstances, sequelizeOptions) 68 await videoCreated.setTags(tagInstances, sequelizeOptions)
69
70 logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
71
72 return videoCreated
69 }) 73 })
70 74
71 logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
72} 75}
diff --git a/server/lib/activitypub/process-announce.ts b/server/lib/activitypub/process-announce.ts
new file mode 100644
index 000000000..d67958aec
--- /dev/null
+++ b/server/lib/activitypub/process-announce.ts
@@ -0,0 +1,52 @@
1import { ActivityAnnounce } from '../../../shared/models/activitypub/activity'
2import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
3import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
4import { logger } from '../../helpers/logger'
5import { processAddActivity } from './process-add'
6import { processCreateActivity } from './process-create'
7import { database as db } from '../../initializers/index'
8import { getOrCreateAccount } from '../../helpers/activitypub'
9import { VideoChannelInstance } from '../../models/video/video-channel-interface'
10import { VideoInstance } from '../../models/index'
11
12async function processAnnounceActivity (activity: ActivityAnnounce) {
13 const activityType = activity.object.type
14 const accountAnnouncer = await getOrCreateAccount(activity.actor)
15
16 if (activityType === 'VideoChannel') {
17 const activityCreate = Object.assign(activity, {
18 type: 'Create' as 'Create',
19 actor: activity.object.actor,
20 object: activity.object as VideoChannelObject
21 })
22
23 // Add share entry
24 const videoChannel: VideoChannelInstance = await processCreateActivity(activityCreate)
25 await db.VideoChannelShare.create({
26 accountId: accountAnnouncer.id,
27 videoChannelId: videoChannel.id
28 })
29 } else if (activityType === 'Video') {
30 const activityAdd = Object.assign(activity, {
31 type: 'Add' as 'Add',
32 actor: activity.object.actor,
33 object: activity.object as VideoTorrentObject
34 })
35
36 // Add share entry
37 const video: VideoInstance = await processAddActivity(activityAdd)
38 await db.VideoShare.create({
39 accountId: accountAnnouncer.id,
40 videoId: video.id
41 })
42 }
43
44 logger.warn('Unknown activity object type %s when announcing activity.', activityType, { activity: activity.id })
45 return Promise.resolve(undefined)
46}
47
48// ---------------------------------------------------------------------------
49
50export {
51 processAnnounceActivity
52}
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts
index 8d842b822..1b825ebbc 100644
--- a/server/lib/activitypub/process-create.ts
+++ b/server/lib/activitypub/process-create.ts
@@ -40,7 +40,7 @@ function processCreateVideoChannel (account: AccountInstance, videoChannelToCrea
40async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { 40async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) {
41 logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid) 41 logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid)
42 42
43 await db.sequelize.transaction(async t => { 43 return db.sequelize.transaction(async t => {
44 let videoChannel = await db.VideoChannel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t) 44 let videoChannel = await db.VideoChannel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t)
45 if (videoChannel) throw new Error('Video channel with this URL/UUID already exists.') 45 if (videoChannel) throw new Error('Video channel with this URL/UUID already exists.')
46 46
@@ -57,10 +57,11 @@ async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCr
57 videoChannel = db.VideoChannel.build(videoChannelData) 57 videoChannel = db.VideoChannel.build(videoChannelData)
58 videoChannel.url = getActivityPubUrl('videoChannel', videoChannel.uuid) 58 videoChannel.url = getActivityPubUrl('videoChannel', videoChannel.uuid)
59 59
60 await videoChannel.save({ transaction: t }) 60 videoChannel = await videoChannel.save({ transaction: t })
61 }) 61 logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid)
62 62
63 logger.info('Remote video channel with uuid %s inserted.', videoChannelToCreateData.uuid) 63 return videoChannel
64 })
64} 65}
65 66
66function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { 67function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) {