aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-announce.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/lib/activitypub/process/process-announce.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/lib/activitypub/process/process-announce.ts')
-rw-r--r--server/lib/activitypub/process/process-announce.ts35
1 files changed, 18 insertions, 17 deletions
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 2aa9ad5c7..ff2c6d708 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -1,10 +1,11 @@
1import { ActivityAdd, ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub/activity' 1import { ActivityAdd, ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { logger, retryTransactionWrapper } from '../../../helpers'
3import { logger } from '../../../helpers/logger' 3import { sequelizeTypescript } from '../../../initializers'
4import { database as db } from '../../../initializers/index' 4import { AccountModel } from '../../../models/account/account'
5import { AccountInstance } from '../../../models/account/account-interface' 5import { VideoModel } from '../../../models/video/video'
6import { VideoInstance } from '../../../models/index' 6import { VideoChannelModel } from '../../../models/video/video-channel'
7import { VideoChannelInstance } from '../../../models/video/video-channel-interface' 7import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
8import { VideoShareModel } from '../../../models/video/video-share'
8import { getOrCreateAccountAndServer } from '../account' 9import { getOrCreateAccountAndServer } from '../account'
9import { forwardActivity } from '../send/misc' 10import { forwardActivity } from '../send/misc'
10import { processAddActivity } from './process-add' 11import { processAddActivity } from './process-add'
@@ -36,7 +37,7 @@ export {
36 37
37// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------
38 39
39function processVideoChannelShare (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { 40function processVideoChannelShare (accountAnnouncer: AccountModel, activity: ActivityAnnounce) {
40 const options = { 41 const options = {
41 arguments: [ accountAnnouncer, activity ], 42 arguments: [ accountAnnouncer, activity ],
42 errorMessage: 'Cannot share the video channel with many retries.' 43 errorMessage: 'Cannot share the video channel with many retries.'
@@ -45,18 +46,18 @@ function processVideoChannelShare (accountAnnouncer: AccountInstance, activity:
45 return retryTransactionWrapper(shareVideoChannel, options) 46 return retryTransactionWrapper(shareVideoChannel, options)
46} 47}
47 48
48async function shareVideoChannel (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { 49async function shareVideoChannel (accountAnnouncer: AccountModel, activity: ActivityAnnounce) {
49 const announcedActivity = activity.object as ActivityCreate 50 const announcedActivity = activity.object as ActivityCreate
50 51
51 return db.sequelize.transaction(async t => { 52 return sequelizeTypescript.transaction(async t => {
52 // Add share entry 53 // Add share entry
53 const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity) 54 const videoChannel: VideoChannelModel = await processCreateActivity(announcedActivity)
54 const share = { 55 const share = {
55 accountId: accountAnnouncer.id, 56 accountId: accountAnnouncer.id,
56 videoChannelId: videoChannel.id 57 videoChannelId: videoChannel.id
57 } 58 }
58 59
59 const [ , created ] = await db.VideoChannelShare.findOrCreate({ 60 const [ , created ] = await VideoChannelShareModel.findOrCreate({
60 where: share, 61 where: share,
61 defaults: share, 62 defaults: share,
62 transaction: t 63 transaction: t
@@ -72,7 +73,7 @@ async function shareVideoChannel (accountAnnouncer: AccountInstance, activity: A
72 }) 73 })
73} 74}
74 75
75function processVideoShare (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { 76function processVideoShare (accountAnnouncer: AccountModel, activity: ActivityAnnounce) {
76 const options = { 77 const options = {
77 arguments: [ accountAnnouncer, activity ], 78 arguments: [ accountAnnouncer, activity ],
78 errorMessage: 'Cannot share the video with many retries.' 79 errorMessage: 'Cannot share the video with many retries.'
@@ -81,19 +82,19 @@ function processVideoShare (accountAnnouncer: AccountInstance, activity: Activit
81 return retryTransactionWrapper(shareVideo, options) 82 return retryTransactionWrapper(shareVideo, options)
82} 83}
83 84
84function shareVideo (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { 85function shareVideo (accountAnnouncer: AccountModel, activity: ActivityAnnounce) {
85 const announcedActivity = activity.object as ActivityAdd 86 const announcedActivity = activity.object as ActivityAdd
86 87
87 return db.sequelize.transaction(async t => { 88 return sequelizeTypescript.transaction(async t => {
88 // Add share entry 89 // Add share entry
89 const video: VideoInstance = await processAddActivity(announcedActivity) 90 const video: VideoModel = await processAddActivity(announcedActivity)
90 91
91 const share = { 92 const share = {
92 accountId: accountAnnouncer.id, 93 accountId: accountAnnouncer.id,
93 videoId: video.id 94 videoId: video.id
94 } 95 }
95 96
96 const [ , created ] = await db.VideoShare.findOrCreate({ 97 const [ , created ] = await VideoShareModel.findOrCreate({
97 where: share, 98 where: share,
98 defaults: share, 99 defaults: share,
99 transaction: t 100 transaction: t