diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/index.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/process-add.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/process-announce.ts | 52 | ||||
-rw-r--r-- | server/lib/activitypub/process-create.ts | 9 |
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 @@ | |||
1 | export * from './process-accept' | ||
2 | export * from './process-add' | ||
3 | export * from './process-announce' | ||
1 | export * from './process-create' | 4 | export * from './process-create' |
5 | export * from './process-delete' | ||
2 | export * from './process-flag' | 6 | export * from './process-flag' |
7 | export * from './process-follow' | ||
3 | export * from './process-update' | 8 | export * from './process-update' |
4 | export * from './send-request' | 9 | export * 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 | |||
39 | async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string, videoToCreateData: VideoTorrentObject) { | 39 | async 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 @@ | |||
1 | import { ActivityAnnounce } from '../../../shared/models/activitypub/activity' | ||
2 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' | ||
3 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' | ||
4 | import { logger } from '../../helpers/logger' | ||
5 | import { processAddActivity } from './process-add' | ||
6 | import { processCreateActivity } from './process-create' | ||
7 | import { database as db } from '../../initializers/index' | ||
8 | import { getOrCreateAccount } from '../../helpers/activitypub' | ||
9 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' | ||
10 | import { VideoInstance } from '../../models/index' | ||
11 | |||
12 | async 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 | |||
50 | export { | ||
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 | |||
40 | async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { | 40 | async 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 | ||
66 | function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { | 67 | function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { |