mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Limit max live sessions
This commit is contained in:
parent
9b05a4b49e
commit
a6f2e92c35
2 changed files with 18 additions and 25 deletions
|
@ -1,12 +1,5 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import {
|
import { HttpStatusCode, LiveVideoCreate, LiveVideoUpdate, ThumbnailType, UserRight, VideoState } from '@peertube/peertube-models'
|
||||||
HttpStatusCode,
|
|
||||||
LiveVideoCreate,
|
|
||||||
LiveVideoUpdate,
|
|
||||||
ThumbnailType,
|
|
||||||
UserRight,
|
|
||||||
VideoState
|
|
||||||
} from '@peertube/peertube-models'
|
|
||||||
import { exists } from '@server/helpers/custom-validators/misc.js'
|
import { exists } from '@server/helpers/custom-validators/misc.js'
|
||||||
import { createReqFiles } from '@server/helpers/express-utils.js'
|
import { createReqFiles } from '@server/helpers/express-utils.js'
|
||||||
import { getFormattedObjects } from '@server/helpers/utils.js'
|
import { getFormattedObjects } from '@server/helpers/utils.js'
|
||||||
|
@ -35,37 +28,33 @@ const liveRouter = express.Router()
|
||||||
|
|
||||||
const reqVideoFileLive = createReqFiles([ 'thumbnailfile', 'previewfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
|
const reqVideoFileLive = createReqFiles([ 'thumbnailfile', 'previewfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
|
||||||
|
|
||||||
liveRouter.post('/live',
|
liveRouter.post(
|
||||||
|
'/live',
|
||||||
authenticate,
|
authenticate,
|
||||||
reqVideoFileLive,
|
reqVideoFileLive,
|
||||||
asyncMiddleware(videoLiveAddValidator),
|
asyncMiddleware(videoLiveAddValidator),
|
||||||
asyncRetryTransactionMiddleware(addLiveVideo)
|
asyncRetryTransactionMiddleware(addLiveVideo)
|
||||||
)
|
)
|
||||||
|
|
||||||
liveRouter.get('/live/:videoId/sessions',
|
liveRouter.get(
|
||||||
|
'/live/:videoId/sessions',
|
||||||
authenticate,
|
authenticate,
|
||||||
asyncMiddleware(videoLiveGetValidator),
|
asyncMiddleware(videoLiveGetValidator),
|
||||||
videoLiveListSessionsValidator,
|
videoLiveListSessionsValidator,
|
||||||
asyncMiddleware(getLiveVideoSessions)
|
asyncMiddleware(getLiveVideoSessions)
|
||||||
)
|
)
|
||||||
|
|
||||||
liveRouter.get('/live/:videoId',
|
liveRouter.get('/live/:videoId', optionalAuthenticate, asyncMiddleware(videoLiveGetValidator), getLiveVideo)
|
||||||
optionalAuthenticate,
|
|
||||||
asyncMiddleware(videoLiveGetValidator),
|
|
||||||
getLiveVideo
|
|
||||||
)
|
|
||||||
|
|
||||||
liveRouter.put('/live/:videoId',
|
liveRouter.put(
|
||||||
|
'/live/:videoId',
|
||||||
authenticate,
|
authenticate,
|
||||||
asyncMiddleware(videoLiveGetValidator),
|
asyncMiddleware(videoLiveGetValidator),
|
||||||
videoLiveUpdateValidator,
|
videoLiveUpdateValidator,
|
||||||
asyncRetryTransactionMiddleware(updateLiveVideo)
|
asyncRetryTransactionMiddleware(updateLiveVideo)
|
||||||
)
|
)
|
||||||
|
|
||||||
liveRouter.get('/:videoId/live-session',
|
liveRouter.get('/:videoId/live-session', asyncMiddleware(videoLiveFindReplaySessionValidator), getLiveReplaySession)
|
||||||
asyncMiddleware(videoLiveFindReplaySessionValidator),
|
|
||||||
getLiveReplaySession
|
|
||||||
)
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -90,7 +79,7 @@ function getLiveReplaySession (req: express.Request, res: express.Response) {
|
||||||
async function getLiveVideoSessions (req: express.Request, res: express.Response) {
|
async function getLiveVideoSessions (req: express.Request, res: express.Response) {
|
||||||
const videoLive = res.locals.videoLive
|
const videoLive = res.locals.videoLive
|
||||||
|
|
||||||
const data = await VideoLiveSessionModel.listSessionsOfLiveForAPI({ videoId: videoLive.videoId })
|
const data = await VideoLiveSessionModel.listSessionsOfLiveForAPI({ videoId: videoLive.videoId, count: 100 })
|
||||||
|
|
||||||
return res.json(getFormattedObjects(data, data.length))
|
return res.json(getFormattedObjects(data, data.length))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ import {
|
||||||
Column,
|
Column,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
DataType,
|
DataType,
|
||||||
ForeignKey, Scopes,
|
ForeignKey,
|
||||||
|
Scopes,
|
||||||
Table,
|
Table,
|
||||||
UpdatedAt
|
UpdatedAt
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
|
@ -54,7 +55,6 @@ export enum ScopeNames {
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class VideoLiveSessionModel extends SequelizeModel<VideoLiveSessionModel> {
|
export class VideoLiveSessionModel extends SequelizeModel<VideoLiveSessionModel> {
|
||||||
|
|
||||||
@CreatedAt
|
@CreatedAt
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
|
|
||||||
|
@ -174,13 +174,17 @@ export class VideoLiveSessionModel extends SequelizeModel<VideoLiveSessionModel>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static listSessionsOfLiveForAPI (options: { videoId: number }) {
|
static listSessionsOfLiveForAPI (options: {
|
||||||
const { videoId } = options
|
videoId: number
|
||||||
|
count: number
|
||||||
|
}) {
|
||||||
|
const { videoId, count } = options
|
||||||
|
|
||||||
const query: FindOptions<AttributesOnly<VideoLiveSessionModel>> = {
|
const query: FindOptions<AttributesOnly<VideoLiveSessionModel>> = {
|
||||||
where: {
|
where: {
|
||||||
liveVideoId: videoId
|
liveVideoId: videoId
|
||||||
},
|
},
|
||||||
|
limit: count,
|
||||||
order: [ [ 'startDate', 'ASC' ] ]
|
order: [ [ 'startDate', 'ASC' ] ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue