ffplayout/components/ConfigChannel.vue

170 lines
6.3 KiB
Vue
Raw Normal View History

2023-01-11 10:54:25 +01:00
<template>
<div v-if="configStore.channels && configStore.channels[configStore.id]" class="w-full max-w-[800px]">
<h2 class="pt-3 text-3xl">{{ $t('config.channelConf') }} ({{ configStore.channels[configStore.id].id }})</h2>
2024-04-04 23:28:25 +02:00
<div class="w-full flex justify-end my-4">
2024-06-30 22:04:04 +02:00
<button v-if="authStore.role === 'GlobalAdmin'" class="btn btn-sm btn-primary" @click="addChannel()">
{{ $t('config.addChannel') }}
</button>
2024-04-04 23:28:25 +02:00
</div>
2024-08-22 20:29:16 +02:00
<form class="w-full" @submit.prevent="onSubmitChannel">
2024-04-04 23:28:25 +02:00
<label class="form-control w-full">
<div class="label">
2024-04-16 14:07:50 +02:00
<span class="label-text">{{ $t('config.name') }}</span>
2023-01-11 10:54:25 +01:00
</div>
2024-04-04 23:28:25 +02:00
<input
v-model="configStore.channels[configStore.id].name"
2024-04-04 23:28:25 +02:00
type="text"
placeholder="Type here"
class="input input-bordered w-full"
/>
2024-04-04 23:28:25 +02:00
</label>
<label class="form-control w-full mt-5">
<div class="label">
2024-04-16 14:07:50 +02:00
<span class="label-text">{{ $t('config.previewUrl') }}</span>
2023-01-11 10:54:25 +01:00
</div>
2024-04-04 23:28:25 +02:00
<input
v-model="configStore.channels[configStore.id].preview_url"
2024-04-04 23:28:25 +02:00
type="text"
class="input input-bordered w-full"
/>
2024-04-04 23:28:25 +02:00
</label>
<label class="form-control w-full mt-5">
<div class="label">
2024-04-16 14:07:50 +02:00
<span class="label-text">{{ $t('config.extensions') }}</span>
2023-01-11 10:54:25 +01:00
</div>
2024-04-04 23:28:25 +02:00
<input
v-model="configStore.channels[configStore.id].extra_extensions"
2024-04-04 23:28:25 +02:00
type="text"
class="input input-bordered w-full"
/>
2024-04-04 23:28:25 +02:00
</label>
<template v-if="authStore.role === 'GlobalAdmin'">
2024-08-22 20:50:03 +02:00
<div class="mt-7 font-bold h-3">
<p v-if="configStore.playout.storage.shared_storage">
<SvgIcon name="warning" classes="inline mr-2" />
<span>{{ $t('config.sharedStorage') }}</span>
</p>
2024-08-22 20:29:16 +02:00
</div>
2024-08-22 20:50:03 +02:00
<label class="form-control w-full mt-3">
<div class="label">
<span class="label-text">{{ $t('config.hlsPath') }}</span>
</div>
<input
v-model="configStore.channels[configStore.id].hls_path"
type="text"
class="input input-bordered w-full"
/>
</label>
<label class="form-control w-full mt-5">
<div class="label">
<span class="label-text">{{ $t('config.playlistPath') }}</span>
</div>
<input
v-model="configStore.channels[configStore.id].playlist_path"
type="text"
class="input input-bordered w-full"
/>
</label>
<label class="form-control w-full mt-5">
<div class="label">
<span class="label-text">{{ $t('config.storagePath') }}</span>
</div>
<input
v-model="configStore.channels[configStore.id].storage_path"
type="text"
class="input input-bordered w-full"
/>
</label>
</template>
2024-04-07 15:45:26 +02:00
<div class="join my-4">
2024-04-16 14:07:50 +02:00
<button class="join-item btn btn-primary" type="submit">{{ $t('config.save') }}</button>
2024-04-04 23:28:25 +02:00
<button
2024-06-30 22:04:04 +02:00
v-if="
authStore.role === 'GlobalAdmin' &&
configStore.channels.length > 1 &&
configStore.channels[configStore.id].id > 1
2024-06-30 22:04:04 +02:00
"
2024-04-16 18:13:28 +02:00
class="join-item btn btn-primary"
2024-04-04 23:28:25 +02:00
@click="deleteChannel()"
>
2024-04-16 14:07:50 +02:00
{{ $t('config.delete') }}
2024-04-04 23:28:25 +02:00
</button>
</div>
</form>
2023-01-11 10:54:25 +01:00
</div>
</template>
<script setup lang="ts">
const { $_ } = useNuxtApp()
2024-04-16 14:07:50 +02:00
const { t } = useI18n()
2023-01-11 10:54:25 +01:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
2024-08-23 11:48:38 +02:00
function rmId(path: string) {
return path.replace(/\/\d+$/, '');
}
2023-01-11 10:54:25 +01:00
async function addChannel() {
const channels = $_.cloneDeep(configStore.channels)
const newChannel = $_.cloneDeep(configStore.channels[configStore.channels.length - 1])
2023-01-11 10:54:25 +01:00
newChannel.id = channels.length + 1
newChannel.name = `Channel ${newChannel.id}`
2024-07-02 21:40:55 +02:00
newChannel.preview_url = `${window.location.protocol}//${window.location.host}/live/${newChannel.id}/stream.m3u8`
2024-08-23 11:48:38 +02:00
newChannel.hls_path = `${rmId(newChannel.hls_path)}/${newChannel.id}`
newChannel.playlist_path = `${rmId(newChannel.playlist_path)}/${newChannel.id}`
newChannel.storage_path = `${rmId(newChannel.storage_path)}/${newChannel.id}`
2023-01-11 10:54:25 +01:00
channels.push(newChannel)
configStore.channels = channels
configStore.id = configStore.channels.length - 1
2023-01-11 10:54:25 +01:00
}
async function onSubmitChannel() {
2023-01-11 10:54:25 +01:00
/*
Save channel settings.
2023-01-11 10:54:25 +01:00
*/
const update = await configStore.setChannelConfig(configStore.channels[configStore.id])
2023-01-11 10:54:25 +01:00
if (update.status) {
2024-04-16 14:07:50 +02:00
indexStore.msgAlert('success', t('config.updateChannelSuccess'), 2)
2023-01-11 10:54:25 +01:00
} else {
2024-04-16 14:07:50 +02:00
indexStore.msgAlert('error', t('config.updateChannelFailed'), 2)
2023-01-11 10:54:25 +01:00
}
}
async function deleteChannel() {
const config = $_.cloneDeep(configStore.channels)
const id = config[configStore.id].id
2023-01-11 10:54:25 +01:00
if (id === 1) {
2024-04-16 14:07:50 +02:00
indexStore.msgAlert('warning', t('config.errorChannelDelete'), 2)
2023-01-11 10:54:25 +01:00
return
}
const response = await fetch(`/api/channel/${id}`, {
2023-01-11 10:54:25 +01:00
method: 'DELETE',
headers: authStore.authHeader,
})
config.splice(configStore.id, 1)
configStore.channels = config
configStore.id = configStore.channels.length - 1
2023-01-11 10:54:25 +01:00
await configStore.getPlayoutConfig()
if (response.status === 200) {
2024-04-16 14:07:50 +02:00
indexStore.msgAlert('success', t('config.errorChannelDelete'), 2)
2023-01-11 10:54:25 +01:00
} else {
2024-04-16 14:07:50 +02:00
indexStore.msgAlert('error', t('config.deleteChannelFailed'), 2)
2023-01-11 10:54:25 +01:00
}
}
</script>