mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 01:39:37 +02:00
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { PlayerChannelSettings, PlayerVideoSettings } from '@peertube/peertube-models'
|
|
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
|
|
import { sequelizeTypescript } from '@server/initializers/database.js'
|
|
import { PlayerSettingModel } from '@server/models/video/player-setting.js'
|
|
import { MChannelId, MVideoId } from '@server/types/models/index.js'
|
|
|
|
export async function upsertPlayerSettings (options: {
|
|
settings: PlayerVideoSettings | PlayerChannelSettings
|
|
channel: MChannelId
|
|
video: MVideoId
|
|
}) {
|
|
const { settings, channel, video } = options
|
|
|
|
if (!channel && !video) throw new Error('channel or video must be specified')
|
|
|
|
return retryTransactionWrapper(() => {
|
|
return sequelizeTypescript.transaction(async transaction => {
|
|
const setting = channel
|
|
? await PlayerSettingModel.loadByChannelId(channel.id, transaction)
|
|
: await PlayerSettingModel.loadByVideoId(video.id, transaction)
|
|
|
|
if (setting) await setting.destroy({ transaction })
|
|
|
|
return PlayerSettingModel.create({
|
|
theme: settings.theme,
|
|
channelId: channel?.id,
|
|
videoId: video?.id
|
|
}, { transaction })
|
|
})
|
|
})
|
|
}
|