diff options
Diffstat (limited to 'server/controllers/api/videos/live.ts')
-rw-r--r-- | server/controllers/api/videos/live.ts | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index c6f038079..e51658927 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts | |||
@@ -10,11 +10,11 @@ import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator | |||
10 | import { VideoLiveModel } from '@server/models/video/video-live' | 10 | import { VideoLiveModel } from '@server/models/video/video-live' |
11 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' | 11 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' |
12 | import { buildUUID, uuidToShort } from '@shared/extra-utils' | 12 | import { buildUUID, uuidToShort } from '@shared/extra-utils' |
13 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, VideoState } from '@shared/models' | 13 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' |
14 | import { logger } from '../../../helpers/logger' | 14 | import { logger } from '../../../helpers/logger' |
15 | import { sequelizeTypescript } from '../../../initializers/database' | 15 | import { sequelizeTypescript } from '../../../initializers/database' |
16 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 16 | import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
17 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' | 17 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, optionalAuthenticate } from '../../../middlewares' |
18 | import { VideoModel } from '../../../models/video/video' | 18 | import { VideoModel } from '../../../models/video/video' |
19 | 19 | ||
20 | const liveRouter = express.Router() | 20 | const liveRouter = express.Router() |
@@ -29,7 +29,7 @@ liveRouter.post('/live', | |||
29 | ) | 29 | ) |
30 | 30 | ||
31 | liveRouter.get('/live/:videoId', | 31 | liveRouter.get('/live/:videoId', |
32 | authenticate, | 32 | optionalAuthenticate, |
33 | asyncMiddleware(videoLiveGetValidator), | 33 | asyncMiddleware(videoLiveGetValidator), |
34 | getLiveVideo | 34 | getLiveVideo |
35 | ) | 35 | ) |
@@ -52,7 +52,17 @@ export { | |||
52 | function getLiveVideo (req: express.Request, res: express.Response) { | 52 | function getLiveVideo (req: express.Request, res: express.Response) { |
53 | const videoLive = res.locals.videoLive | 53 | const videoLive = res.locals.videoLive |
54 | 54 | ||
55 | return res.json(videoLive.toFormattedJSON()) | 55 | return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res))) |
56 | } | ||
57 | |||
58 | function canSeePrivateLiveInformation (res: express.Response) { | ||
59 | const user = res.locals.oauth?.token.User | ||
60 | if (!user) return false | ||
61 | |||
62 | if (user.hasRight(UserRight.GET_ANY_LIVE)) return true | ||
63 | |||
64 | const video = res.locals.videoAll | ||
65 | return video.VideoChannel.Account.userId === user.id | ||
56 | } | 66 | } |
57 | 67 | ||
58 | async function updateLiveVideo (req: express.Request, res: express.Response) { | 68 | async function updateLiveVideo (req: express.Request, res: express.Response) { |