diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-22 09:50:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-04-22 09:50:20 +0200 |
commit | 961cbe4269e5f34639e29310fb3d90a6cb1bd6bc (patch) | |
tree | 06404c72c25a95238e7ef8a6bdfcb90d40c8649c /server/controllers/api/videos | |
parent | 4ec52d04dcc5d664612331f8e08d7d90da990415 (diff) | |
download | PeerTube-961cbe4269e5f34639e29310fb3d90a6cb1bd6bc.tar.gz PeerTube-961cbe4269e5f34639e29310fb3d90a6cb1bd6bc.tar.zst PeerTube-961cbe4269e5f34639e29310fb3d90a6cb1bd6bc.zip |
Fix getting live by anonymous user
Diffstat (limited to 'server/controllers/api/videos')
-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) { |