Fetch media proxy settings and render form if it's enabled

This commit is contained in:
Angelina Filippova 2020-09-05 23:57:52 +03:00
parent dd88974338
commit ac1864c46f
2 changed files with 84 additions and 62 deletions

View file

@ -1,4 +1,5 @@
import { listBannedUrls, purgeUrls, removeBannedUrls, searchBannedUrls } from '@/api/mediaProxyCache'
import { fetchSettings } from '@/api/settings'
import { Message } from 'element-ui'
import i18n from '@/lang'
@ -7,10 +8,14 @@ const mediaProxyCache = {
bannedUrls: [],
currentPage: 1,
loading: false,
mediaProxyEnabled: false,
pageSize: 50,
totalUrlsCount: 0
},
mutations: {
MEDIA_PROXY_ENABLED: (state, enabled) => {
state.mediaProxyEnabled = enabled
},
SET_BANNED_URLS: (state, urls) => {
state.bannedUrls = urls.map(el => { return { url: el } })
},
@ -25,6 +30,17 @@ const mediaProxyCache = {
}
},
actions: {
async FetchMediaProxySetting({ commit, getters }) {
const { data } = await fetchSettings(getters.authHost, getters.token)
const mediaProxySettings = data.configs.find(el => el.key === ':media_proxy')
? data.configs.find(el => el.key === ':media_proxy').value
: []
const mediaProxyEnabled = mediaProxySettings.find(el => el.tuple[0] === ':enabled')
? mediaProxySettings.find(el => el.tuple[0] === ':enabled').tuple[1]
: false
commit('MEDIA_PROXY_ENABLED', mediaProxyEnabled)
},
async ListBannedUrls({ commit, getters, state }, { page }) {
commit('SET_LOADING', true)
const response = await listBannedUrls(page, state.pageSize, getters.authHost, getters.token)

View file

@ -1,5 +1,6 @@
<template>
<div class="media-proxy-cache-container">
<div v-if="mediaProxyEnabled">
<div class="media-proxy-cache-header-container">
<h1>{{ $t('mediaProxyCache.mediaProxyCache') }}</h1>
<reboot-button/>
@ -64,6 +65,7 @@
/>
</div>
</div>
</div>
</template>
<script>
@ -94,6 +96,9 @@ export default {
loading() {
return this.$store.state.mediaProxyCache.loading
},
mediaProxyEnabled() {
return this.$store.state.mediaProxyCache.mediaProxyEnabled
},
pageSize() {
return this.$store.state.mediaProxyCache.pageSize
},
@ -112,6 +117,7 @@ export default {
mounted() {
this.$store.dispatch('GetNodeInfo')
this.$store.dispatch('NeedReboot')
this.$store.dispatch('FetchMediaProxySetting')
this.$store.dispatch('ListBannedUrls', { page: 1 })
},
methods: {