1
0
Fork 0

Update video-channel routes (again)

Use /video-channels now, it's more simple for clients
This commit is contained in:
Chocobozzz 2018-04-25 16:15:39 +02:00
parent d3e91a5f72
commit cc918ac3f4
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 852 additions and 1103 deletions

View File

@ -6,7 +6,7 @@
* Hide by default NSFW videos. Update the `instance.default_nsfw_policy` configuration to `blur` to keep the old behaviour
* Move video channels routes:
* `/videos/channels` routes to `/accounts/{accountId}/video-channels`
* `/videos/channels` routes to `/video-channels`
* `/videos/accounts/{accountId}/channels` route to `/accounts/{accountId}/video-channels`
* PeerTube now listen on 127.0.0.1 by default
* Use ISO 639 for language (*en*, *es*, *fr*...)

View File

@ -1,30 +1,18 @@
import * as express from 'express'
import { getFormattedObjects, resetSequelizeInstance } from '../../helpers/utils'
import { getFormattedObjects } from '../../helpers/utils'
import {
asyncMiddleware,
authenticate,
listVideoAccountChannelsValidator,
optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort,
videoChannelsAddValidator,
videoChannelsGetValidator,
videoChannelsRemoveValidator,
videoChannelsUpdateValidator
setDefaultSort
} from '../../middlewares'
import { accountsGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
import { isNSFWHidden } from '../../helpers/express-utils'
import { VideoChannelModel } from '../../models/video/video-channel'
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
import { sendUpdateActor } from '../../lib/activitypub/send'
import { createVideoChannel } from '../../lib/video-channel'
import { setAsyncActorKeys } from '../../lib/activitypub'
import { sequelizeTypescript } from '../../initializers'
import { logger } from '../../helpers/logger'
import { retryTransactionWrapper } from '../../helpers/database-utils'
const accountsRouter = express.Router()
@ -56,39 +44,6 @@ accountsRouter.get('/:accountId/video-channels',
asyncMiddleware(listVideoAccountChannels)
)
accountsRouter.post('/:accountId/video-channels',
authenticate,
videoChannelsAddValidator,
asyncMiddleware(addVideoChannelRetryWrapper)
)
accountsRouter.put('/:accountId/video-channels/:id',
authenticate,
asyncMiddleware(videoChannelsUpdateValidator),
updateVideoChannelRetryWrapper
)
accountsRouter.delete('/:accountId/video-channels/:id',
authenticate,
asyncMiddleware(videoChannelsRemoveValidator),
asyncMiddleware(removeVideoChannelRetryWrapper)
)
accountsRouter.get('/:accountId/video-channels/:id',
asyncMiddleware(videoChannelsGetValidator),
asyncMiddleware(getVideoChannel)
)
accountsRouter.get('/:accountId/video-channels/:id/videos',
asyncMiddleware(videoChannelsGetValidator),
paginationValidator,
videosSortValidator,
setDefaultSort,
setDefaultPagination,
optionalAuthenticate,
asyncMiddleware(listVideoChannelVideos)
)
// ---------------------------------------------------------------------------
export {
@ -115,125 +70,6 @@ async function listVideoAccountChannels (req: express.Request, res: express.Resp
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
// Wrapper to video channel add that retry the async function if there is a database error
// We need this because we run the transaction in SERIALIZABLE isolation that can fail
async function addVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot insert the video video channel with many retries.'
}
const videoChannel = await retryTransactionWrapper(addVideoChannel, options)
return res.json({
videoChannel: {
id: videoChannel.id,
uuid: videoChannel.Actor.uuid
}
}).end()
}
async function addVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInfo: VideoChannelCreate = req.body
const account: AccountModel = res.locals.oauth.token.User.Account
const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {
return createVideoChannel(videoChannelInfo, account, t)
})
setAsyncActorKeys(videoChannelCreated.Actor)
.catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err }))
logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
return videoChannelCreated
}
async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot update the video with many retries.'
}
await retryTransactionWrapper(updateVideoChannel, options)
return res.type('json').status(204).end()
}
async function updateVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInstance = res.locals.videoChannel as VideoChannelModel
const videoChannelFieldsSave = videoChannelInstance.toJSON()
const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
try {
await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = {
transaction: t
}
if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name)
if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support)
const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions)
await sendUpdateActor(videoChannelInstanceUpdated, t)
})
logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
} catch (err) {
logger.debug('Cannot update the video channel.', { err })
// Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
// So it will skip the SQL request, even if the last one was ROLLBACKed!
resetSequelizeInstance(videoChannelInstance, videoChannelFieldsSave)
throw err
}
}
async function removeVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot remove the video channel with many retries.'
}
await retryTransactionWrapper(removeVideoChannel, options)
return res.type('json').status(204).end()
}
async function removeVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
return sequelizeTypescript.transaction(async t => {
await videoChannelInstance.destroy({ transaction: t })
logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
})
}
async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {
const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)
return res.json(videoChannelWithVideos.toFormattedJSON())
}
async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
const resultList = await VideoModel.listForApi({
start: req.query.start,
count: req.query.count,
sort: req.query.sort,
hideNSFW: isNSFWHidden(res),
withFiles: false,
videoChannelId: videoChannelInstance.id
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
const account: AccountModel = res.locals.account

View File

@ -1,13 +1,30 @@
import * as express from 'express'
import { getFormattedObjects } from '../../helpers/utils'
import { getFormattedObjects, resetSequelizeInstance } from '../../helpers/utils'
import {
asyncMiddleware,
authenticate,
optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort,
videoChannelsSortValidator
videoChannelsAddValidator,
videoChannelsGetValidator,
videoChannelsRemoveValidator,
videoChannelsSortValidator,
videoChannelsUpdateValidator
} from '../../middlewares'
import { VideoChannelModel } from '../../models/video/video-channel'
import { videosSortValidator } from '../../middlewares/validators'
import { sendUpdateActor } from '../../lib/activitypub/send'
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
import { createVideoChannel } from '../../lib/video-channel'
import { isNSFWHidden } from '../../helpers/express-utils'
import { setAsyncActorKeys } from '../../lib/activitypub'
import { retryTransactionWrapper } from '../../helpers/database-utils'
import { AccountModel } from '../../models/account/account'
import { sequelizeTypescript } from '../../initializers'
import { logger } from '../../helpers/logger'
import { VideoModel } from '../../models/video/video'
const videoChannelRouter = express.Router()
@ -19,6 +36,39 @@ videoChannelRouter.get('/',
asyncMiddleware(listVideoChannels)
)
videoChannelRouter.post('/',
authenticate,
videoChannelsAddValidator,
asyncMiddleware(addVideoChannelRetryWrapper)
)
videoChannelRouter.put('/:id',
authenticate,
asyncMiddleware(videoChannelsUpdateValidator),
updateVideoChannelRetryWrapper
)
videoChannelRouter.delete('/:id',
authenticate,
asyncMiddleware(videoChannelsRemoveValidator),
asyncMiddleware(removeVideoChannelRetryWrapper)
)
videoChannelRouter.get('/:id',
asyncMiddleware(videoChannelsGetValidator),
asyncMiddleware(getVideoChannel)
)
videoChannelRouter.get('/:id/videos',
asyncMiddleware(videoChannelsGetValidator),
paginationValidator,
videosSortValidator,
setDefaultSort,
setDefaultPagination,
optionalAuthenticate,
asyncMiddleware(listVideoChannelVideos)
)
// ---------------------------------------------------------------------------
export {
@ -32,3 +82,122 @@ async function listVideoChannels (req: express.Request, res: express.Response, n
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
// Wrapper to video channel add that retry the async function if there is a database error
// We need this because we run the transaction in SERIALIZABLE isolation that can fail
async function addVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot insert the video video channel with many retries.'
}
const videoChannel = await retryTransactionWrapper(addVideoChannel, options)
return res.json({
videoChannel: {
id: videoChannel.id,
uuid: videoChannel.Actor.uuid
}
}).end()
}
async function addVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInfo: VideoChannelCreate = req.body
const account: AccountModel = res.locals.oauth.token.User.Account
const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {
return createVideoChannel(videoChannelInfo, account, t)
})
setAsyncActorKeys(videoChannelCreated.Actor)
.catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err }))
logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
return videoChannelCreated
}
async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot update the video with many retries.'
}
await retryTransactionWrapper(updateVideoChannel, options)
return res.type('json').status(204).end()
}
async function updateVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInstance = res.locals.videoChannel as VideoChannelModel
const videoChannelFieldsSave = videoChannelInstance.toJSON()
const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
try {
await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = {
transaction: t
}
if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name)
if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support)
const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions)
await sendUpdateActor(videoChannelInstanceUpdated, t)
})
logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
} catch (err) {
logger.debug('Cannot update the video channel.', { err })
// Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
// So it will skip the SQL request, even if the last one was ROLLBACKed!
resetSequelizeInstance(videoChannelInstance, videoChannelFieldsSave)
throw err
}
}
async function removeVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
errorMessage: 'Cannot remove the video channel with many retries.'
}
await retryTransactionWrapper(removeVideoChannel, options)
return res.type('json').status(204).end()
}
async function removeVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
return sequelizeTypescript.transaction(async t => {
await videoChannelInstance.destroy({ transaction: t })
logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
})
}
async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) {
const videoChannelWithVideos = await VideoChannelModel.loadAndPopulateAccountAndVideos(res.locals.videoChannel.id)
return res.json(videoChannelWithVideos.toFormattedJSON())
}
async function listVideoChannelVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
const resultList = await VideoModel.listForApi({
start: req.query.start,
count: req.query.count,
sort: req.query.sort,
hideNSFW: isNSFWHidden(res),
withFiles: false,
videoChannelId: videoChannelInstance.id
})
return res.json(getFormattedObjects(resultList.data, resultList.total))
}

View File

@ -27,7 +27,6 @@ const listVideoAccountChannelsValidator = [
]
const videoChannelsAddValidator = [
param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
body('name').custom(isVideoChannelNameValid).withMessage('Should have a valid name'),
body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@ -43,7 +42,6 @@ const videoChannelsAddValidator = [
const videoChannelsUpdateValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
body('name').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid name'),
body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@ -52,9 +50,7 @@ const videoChannelsUpdateValidator = [
logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body })
if (areValidationErrors(req, res)) return
if (!await isAccountIdExist(req.params.accountId, res)) return
if (!await isVideoChannelExist(req.params.id, res)) return
if (!checkAccountOwnsVideoChannel(res.locals.account, res.locals.videoChannel, res)) return
// We need to make additional checks
if (res.locals.videoChannel.Actor.isOwned() === false) {
@ -75,17 +71,13 @@ const videoChannelsUpdateValidator = [
const videoChannelsRemoveValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
if (!await isAccountIdExist(req.params.accountId, res)) return
if (!await isVideoChannelExist(req.params.id, res)) return
if (!checkAccountOwnsVideoChannel(res.locals.account, res.locals.videoChannel, res)) return
// Check if the user who did the request is able to delete the video
if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return
if (!await checkVideoChannelIsNotTheLastOne(res)) return
@ -95,19 +87,14 @@ const videoChannelsRemoveValidator = [
const videoChannelsGetValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
param('accountId').optional().custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelsGet parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
// On some routes, accountId is optional (for example in the ActivityPub route)
if (req.params.accountId && !await isAccountIdExist(req.params.accountId, res)) return
if (!await isVideoChannelExist(req.params.id, res)) return
if (res.locals.account && !checkAccountOwnsVideoChannel(res.locals.account, res.locals.videoChannel, res)) return
return next()
}
]
@ -160,15 +147,3 @@ async function checkVideoChannelIsNotTheLastOne (res: express.Response) {
return true
}
function checkAccountOwnsVideoChannel (account: AccountModel, videoChannel: VideoChannelModel, res: express.Response) {
if (videoChannel.Account.id !== account.id) {
res.status(400)
.json({ error: 'This account does not own this video channel' })
.end()
return false
}
return true
}

View File

@ -27,10 +27,8 @@ const expect = chai.expect
describe('Test videos API validator', function () {
const videoChannelPath = '/api/v1/video-channels'
const accountPath = '/api/v1/accounts/'
let server: ServerInfo
let accessTokenUser: string
let accountUUID: string
let videoChannelUUID: string
// ---------------------------------------------------------------
@ -57,7 +55,6 @@ describe('Test videos API validator', function () {
{
const res = await getMyUserInformation(server.url, server.accessToken)
const user: User = res.body
accountUUID = user.account.uuid
videoChannelUUID = user.videoChannels[0].uuid
}
})
@ -92,45 +89,46 @@ describe('Test videos API validator', function () {
description: 'super description',
support: 'super support text'
}
let path: string
before(async function () {
path = accountPath + accountUUID + '/video-channels'
})
it('Should fail with a non authenticated user', async function () {
await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
await makePostBodyRequest({
url: server.url,
path: videoChannelPath,
token: 'none',
fields: baseCorrectParams,
statusCodeExpected: 401
})
})
it('Should fail with nothing', async function () {
const fields = {}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
})
it('Should fail without name', async function () {
const fields = omit(baseCorrectParams, 'name')
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
})
it('Should fail with a long name', async function () {
const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
})
it('Should fail with a long description', async function () {
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
})
it('Should fail with a long support text', async function () {
const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
})
it('Should succeed with the correct parameters', async function () {
await makePostBodyRequest({
url: server.url,
path,
path: videoChannelPath,
token: server.accessToken,
fields: baseCorrectParams,
statusCodeExpected: 200
@ -146,7 +144,7 @@ describe('Test videos API validator', function () {
let path: string
before(async function () {
path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID
path = videoChannelPath + '/' + videoChannelUUID
})
it('Should fail with a non authenticated user', async function () {
@ -196,16 +194,10 @@ describe('Test videos API validator', function () {
})
describe('When getting a video channel', function () {
let basePath: string
before(async function () {
basePath = accountPath + accountUUID + '/video-channels'
})
it('Should return the list of the video channels with nothing', async function () {
const res = await makeGetRequest({
url: server.url,
path: basePath,
path: videoChannelPath,
statusCodeExpected: 200
})
@ -215,7 +207,7 @@ describe('Test videos API validator', function () {
it('Should fail without a correct uuid', async function () {
await makeGetRequest({
url: server.url,
path: basePath + '/coucou',
path: videoChannelPath + '/coucou',
statusCodeExpected: 400
})
})
@ -223,7 +215,7 @@ describe('Test videos API validator', function () {
it('Should return 404 with an incorrect video channel', async function () {
await makeGetRequest({
url: server.url,
path: basePath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
statusCodeExpected: 404
})
})
@ -231,7 +223,7 @@ describe('Test videos API validator', function () {
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({
url: server.url,
path: basePath + '/' + videoChannelUUID,
path: videoChannelPath + '/' + videoChannelUUID,
statusCodeExpected: 200
})
})
@ -239,30 +231,26 @@ describe('Test videos API validator', function () {
describe('When deleting a video channel', function () {
it('Should fail with a non authenticated user', async function () {
await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401)
await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
})
it('Should fail with another authenticated user', async function () {
await deleteVideoChannel(server.url, accessTokenUser, accountUUID, videoChannelUUID, 403)
})
it('Should fail with an unknown account id', async function () {
await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelUUID, 404)
await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
})
it('Should fail with an unknown video channel id', async function () {
await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404)
await deleteVideoChannel(server.url, server.accessToken,454554, 404)
})
it('Should succeed with the correct parameters', async function () {
await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID)
await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
})
it('Should fail to delete the last user video channel', async function () {
const res = await getVideoChannelsList(server.url, 0, 1)
const lastVideoChannelUUID = res.body.data[0].uuid
await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409)
await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
})
})

View File

@ -63,7 +63,7 @@ describe('Test video channels', function () {
description: 'super video channel description',
support: 'super video channel support text'
}
const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannel)
const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
videoChannelId = res.body.videoChannel.id
videoChannelUUID = res.body.videoChannel.uuid
@ -130,7 +130,7 @@ describe('Test video channels', function () {
support: 'video channel support text updated'
}
await updateVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId, videoChannelAttributes)
await updateVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId, videoChannelAttributes)
await wait(3000)
})
@ -149,7 +149,7 @@ describe('Test video channels', function () {
})
it('Should get video channel', async function () {
const res = await getVideoChannel(servers[0].url, accountUUID, videoChannelId)
const res = await getVideoChannel(servers[0].url, videoChannelId)
const videoChannel = res.body
expect(videoChannel.displayName).to.equal('video channel updated')
@ -161,7 +161,7 @@ describe('Test video channels', function () {
this.timeout(10000)
for (const server of servers) {
const res = await getVideoChannelVideos(server.url, server.accessToken, accountUUID, videoChannelUUID, 0, 5)
const res = await getVideoChannelVideos(server.url, server.accessToken, videoChannelUUID, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1)
@ -170,7 +170,7 @@ describe('Test video channels', function () {
})
it('Should delete video channel', async function () {
await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId)
await deleteVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId)
})
it('Should have video channel deleted', async function () {

View File

@ -39,7 +39,7 @@ describe('Test video NSFW policy', function () {
getVideosListWithToken(server.url, token),
searchVideoWithToken(server.url, 'n', token),
getAccountVideos(server.url, token, accountUUID, 0, 5),
getVideoChannelVideos(server.url, token, accountUUID, videoChannelUUID, 0, 5)
getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5)
])
}
@ -47,7 +47,7 @@ describe('Test video NSFW policy', function () {
getVideosList(server.url),
searchVideo(server.url, 'n'),
getAccountVideos(server.url, undefined, accountUUID, 0, 5),
getVideoChannelVideos(server.url, undefined, accountUUID, videoChannelUUID, 0, 5)
getVideoChannelVideos(server.url, undefined, videoChannelUUID, 0, 5)
])
})
}

View File

@ -34,11 +34,10 @@ function getAccountVideoChannelsList (url: string, accountId: number | string, s
function addVideoChannel (
url: string,
token: string,
accountId: number | string,
videoChannelAttributesArg: VideoChannelAttributes,
expectedStatus = 200
) {
const path = '/api/v1/accounts/' + accountId + '/video-channels/'
const path = '/api/v1/video-channels/'
// Default attributes
let attributes = {
@ -59,13 +58,12 @@ function addVideoChannel (
function updateVideoChannel (
url: string,
token: string,
accountId: number | string,
channelId: number | string,
attributes: VideoChannelAttributes,
expectedStatus = 204
) {
const body = {}
const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
const path = '/api/v1/video-channels/' + channelId
if (attributes.name) body['name'] = attributes.name
if (attributes.description) body['description'] = attributes.description
@ -79,8 +77,8 @@ function updateVideoChannel (
.expect(expectedStatus)
}
function deleteVideoChannel (url: string, token: string, accountId: number | string, channelId: number | string, expectedStatus = 204) {
const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
function deleteVideoChannel (url: string, token: string, channelId: number | string, expectedStatus = 204) {
const path = '/api/v1/video-channels/' + channelId
return request(url)
.delete(path)
@ -89,8 +87,8 @@ function deleteVideoChannel (url: string, token: string, accountId: number | str
.expect(expectedStatus)
}
function getVideoChannel (url: string, accountId: number | string, channelId: number | string) {
const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
function getVideoChannel (url: string, channelId: number | string) {
const path = '/api/v1/video-channels/' + channelId
return request(url)
.get(path)

View File

@ -186,13 +186,12 @@ function getAccountVideos (url: string, accessToken: string, accountId: number |
function getVideoChannelVideos (
url: string,
accessToken: string,
accountId: number | string,
videoChannelId: number | string,
start: number,
count: number,
sort?: string
) {
const path = '/api/v1/accounts/' + accountId + '/video-channels/' + videoChannelId + '/videos'
const path = '/api/v1/video-channels/' + videoChannelId + '/videos'
return makeGetRequest({
url,

File diff suppressed because it is too large Load Diff

View File

@ -1017,27 +1017,6 @@ paths:
type: array
items:
$ref: '#/definitions/VideoChannel'
/accounts/{accountId}/video-channels:
get:
tags:
- VideoChannel
consumes:
- application/json
produces:
- application/json
parameters:
- name: accountId
in: path
required: true
type: string
description: 'The account id '
responses:
'200':
description: successful operation
schema:
type: array
items:
$ref: '#/definitions/VideoChannel'
post:
security:
- OAuth2: [ ]
@ -1048,11 +1027,6 @@ paths:
produces:
- application/json
parameters:
- name: accountId
in: path
required: true
type: string
description: 'The account id '
- in: body
name: body
schema:
@ -1060,7 +1034,7 @@ paths:
responses:
'204':
description: successful operation
"/account/{accountId}/video-channels/{id}":
"/video-channels/{id}":
get:
tags:
- VideoChannel
@ -1069,11 +1043,6 @@ paths:
produces:
- application/json
parameters:
- name: accountId
in: path
required: true
type: string
description: 'The account id '
- name: id
in: path
required: true
@ -1094,11 +1063,6 @@ paths:
produces:
- application/json
parameters:
- name: accountId
in: path
required: true
type: string
description: 'The account id '
- name: id
in: path
required: true
@ -1121,11 +1085,6 @@ paths:
produces:
- application/json
parameters:
- name: accountId
in: path
required: true
type: string
description: 'The account id '
- name: id
in: path
required: true
@ -1134,7 +1093,26 @@ paths:
responses:
'204':
description: successful operation
"/account/{accountId}/video-channels/{id}/videos":
"/video-channels/{id}/videos":
get:
tags:
- VideoChannel
consumes:
- application/json
produces:
- application/json
parameters:
- name: id
in: path
required: true
type: string
description: 'The video channel id '
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Video'
/accounts/{accountId}/video-channels:
get:
tags:
- VideoChannel
@ -1148,16 +1126,13 @@ paths:
required: true
type: string
description: 'The account id '
- name: id
in: path
required: true
type: string
description: 'The video channel id '
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Video'
type: array
items:
$ref: '#/definitions/VideoChannel'
"/videos/{videoId}/comment-threads":
get:
tags: