mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Quit early if quota is exceeded
This commit is contained in:
@@ -38,6 +38,7 @@ import { computeResolutionsToTranscode } from '../transcoding/transcoding-resolu
|
||||
import { LiveQuotaStore } from './live-quota-store.js'
|
||||
import { cleanupAndDestroyPermanentLive, getLiveSegmentTime } from './live-utils.js'
|
||||
import { MuxingSession } from './shared/index.js'
|
||||
import { isUserQuotaValid } from '../user.js'
|
||||
|
||||
// Disable node media server logs
|
||||
nodeMediaServerLogger.setLogType(0)
|
||||
@@ -271,15 +272,24 @@ class LiveManager {
|
||||
|
||||
if (this.videoSessions.has(video.uuid)) {
|
||||
logger.warn(
|
||||
'Video %s has already a live session %s. Refusing stream %s.',
|
||||
video.uuid,
|
||||
this.videoSessions.get(video.uuid),
|
||||
streamKey,
|
||||
`Video ${video.uuid} has already a live session ${this.videoSessions.get(video.uuid)}. Refusing stream ${streamKey}.`,
|
||||
lTags(sessionId, video.uuid)
|
||||
)
|
||||
return this.abortSession(sessionId)
|
||||
}
|
||||
|
||||
if (videoLive.saveReplay && await isUserQuotaValid({ channelUserId: user.id, uploadSize: 1000 }) !== true) {
|
||||
logger.warn('User quota exceeded. Refusing stream %s.', streamKey, lTags(sessionId, video.uuid))
|
||||
|
||||
try {
|
||||
await this.saveEndingSession({ videoUUID: video.uuid, error: LiveVideoError.QUOTA_EXCEEDED })
|
||||
} catch (err) {
|
||||
logger.error('Cannot save ending session of live with quota exceeded error.', { err, ...lTags(sessionId, video.uuid) })
|
||||
}
|
||||
|
||||
return this.abortSession(sessionId)
|
||||
}
|
||||
|
||||
// Cleanup old potential live (could happen with a permanent live)
|
||||
const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSByVideo(video.id)
|
||||
if (oldStreamingPlaylist) {
|
||||
|
||||
@@ -230,7 +230,7 @@ export async function getOriginalVideoFileTotalDailyFromUser (user: MUserId) {
|
||||
|
||||
export async function isUserQuotaValid (options: {
|
||||
channelUserId: number
|
||||
uploadSize: number
|
||||
uploadSize: number // In bytes
|
||||
checkDaily?: boolean // default true
|
||||
}) {
|
||||
const { channelUserId, uploadSize, checkDaily = true } = options
|
||||
|
||||
Reference in New Issue
Block a user