From ac1864c46f8529768d32b5de27af725f0e34dd74 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 5 Sep 2020 23:57:52 +0300 Subject: [PATCH] Fetch media proxy settings and render form if it's enabled --- src/store/modules/mediaProxyCache.js | 16 ++++ src/views/mediaProxyCache/index.vue | 130 ++++++++++++++------------- 2 files changed, 84 insertions(+), 62 deletions(-) diff --git a/src/store/modules/mediaProxyCache.js b/src/store/modules/mediaProxyCache.js index b15fdb34..5a5307da 100644 --- a/src/store/modules/mediaProxyCache.js +++ b/src/store/modules/mediaProxyCache.js @@ -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) diff --git a/src/views/mediaProxyCache/index.vue b/src/views/mediaProxyCache/index.vue index 64dbe184..47475244 100644 --- a/src/views/mediaProxyCache/index.vue +++ b/src/views/mediaProxyCache/index.vue @@ -1,67 +1,69 @@ @@ -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: {