Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Quit early if quota is exceeded

Chocobozzza5f482519ea0
diff --git a/server/core/lib/live/live-manager.ts b/server/core/lib/live/live-manager.ts
index b9e41fa287..c19fc45cb6 100644
--- a/server/core/lib/live/live-manager.ts
+++ b/server/core/lib/live/live-manager.ts
@@ -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) {
diff --git a/server/core/lib/user.ts b/server/core/lib/user.ts
index 8bcff7e94b..f0db8d0d2c 100644
--- a/server/core/lib/user.ts
+++ b/server/core/lib/user.ts
@@ -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