aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/ownership.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-20 10:13:13 +0200
committerChocobozzz <me@florianbigard.com>2018-09-20 11:45:59 +0200
commit91411dba928678c15a5e99d9795ae061909e397d (patch)
tree7ba6e340cc9eb6f993051fcac74eefd652cb0ffd /server/controllers/api/videos/ownership.ts
parentfcc7c060374c3a547257d96af847352c14d6144b (diff)
downloadPeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.gz
PeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.zst
PeerTube-91411dba928678c15a5e99d9795ae061909e397d.zip
Limit associations fetch when loading token
Diffstat (limited to 'server/controllers/api/videos/ownership.ts')
-rw-r--r--server/controllers/api/videos/ownership.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index d26ed6cfc..5ea7d7c6a 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -19,6 +19,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
19import { getFormattedObjects } from '../../../helpers/utils' 19import { getFormattedObjects } from '../../../helpers/utils'
20import { changeVideoChannelShare } from '../../../lib/activitypub' 20import { changeVideoChannelShare } from '../../../lib/activitypub'
21import { sendUpdateVideo } from '../../../lib/activitypub/send' 21import { sendUpdateVideo } from '../../../lib/activitypub/send'
22import { UserModel } from '../../../models/account/user'
22 23
23const ownershipVideoRouter = express.Router() 24const ownershipVideoRouter = express.Router()
24 25
@@ -58,26 +59,25 @@ export {
58 59
59async function giveVideoOwnership (req: express.Request, res: express.Response) { 60async function giveVideoOwnership (req: express.Request, res: express.Response) {
60 const videoInstance = res.locals.video as VideoModel 61 const videoInstance = res.locals.video as VideoModel
61 const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel 62 const initiatorAccountId = (res.locals.oauth.token.User as UserModel).Account.id
62 const nextOwner = res.locals.nextOwner as AccountModel 63 const nextOwner = res.locals.nextOwner as AccountModel
63 64
64 await sequelizeTypescript.transaction(t => { 65 await sequelizeTypescript.transaction(t => {
65 return VideoChangeOwnershipModel.findOrCreate({ 66 return VideoChangeOwnershipModel.findOrCreate({
66 where: { 67 where: {
67 initiatorAccountId: initiatorAccount.id, 68 initiatorAccountId,
68 nextOwnerAccountId: nextOwner.id, 69 nextOwnerAccountId: nextOwner.id,
69 videoId: videoInstance.id, 70 videoId: videoInstance.id,
70 status: VideoChangeOwnershipStatus.WAITING 71 status: VideoChangeOwnershipStatus.WAITING
71 }, 72 },
72 defaults: { 73 defaults: {
73 initiatorAccountId: initiatorAccount.id, 74 initiatorAccountId,
74 nextOwnerAccountId: nextOwner.id, 75 nextOwnerAccountId: nextOwner.id,
75 videoId: videoInstance.id, 76 videoId: videoInstance.id,
76 status: VideoChangeOwnershipStatus.WAITING 77 status: VideoChangeOwnershipStatus.WAITING
77 }, 78 },
78 transaction: t 79 transaction: t
79 }) 80 })
80
81 }) 81 })
82 82
83 logger.info('Ownership change for video %s created.', videoInstance.name) 83 logger.info('Ownership change for video %s created.', videoInstance.name)
@@ -85,9 +85,10 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
85} 85}
86 86
87async function listVideoOwnership (req: express.Request, res: express.Response) { 87async function listVideoOwnership (req: express.Request, res: express.Response) {
88 const currentAccount = res.locals.oauth.token.User.Account as AccountModel 88 const currentAccountId = (res.locals.oauth.token.User as UserModel).Account.id
89
89 const resultList = await VideoChangeOwnershipModel.listForApi( 90 const resultList = await VideoChangeOwnershipModel.listForApi(
90 currentAccount.id, 91 currentAccountId,
91 req.query.start || 0, 92 req.query.start || 0,
92 req.query.count || 10, 93 req.query.count || 10,
93 req.query.sort || 'createdAt' 94 req.query.sort || 'createdAt'