]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/channel.ts
Server shares user videos
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / channel.ts
index ab54eedee335947936a9e26abc8d379738c5f70d..8f3df2550341bfdeb85fce870440cfa55e49af1c 100644 (file)
@@ -1,31 +1,23 @@
 import * as express from 'express'
-
+import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared'
+import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers'
 import { database as db } from '../../../initializers'
+import { createVideoChannel } from '../../../lib'
 import {
-  logger,
-  getFormattedObjects,
-  retryTransactionWrapper,
-  resetSequelizeInstance
-} from '../../../helpers'
-import {
+  asyncMiddleware,
   authenticate,
+  listVideoAccountChannelsValidator,
   paginationValidator,
-  videoChannelsSortValidator,
-  videoChannelsAddValidator,
-  setVideoChannelsSort,
   setPagination,
+  setVideoChannelsSort,
+  videoChannelsGetValidator,
+  videoChannelsAddValidator,
   videoChannelsRemoveValidator,
-  videoChannelGetValidator,
-  videoChannelsUpdateValidator,
-  listVideoAuthorChannelsValidator,
-  asyncMiddleware
+  videoChannelsSortValidator,
+  videoChannelsUpdateValidator
 } from '../../../middlewares'
-import {
-  createVideoChannel,
-  updateVideoChannelToFriends
-} from '../../../lib'
-import { VideoChannelInstance, AuthorInstance } from '../../../models'
-import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared'
+import { AccountInstance, VideoChannelInstance } from '../../../models'
+import { sendUpdateVideoChannel } from '../../../lib/activitypub/send-request'
 
 const videoChannelRouter = express.Router()
 
@@ -37,9 +29,9 @@ videoChannelRouter.get('/channels',
   asyncMiddleware(listVideoChannels)
 )
 
-videoChannelRouter.get('/authors/:authorId/channels',
-  listVideoAuthorChannelsValidator,
-  asyncMiddleware(listVideoAuthorChannels)
+videoChannelRouter.get('/accounts/:accountId/channels',
+  listVideoAccountChannelsValidator,
+  asyncMiddleware(listVideoAccountChannels)
 )
 
 videoChannelRouter.post('/channels',
@@ -61,7 +53,7 @@ videoChannelRouter.delete('/channels/:id',
 )
 
 videoChannelRouter.get('/channels/:id',
-  videoChannelGetValidator,
+  videoChannelsGetValidator,
   asyncMiddleware(getVideoChannel)
 )
 
@@ -79,8 +71,8 @@ async function listVideoChannels (req: express.Request, res: express.Response, n
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
 
-async function listVideoAuthorChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const resultList = await db.VideoChannel.listByAuthor(res.locals.author.id)
+async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const resultList = await db.VideoChannel.listByAccount(res.locals.account.id)
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
@@ -101,11 +93,11 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R
 
 async function addVideoChannel (req: express.Request, res: express.Response) {
   const videoChannelInfo: VideoChannelCreate = req.body
-  const author: AuthorInstance = res.locals.oauth.token.User.Author
+  const account: AccountInstance = res.locals.oauth.token.User.Account
   let videoChannelCreated: VideoChannelInstance
 
   await db.sequelize.transaction(async t => {
-    videoChannelCreated = await createVideoChannel(videoChannelInfo, author, t)
+    videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t)
   })
 
   logger.info('Video channel with uuid %s created.', videoChannelCreated.uuid)
@@ -137,11 +129,8 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
       if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
 
       await videoChannelInstance.save(sequelizeOptions)
-      const json = videoChannelInstance.toUpdateRemoteJSON()
-
-      // Now we'll update the video channel's meta data to our friends
-      return updateVideoChannelToFriends(json, t)
 
+      await sendUpdateVideoChannel(videoChannelInstance, t)
     })
 
     logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid)
@@ -179,7 +168,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
 }
 
 async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const videoChannelWithVideos = await db.VideoChannel.loadAndPopulateAuthorAndVideos(res.locals.videoChannel.id)
+  const videoChannelWithVideos = await db.VideoChannel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)
 
   return res.json(videoChannelWithVideos.toFormattedJSON())
 }