aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-create.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r--server/lib/activitypub/process/process-create.ts48
1 files changed, 25 insertions, 23 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index 4740dc432..c1eb2a8ab 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -1,10 +1,12 @@
1import { ActivityCreate, VideoChannelObject } from '../../../../shared' 1import { ActivityCreate, VideoChannelObject } from '../../../../shared'
2import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object' 2import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects'
3import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects/video-abuse-object'
4import { ViewObject } from '../../../../shared/models/activitypub/objects/view-object'
5import { logger, retryTransactionWrapper } from '../../../helpers' 3import { logger, retryTransactionWrapper } from '../../../helpers'
6import { database as db } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
7import { AccountInstance } from '../../../models/account/account-interface' 5import { AccountModel } from '../../../models/account/account'
6import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
7import { VideoModel } from '../../../models/video/video'
8import { VideoAbuseModel } from '../../../models/video/video-abuse'
9import { VideoChannelModel } from '../../../models/video/video-channel'
8import { getOrCreateAccountAndServer } from '../account' 10import { getOrCreateAccountAndServer } from '../account'
9import { forwardActivity } from '../send/misc' 11import { forwardActivity } from '../send/misc'
10import { getVideoChannelActivityPubUrl } from '../url' 12import { getVideoChannelActivityPubUrl } from '../url'
@@ -37,7 +39,7 @@ export {
37 39
38// --------------------------------------------------------------------------- 40// ---------------------------------------------------------------------------
39 41
40async function processCreateDislike (byAccount: AccountInstance, activity: ActivityCreate) { 42async function processCreateDislike (byAccount: AccountModel, activity: ActivityCreate) {
41 const options = { 43 const options = {
42 arguments: [ byAccount, activity ], 44 arguments: [ byAccount, activity ],
43 errorMessage: 'Cannot dislike the video with many retries.' 45 errorMessage: 'Cannot dislike the video with many retries.'
@@ -46,11 +48,11 @@ async function processCreateDislike (byAccount: AccountInstance, activity: Activ
46 return retryTransactionWrapper(createVideoDislike, options) 48 return retryTransactionWrapper(createVideoDislike, options)
47} 49}
48 50
49function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreate) { 51function createVideoDislike (byAccount: AccountModel, activity: ActivityCreate) {
50 const dislike = activity.object as DislikeObject 52 const dislike = activity.object as DislikeObject
51 53
52 return db.sequelize.transaction(async t => { 54 return sequelizeTypescript.transaction(async t => {
53 const video = await db.Video.loadByUrlAndPopulateAccount(dislike.object, t) 55 const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t)
54 if (!video) throw new Error('Unknown video ' + dislike.object) 56 if (!video) throw new Error('Unknown video ' + dislike.object)
55 57
56 const rate = { 58 const rate = {
@@ -58,7 +60,7 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat
58 videoId: video.id, 60 videoId: video.id,
59 accountId: byAccount.id 61 accountId: byAccount.id
60 } 62 }
61 const [ , created ] = await db.AccountVideoRate.findOrCreate({ 63 const [ , created ] = await AccountVideoRateModel.findOrCreate({
62 where: rate, 64 where: rate,
63 defaults: rate, 65 defaults: rate,
64 transaction: t 66 transaction: t
@@ -73,14 +75,14 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat
73 }) 75 })
74} 76}
75 77
76async function processCreateView (byAccount: AccountInstance, activity: ActivityCreate) { 78async function processCreateView (byAccount: AccountModel, activity: ActivityCreate) {
77 const view = activity.object as ViewObject 79 const view = activity.object as ViewObject
78 80
79 const video = await db.Video.loadByUrlAndPopulateAccount(view.object) 81 const video = await VideoModel.loadByUrlAndPopulateAccount(view.object)
80 82
81 if (!video) throw new Error('Unknown video ' + view.object) 83 if (!video) throw new Error('Unknown video ' + view.object)
82 84
83 const account = await db.Account.loadByUrl(view.actor) 85 const account = await AccountModel.loadByUrl(view.actor)
84 if (!account) throw new Error('Unknown account ' + view.actor) 86 if (!account) throw new Error('Unknown account ' + view.actor)
85 87
86 await video.increment('views') 88 await video.increment('views')
@@ -92,7 +94,7 @@ async function processCreateView (byAccount: AccountInstance, activity: Activity
92 } 94 }
93} 95}
94 96
95async function processCreateVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { 97async function processCreateVideoChannel (account: AccountModel, videoChannelToCreateData: VideoChannelObject) {
96 const options = { 98 const options = {
97 arguments: [ account, videoChannelToCreateData ], 99 arguments: [ account, videoChannelToCreateData ],
98 errorMessage: 'Cannot insert the remote video channel with many retries.' 100 errorMessage: 'Cannot insert the remote video channel with many retries.'
@@ -107,15 +109,15 @@ async function processCreateVideoChannel (account: AccountInstance, videoChannel
107 return videoChannel 109 return videoChannel
108} 110}
109 111
110function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { 112function addRemoteVideoChannel (account: AccountModel, videoChannelToCreateData: VideoChannelObject) {
111 logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid) 113 logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid)
112 114
113 return db.sequelize.transaction(async t => { 115 return sequelizeTypescript.transaction(async t => {
114 let videoChannel = await db.VideoChannel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t) 116 let videoChannel = await VideoChannelModel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t)
115 if (videoChannel) return videoChannel 117 if (videoChannel) return videoChannel
116 118
117 const videoChannelData = videoChannelActivityObjectToDBAttributes(videoChannelToCreateData, account) 119 const videoChannelData = videoChannelActivityObjectToDBAttributes(videoChannelToCreateData, account)
118 videoChannel = db.VideoChannel.build(videoChannelData) 120 videoChannel = new VideoChannelModel(videoChannelData)
119 videoChannel.url = getVideoChannelActivityPubUrl(videoChannel) 121 videoChannel.url = getVideoChannelActivityPubUrl(videoChannel)
120 122
121 videoChannel = await videoChannel.save({ transaction: t }) 123 videoChannel = await videoChannel.save({ transaction: t })
@@ -125,7 +127,7 @@ function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateDa
125 }) 127 })
126} 128}
127 129
128function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { 130function processCreateVideoAbuse (account: AccountModel, videoAbuseToCreateData: VideoAbuseObject) {
129 const options = { 131 const options = {
130 arguments: [ account, videoAbuseToCreateData ], 132 arguments: [ account, videoAbuseToCreateData ],
131 errorMessage: 'Cannot insert the remote video abuse with many retries.' 133 errorMessage: 'Cannot insert the remote video abuse with many retries.'
@@ -134,11 +136,11 @@ function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateDa
134 return retryTransactionWrapper(addRemoteVideoAbuse, options) 136 return retryTransactionWrapper(addRemoteVideoAbuse, options)
135} 137}
136 138
137function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { 139function addRemoteVideoAbuse (account: AccountModel, videoAbuseToCreateData: VideoAbuseObject) {
138 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) 140 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
139 141
140 return db.sequelize.transaction(async t => { 142 return sequelizeTypescript.transaction(async t => {
141 const video = await db.Video.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t) 143 const video = await VideoModel.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t)
142 if (!video) { 144 if (!video) {
143 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) 145 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object)
144 return undefined 146 return undefined
@@ -150,7 +152,7 @@ function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData:
150 videoId: video.id 152 videoId: video.id
151 } 153 }
152 154
153 await db.VideoAbuse.create(videoAbuseData) 155 await VideoAbuseModel.create(videoAbuseData)
154 156
155 logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) 157 logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object)
156 }) 158 })