From 47dd86911f1aa2fea8b570691bd87e83e7d0d3bc Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 17 Oct 2019 22:59:25 +0200 Subject: [PATCH] Add ability to manage relays --- src/api/relays.js | 34 ++++++++++++ src/lang/en.js | 1 + src/store/index.js | 2 + src/store/modules/relays.js | 44 ++++++++++++++++ src/views/settings/components/Relays.vue | 66 ++++++++++++++++++++++++ src/views/settings/components/index.js | 1 + src/views/settings/index.vue | 7 ++- 7 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/api/relays.js create mode 100644 src/store/modules/relays.js create mode 100644 src/views/settings/components/Relays.vue diff --git a/src/api/relays.js b/src/api/relays.js new file mode 100644 index 00000000..3be0188d --- /dev/null +++ b/src/api/relays.js @@ -0,0 +1,34 @@ +import request from '@/utils/request' +import { getToken } from '@/utils/auth' +import { baseName } from './utils' + +export async function fetchRelays(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/relay', + method: 'get', + headers: authHeaders(token) + }) +} + +export async function addRelay(relay, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/relay', + method: 'post', + headers: authHeaders(token), + data: { relay_url: relay } + }) +} + +export async function deleteRelay(relay, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: '/api/pleroma/admin/relay', + method: 'delete', + headers: authHeaders(token), + data: { relay_url: `https://${relay}/actor` } + }) +} + +const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/lang/en.js b/src/lang/en.js index 8088e441..c191007c 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -312,6 +312,7 @@ export default { rateLimiters: 'Rate limiters', database: 'Database', other: 'Other', + relays: 'Relays', success: 'Settings changed successfully!' }, invites: { diff --git a/src/store/index.js b/src/store/index.js index 985074a0..45251a38 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import errorLog from './modules/errorLog' import moderationLog from './modules/moderationLog' import invites from './modules/invites' import permission from './modules/permission' +import relays from './modules/relays' import reports from './modules/reports' import settings from './modules/settings' import tagsView from './modules/tagsView' @@ -23,6 +24,7 @@ const store = new Vuex.Store({ moderationLog, invites, permission, + relays, reports, settings, tagsView, diff --git a/src/store/modules/relays.js b/src/store/modules/relays.js new file mode 100644 index 00000000..6353569e --- /dev/null +++ b/src/store/modules/relays.js @@ -0,0 +1,44 @@ +import { fetchRelays, addRelay, deleteRelay } from '@/api/relays' + +const relays = { + state: { + fetchedRelays: [], + loading: true + }, + mutations: { + SET_LOADING: (state, loading) => { + state.loading = loading + }, + SET_RELAYS: (state, relays) => { + state.fetchedRelays = relays + }, + ADD_RELAY: (state, relay) => { + state.fetchedRelays = [...state.fetchedRelays, relay] + }, + DELETE_RELAY: (state, relay) => { + state.fetchedRelays = state.fetchedRelays.filter(fetchedRelay => fetchedRelay !== relay) + } + }, + actions: { + async FetchRelays({ commit, getters }) { + commit('SET_LOADING', true) + + const response = await fetchRelays(getters.authHost, getters.token) + + commit('SET_RELAYS', response.data.relays) + commit('SET_LOADING', false) + }, + async AddRelay({ commit, getters }, relay) { + commit('ADD_RELAY', relay) + + await addRelay(relay, getters.authHost, getters.token) + }, + async DeleteRelay({ commit, getters }, relay) { + commit('DELETE_RELAY', relay) + + await deleteRelay(relay, getters.authHost, getters.token) + } + } +} + +export default relays diff --git a/src/views/settings/components/Relays.vue b/src/views/settings/components/Relays.vue new file mode 100644 index 00000000..1240ad3d --- /dev/null +++ b/src/views/settings/components/Relays.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/src/views/settings/components/index.js b/src/views/settings/components/index.js index 4e5b8e8e..040d6712 100644 --- a/src/views/settings/components/index.js +++ b/src/views/settings/components/index.js @@ -17,5 +17,6 @@ export { default as Metadata } from './Metadata' export { default as Mrf } from './MRF' export { default as Other } from './Other' export { default as RateLimiters } from './RateLimiters' +export { default as Relays } from './Relays' export { default as Upload } from './Upload' export { default as WebPush } from './WebPush' diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue index 79ae7727..4ce9888d 100644 --- a/src/views/settings/index.vue +++ b/src/views/settings/index.vue @@ -56,6 +56,9 @@ + + + @@ -70,10 +73,10 @@