From 764621d6fd6739e66d222c964d178313f7016415 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 5 Jul 2020 02:34:40 +0300 Subject: [PATCH] Create actions for listing banned urls, purge and remove banned urls form cachex --- src/store/index.js | 4 ++- src/store/modules/mediaProxyCache.js | 49 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/store/modules/mediaProxyCache.js diff --git a/src/store/index.js b/src/store/index.js index e2fcd651..bd4a6e5b 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import emojiPacks from './modules/emojiPacks' import errorLog from './modules/errorLog' import getters from './getters' import invites from './modules/invites' +import mediaProxyCache from './modules/mediaProxyCache' import moderationLog from './modules/moderationLog' import peers from './modules/peers' import permission from './modules/permission' @@ -24,8 +25,9 @@ const store = new Vuex.Store({ app, errorLog, emojiPacks, - moderationLog, invites, + mediaProxyCache, + moderationLog, peers, permission, relays, diff --git a/src/store/modules/mediaProxyCache.js b/src/store/modules/mediaProxyCache.js new file mode 100644 index 00000000..5990c8e8 --- /dev/null +++ b/src/store/modules/mediaProxyCache.js @@ -0,0 +1,49 @@ +import { listBannedUrls, purgeUrls, removeBannedUrls } from '@/api/mediaProxyCache' +import { Message } from 'element-ui' +import i18n from '@/lang' + +const mediaProxyCache = { + state: { + bannedUrls: [], + bannedUrlsCount: 0, + currentPage: 1, + loading: false + }, + mutations: { + SET_BANNED_URLS: (state, urls) => { + state.bannedUrls = urls + }, + SET_BANNED_URLS_COUNT: (state, count) => { + state.bannedUrlsCount = count + }, + SET_LOADING: (state, status) => { + state.loading = status + }, + SET_PAGE: (state, page) => { + state.currentPage = page + } + }, + actions: { + async ListBannedUrls({ commit, getters }, page) { + commit('SET_LOADING', true) + const response = await listBannedUrls(page, getters.authHost, getters.token) + commit('SET_BANNED_URLS', response.data.urls) + // commit('SET_BANNED_URLS_COUNT', count) + commit('SET_PAGE', page) + commit('SET_LOADING', false) + }, + async PurgeUrls({ commit, getters }, { urls, ban }) { + await purgeUrls(urls, ban, getters.authHost, getters.token) + Message({ + message: i18n.t('mediaProxyCache.evictedMessage'), + type: 'success', + duration: 5 * 1000 + }) + }, + async RemoveBannedUrls({ commit, getters }, urls) { + await removeBannedUrls(urls, getters.authHost, getters.token) + } + } +} + +export default mediaProxyCache