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

View file

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