aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/channel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/channel.ts')
-rw-r--r--server/controllers/api/videos/channel.ts27
1 files changed, 14 insertions, 13 deletions
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts
index d99f47c32..683b0448d 100644
--- a/server/controllers/api/videos/channel.ts
+++ b/server/controllers/api/videos/channel.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' 2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared'
3import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' 3import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers'
4import { database as db } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
5import { createVideoChannel } from '../../../lib' 5import { createVideoChannel } from '../../../lib'
6import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' 6import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update'
7import { 7import {
@@ -17,7 +17,8 @@ import {
17 videoChannelsSortValidator, 17 videoChannelsSortValidator,
18 videoChannelsUpdateValidator 18 videoChannelsUpdateValidator
19} from '../../../middlewares' 19} from '../../../middlewares'
20import { AccountInstance, VideoChannelInstance } from '../../../models' 20import { AccountModel } from '../../../models/account/account'
21import { VideoChannelModel } from '../../../models/video/video-channel'
21 22
22const videoChannelRouter = express.Router() 23const videoChannelRouter = express.Router()
23 24
@@ -66,13 +67,13 @@ export {
66// --------------------------------------------------------------------------- 67// ---------------------------------------------------------------------------
67 68
68async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) { 69async function listVideoChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
69 const resultList = await db.VideoChannel.listForApi(req.query.start, req.query.count, req.query.sort) 70 const resultList = await VideoChannelModel.listForApi(req.query.start, req.query.count, req.query.sort)
70 71
71 return res.json(getFormattedObjects(resultList.data, resultList.total)) 72 return res.json(getFormattedObjects(resultList.data, resultList.total))
72} 73}
73 74
74async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) { 75async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
75 const resultList = await db.VideoChannel.listByAccount(res.locals.account.id) 76 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
76 77
77 return res.json(getFormattedObjects(resultList.data, resultList.total)) 78 return res.json(getFormattedObjects(resultList.data, resultList.total))
78} 79}
@@ -93,10 +94,10 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R
93 94
94async function addVideoChannel (req: express.Request, res: express.Response) { 95async function addVideoChannel (req: express.Request, res: express.Response) {
95 const videoChannelInfo: VideoChannelCreate = req.body 96 const videoChannelInfo: VideoChannelCreate = req.body
96 const account: AccountInstance = res.locals.oauth.token.User.Account 97 const account: AccountModel = res.locals.oauth.token.User.Account
97 let videoChannelCreated: VideoChannelInstance 98 let videoChannelCreated: VideoChannelModel
98 99
99 await db.sequelize.transaction(async t => { 100 await sequelizeTypescript.transaction(async t => {
100 videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) 101 videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t)
101 }) 102 })
102 103
@@ -115,12 +116,12 @@ async function updateVideoChannelRetryWrapper (req: express.Request, res: expres
115} 116}
116 117
117async function updateVideoChannel (req: express.Request, res: express.Response) { 118async function updateVideoChannel (req: express.Request, res: express.Response) {
118 const videoChannelInstance: VideoChannelInstance = res.locals.videoChannel 119 const videoChannelInstance = res.locals.videoChannel as VideoChannelModel
119 const videoChannelFieldsSave = videoChannelInstance.toJSON() 120 const videoChannelFieldsSave = videoChannelInstance.toJSON()
120 const videoChannelInfoToUpdate: VideoChannelUpdate = req.body 121 const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
121 122
122 try { 123 try {
123 await db.sequelize.transaction(async t => { 124 await sequelizeTypescript.transaction(async t => {
124 const sequelizeOptions = { 125 const sequelizeOptions = {
125 transaction: t 126 transaction: t
126 } 127 }
@@ -158,9 +159,9 @@ async function removeVideoChannelRetryWrapper (req: express.Request, res: expres
158} 159}
159 160
160async function removeVideoChannel (req: express.Request, res: express.Response) { 161async function removeVideoChannel (req: express.Request, res: express.Response) {
161 const videoChannelInstance: VideoChannelInstance = res.locals.videoChannel 162 const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
162 163
163 await db.sequelize.transaction(async t => { 164 await sequelizeTypescript.transaction(async t => {
164 await videoChannelInstance.destroy({ transaction: t }) 165 await videoChannelInstance.destroy({ transaction: t })
165 }) 166 })
166 167
@@ -168,7 +169,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
168} 169}
169 170
170async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { 171async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {
171 const videoChannelWithVideos = await db.VideoChannel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id) 172 const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)
172 173
173 return res.json(videoChannelWithVideos.toFormattedJSON()) 174 return res.json(videoChannelWithVideos.toFormattedJSON())
174} 175}