aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r--server/lib/activitypub/process/process-update.ts39
1 files changed, 20 insertions, 19 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 11c6de8f5..771021f0c 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,12 +1,13 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' 2import { VideoChannelObject, VideoTorrentObject } from '../../../../shared'
3import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' 3import { ActivityUpdate } from '../../../../shared/models/activitypub'
4import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers'
5import { logger } from '../../../helpers/logger' 5import { sequelizeTypescript } from '../../../initializers'
6import { resetSequelizeInstance } from '../../../helpers/utils' 6import { AccountModel } from '../../../models/account/account'
7import { database as db } from '../../../initializers' 7import { TagModel } from '../../../models/video/tag'
8import { AccountInstance } from '../../../models/account/account-interface' 8import { VideoModel } from '../../../models/video/video'
9import { VideoInstance } from '../../../models/video/video-interface' 9import { VideoChannelModel } from '../../../models/video/video-channel'
10import { VideoFileModel } from '../../../models/video/video-file'
10import { getOrCreateAccountAndServer } from '../account' 11import { getOrCreateAccountAndServer } from '../account'
11import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' 12import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
12 13
@@ -30,7 +31,7 @@ export {
30 31
31// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
32 33
33function processUpdateVideo (account: AccountInstance, video: VideoTorrentObject) { 34function processUpdateVideo (account: AccountModel, video: VideoTorrentObject) {
34 const options = { 35 const options = {
35 arguments: [ account, video ], 36 arguments: [ account, video ],
36 errorMessage: 'Cannot update the remote video with many retries' 37 errorMessage: 'Cannot update the remote video with many retries'
@@ -39,18 +40,18 @@ function processUpdateVideo (account: AccountInstance, video: VideoTorrentObject
39 return retryTransactionWrapper(updateRemoteVideo, options) 40 return retryTransactionWrapper(updateRemoteVideo, options)
40} 41}
41 42
42async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpdate: VideoTorrentObject) { 43async function updateRemoteVideo (account: AccountModel, videoAttributesToUpdate: VideoTorrentObject) {
43 logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) 44 logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
44 let videoInstance: VideoInstance 45 let videoInstance: VideoModel
45 let videoFieldsSave: object 46 let videoFieldsSave: object
46 47
47 try { 48 try {
48 await db.sequelize.transaction(async t => { 49 await sequelizeTypescript.transaction(async t => {
49 const sequelizeOptions = { 50 const sequelizeOptions = {
50 transaction: t 51 transaction: t
51 } 52 }
52 53
53 const videoInstance = await db.Video.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t) 54 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t)
54 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.') 55 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.')
55 56
56 if (videoInstance.VideoChannel.Account.id !== account.id) { 57 if (videoInstance.VideoChannel.Account.id !== account.id) {
@@ -81,12 +82,12 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd
81 await Promise.all(videoFileDestroyTasks) 82 await Promise.all(videoFileDestroyTasks)
82 83
83 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) 84 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate)
84 const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f)) 85 const tasks: Bluebird<any>[] = videoFileAttributes.map(f => VideoFileModel.create(f))
85 await Promise.all(tasks) 86 await Promise.all(tasks)
86 87
87 const tags = videoAttributesToUpdate.tag.map(t => t.name) 88 const tags = videoAttributesToUpdate.tag.map(t => t.name)
88 const tagInstances = await db.Tag.findOrCreateTags(tags, t) 89 const tagInstances = await TagModel.findOrCreateTags(tags, t)
89 await videoInstance.setTags(tagInstances, sequelizeOptions) 90 await videoInstance.$set('Tags', tagInstances, sequelizeOptions)
90 }) 91 })
91 92
92 logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) 93 logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid)
@@ -101,7 +102,7 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd
101 } 102 }
102} 103}
103 104
104async function processUpdateVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { 105async function processUpdateVideoChannel (account: AccountModel, videoChannel: VideoChannelObject) {
105 const options = { 106 const options = {
106 arguments: [ account, videoChannel ], 107 arguments: [ account, videoChannel ],
107 errorMessage: 'Cannot update the remote video channel with many retries.' 108 errorMessage: 'Cannot update the remote video channel with many retries.'
@@ -110,13 +111,13 @@ async function processUpdateVideoChannel (account: AccountInstance, videoChannel
110 await retryTransactionWrapper(updateRemoteVideoChannel, options) 111 await retryTransactionWrapper(updateRemoteVideoChannel, options)
111} 112}
112 113
113async function updateRemoteVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { 114async function updateRemoteVideoChannel (account: AccountModel, videoChannel: VideoChannelObject) {
114 logger.debug('Updating remote video channel "%s".', videoChannel.uuid) 115 logger.debug('Updating remote video channel "%s".', videoChannel.uuid)
115 116
116 await db.sequelize.transaction(async t => { 117 await sequelizeTypescript.transaction(async t => {
117 const sequelizeOptions = { transaction: t } 118 const sequelizeOptions = { transaction: t }
118 119
119 const videoChannelInstance = await db.VideoChannel.loadByUrl(videoChannel.id) 120 const videoChannelInstance = await VideoChannelModel.loadByUrl(videoChannel.id)
120 if (!videoChannelInstance) throw new Error('Video ' + videoChannel.id + ' not found.') 121 if (!videoChannelInstance) throw new Error('Video ' + videoChannel.id + ' not found.')
121 122
122 if (videoChannelInstance.Account.id !== account.id) { 123 if (videoChannelInstance.Account.id !== account.id) {