aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-add.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-add.ts')
-rw-r--r--server/lib/activitypub/process/process-add.ts42
1 files changed, 22 insertions, 20 deletions
diff --git a/server/lib/activitypub/process/process-add.ts b/server/lib/activitypub/process/process-add.ts
index e6bf63eb2..550593eab 100644
--- a/server/lib/activitypub/process/process-add.ts
+++ b/server/lib/activitypub/process/process-add.ts
@@ -1,13 +1,15 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { VideoTorrentObject } from '../../../../shared' 2import { VideoTorrentObject } from '../../../../shared'
3import { ActivityAdd } from '../../../../shared/models/activitypub/activity' 3import { ActivityAdd } from '../../../../shared/models/activitypub'
4import { VideoRateType } from '../../../../shared/models/videos/video-rate.type' 4import { VideoRateType } from '../../../../shared/models/videos'
5import { retryTransactionWrapper } from '../../../helpers/database-utils' 5import { logger, retryTransactionWrapper } from '../../../helpers'
6import { logger } from '../../../helpers/logger' 6import { sequelizeTypescript } from '../../../initializers'
7import { database as db } from '../../../initializers' 7import { AccountModel } from '../../../models/account/account'
8import { AccountInstance } from '../../../models/account/account-interface' 8import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { VideoChannelInstance } from '../../../models/video/video-channel-interface' 9import { TagModel } from '../../../models/video/tag'
10import { VideoInstance } from '../../../models/video/video-interface' 10import { VideoModel } from '../../../models/video/video'
11import { VideoChannelModel } from '../../../models/video/video-channel'
12import { VideoFileModel } from '../../../models/video/video-file'
11import { getOrCreateAccountAndServer } from '../account' 13import { getOrCreateAccountAndServer } from '../account'
12import { getOrCreateVideoChannel } from '../video-channels' 14import { getOrCreateVideoChannel } from '../video-channels'
13import { generateThumbnailFromUrl } from '../videos' 15import { generateThumbnailFromUrl } from '../videos'
@@ -37,9 +39,9 @@ export {
37 39
38// --------------------------------------------------------------------------- 40// ---------------------------------------------------------------------------
39 41
40async function processAddVideo (account: AccountInstance, 42async function processAddVideo (account: AccountModel,
41 activity: ActivityAdd, 43 activity: ActivityAdd,
42 videoChannel: VideoChannelInstance, 44 videoChannel: VideoChannelModel,
43 videoToCreateData: VideoTorrentObject) { 45 videoToCreateData: VideoTorrentObject) {
44 const options = { 46 const options = {
45 arguments: [ account, activity, videoChannel, videoToCreateData ], 47 arguments: [ account, activity, videoChannel, videoToCreateData ],
@@ -64,24 +66,24 @@ async function processAddVideo (account: AccountInstance,
64 return video 66 return video
65} 67}
66 68
67function addRemoteVideo (account: AccountInstance, 69function addRemoteVideo (account: AccountModel,
68 activity: ActivityAdd, 70 activity: ActivityAdd,
69 videoChannel: VideoChannelInstance, 71 videoChannel: VideoChannelModel,
70 videoToCreateData: VideoTorrentObject) { 72 videoToCreateData: VideoTorrentObject) {
71 logger.debug('Adding remote video %s.', videoToCreateData.id) 73 logger.debug('Adding remote video %s.', videoToCreateData.id)
72 74
73 return db.sequelize.transaction(async t => { 75 return sequelizeTypescript.transaction(async t => {
74 const sequelizeOptions = { 76 const sequelizeOptions = {
75 transaction: t 77 transaction: t
76 } 78 }
77 79
78 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.') 80 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.')
79 81
80 const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t) 82 const videoFromDatabase = await VideoModel.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t)
81 if (videoFromDatabase) return videoFromDatabase 83 if (videoFromDatabase) return videoFromDatabase
82 84
83 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, activity.to, activity.cc) 85 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, activity.to, activity.cc)
84 const video = db.Video.build(videoData) 86 const video = VideoModel.build(videoData)
85 87
86 // Don't block on request 88 // Don't block on request
87 generateThumbnailFromUrl(video, videoToCreateData.icon) 89 generateThumbnailFromUrl(video, videoToCreateData.icon)
@@ -94,12 +96,12 @@ function addRemoteVideo (account: AccountInstance,
94 throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url) 96 throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url)
95 } 97 }
96 98
97 const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f, { transaction: t })) 99 const tasks: Bluebird<any>[] = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t }))
98 await Promise.all(tasks) 100 await Promise.all(tasks)
99 101
100 const tags = videoToCreateData.tag.map(t => t.name) 102 const tags = videoToCreateData.tag.map(t => t.name)
101 const tagInstances = await db.Tag.findOrCreateTags(tags, t) 103 const tagInstances = await TagModel.findOrCreateTags(tags, t)
102 await videoCreated.setTags(tagInstances, sequelizeOptions) 104 await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
103 105
104 logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid) 106 logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)
105 107
@@ -107,13 +109,13 @@ function addRemoteVideo (account: AccountInstance,
107 }) 109 })
108} 110}
109 111
110async function createRates (accountUrls: string[], video: VideoInstance, rate: VideoRateType) { 112async function createRates (accountUrls: string[], video: VideoModel, rate: VideoRateType) {
111 let rateCounts = 0 113 let rateCounts = 0
112 const tasks: Bluebird<any>[] = [] 114 const tasks: Bluebird<any>[] = []
113 115
114 for (const accountUrl of accountUrls) { 116 for (const accountUrl of accountUrls) {
115 const account = await getOrCreateAccountAndServer(accountUrl) 117 const account = await getOrCreateAccountAndServer(accountUrl)
116 const p = db.AccountVideoRate 118 const p = AccountVideoRateModel
117 .create({ 119 .create({
118 videoId: video.id, 120 videoId: video.id,
119 accountId: account.id, 121 accountId: account.id,