mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 01:39:37 +02:00
Add ability to customize player settings
This commit is contained in:
parent
b742dbc0fc
commit
74e97347bb
133 changed files with 2809 additions and 783 deletions
112
server/core/controllers/api/player-settings.ts
Normal file
112
server/core/controllers/api/player-settings.ts
Normal file
|
@ -0,0 +1,112 @@
|
|||
import { PlayerChannelSettingsUpdate, PlayerVideoSettingsUpdate } from '@peertube/peertube-models'
|
||||
import { upsertPlayerSettings } from '@server/lib/player-settings.js'
|
||||
import {
|
||||
getChannelPlayerSettingsValidator,
|
||||
getVideoPlayerSettingsValidator,
|
||||
updatePlayerSettingsValidatorFactory,
|
||||
updateVideoPlayerSettingsValidator
|
||||
} from '@server/middlewares/validators/player-settings.js'
|
||||
import { PlayerSettingModel } from '@server/models/video/player-setting.js'
|
||||
import express from 'express'
|
||||
import {
|
||||
apiRateLimiter,
|
||||
asyncMiddleware,
|
||||
authenticate,
|
||||
optionalAuthenticate,
|
||||
videoChannelsHandleValidatorFactory
|
||||
} from '../../middlewares/index.js'
|
||||
import { sendUpdateChannelPlayerSettings, sendUpdateVideoPlayerSettings } from '@server/lib/activitypub/send/send-update.js'
|
||||
|
||||
const playerSettingsRouter = express.Router()
|
||||
|
||||
playerSettingsRouter.use(apiRateLimiter)
|
||||
|
||||
playerSettingsRouter.get(
|
||||
'/videos/:videoId',
|
||||
optionalAuthenticate,
|
||||
asyncMiddleware(getVideoPlayerSettingsValidator),
|
||||
asyncMiddleware(getVideoPlayerSettings)
|
||||
)
|
||||
|
||||
playerSettingsRouter.put(
|
||||
'/videos/:videoId',
|
||||
authenticate,
|
||||
asyncMiddleware(updateVideoPlayerSettingsValidator),
|
||||
updatePlayerSettingsValidatorFactory('video'),
|
||||
asyncMiddleware(updateVideoPlayerSettings)
|
||||
)
|
||||
|
||||
playerSettingsRouter.get(
|
||||
'/video-channels/:handle',
|
||||
optionalAuthenticate,
|
||||
asyncMiddleware(videoChannelsHandleValidatorFactory({ checkIsLocal: false, checkManage: false })),
|
||||
getChannelPlayerSettingsValidator,
|
||||
asyncMiddleware(getChannelPlayerSettings)
|
||||
)
|
||||
|
||||
playerSettingsRouter.put(
|
||||
'/video-channels/:handle',
|
||||
authenticate,
|
||||
asyncMiddleware(videoChannelsHandleValidatorFactory({ checkIsLocal: true, checkManage: true })),
|
||||
updatePlayerSettingsValidatorFactory('channel'),
|
||||
asyncMiddleware(updateChannelPlayerSettings)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
playerSettingsRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function getVideoPlayerSettings (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.onlyVideo || res.locals.videoAll
|
||||
|
||||
const { videoSetting, channelSetting } = await PlayerSettingModel.loadByVideoIdOrChannelId({
|
||||
channelId: video.channelId,
|
||||
videoId: video.id
|
||||
})
|
||||
|
||||
if (req.query.raw === true) {
|
||||
return res.json(PlayerSettingModel.formatVideoPlayerRawSetting(videoSetting))
|
||||
}
|
||||
|
||||
return res.json(PlayerSettingModel.formatVideoPlayerSetting({ videoSetting, channelSetting }))
|
||||
}
|
||||
|
||||
async function getChannelPlayerSettings (req: express.Request, res: express.Response) {
|
||||
const channel = res.locals.videoChannel
|
||||
|
||||
const channelSetting = await PlayerSettingModel.loadByChannelId(channel.id)
|
||||
|
||||
if (req.query.raw === true) {
|
||||
return res.json(PlayerSettingModel.formatChannelPlayerRawSetting(channelSetting))
|
||||
}
|
||||
|
||||
return res.json(PlayerSettingModel.formatChannelPlayerSetting({ channelSetting }))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function updateVideoPlayerSettings (req: express.Request, res: express.Response) {
|
||||
const body: PlayerVideoSettingsUpdate = req.body
|
||||
const video = res.locals.videoAll
|
||||
|
||||
const setting = await upsertPlayerSettings({ settings: body, channel: undefined, video })
|
||||
|
||||
await sendUpdateVideoPlayerSettings(video, setting, undefined)
|
||||
|
||||
return res.json(PlayerSettingModel.formatVideoPlayerRawSetting(setting))
|
||||
}
|
||||
|
||||
async function updateChannelPlayerSettings (req: express.Request, res: express.Response) {
|
||||
const body: PlayerChannelSettingsUpdate = req.body
|
||||
const channel = res.locals.videoChannel
|
||||
|
||||
const settings = await upsertPlayerSettings({ settings: body, channel, video: undefined })
|
||||
|
||||
await sendUpdateChannelPlayerSettings(channel, settings, undefined)
|
||||
|
||||
return res.json(PlayerSettingModel.formatChannelPlayerRawSetting(settings))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue