diff options
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 39 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' | 2 | import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' |
3 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { sequelizeTypescript } from '../../../initializers' |
6 | import { resetSequelizeInstance } from '../../../helpers/utils' | 6 | import { AccountModel } from '../../../models/account/account' |
7 | import { database as db } from '../../../initializers' | 7 | import { TagModel } from '../../../models/video/tag' |
8 | import { AccountInstance } from '../../../models/account/account-interface' | 8 | import { VideoModel } from '../../../models/video/video' |
9 | import { VideoInstance } from '../../../models/video/video-interface' | 9 | import { VideoChannelModel } from '../../../models/video/video-channel' |
10 | import { VideoFileModel } from '../../../models/video/video-file' | ||
10 | import { getOrCreateAccountAndServer } from '../account' | 11 | import { getOrCreateAccountAndServer } from '../account' |
11 | import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | 12 | import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' |
12 | 13 | ||
@@ -30,7 +31,7 @@ export { | |||
30 | 31 | ||
31 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
32 | 33 | ||
33 | function processUpdateVideo (account: AccountInstance, video: VideoTorrentObject) { | 34 | function 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 | ||
42 | async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpdate: VideoTorrentObject) { | 43 | async 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 | ||
104 | async function processUpdateVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { | 105 | async 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 | ||
113 | async function updateRemoteVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { | 114 | async 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) { |