diff --git a/src/api/settings.js b/src/api/settings.js index a0da39cd..55e35100 100644 --- a/src/api/settings.js +++ b/src/api/settings.js @@ -2,6 +2,15 @@ import request from '@/utils/request' import { getToken } from '@/utils/auth' import { baseName } from './utils' +export async function fetchDescription(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/config/descriptions`, + method: 'get', + headers: authHeaders(token) + }) +} + export async function fetchSettings(authHost, token) { return await request({ baseURL: baseName(authHost), @@ -11,6 +20,15 @@ export async function fetchSettings(authHost, token) { }) } +export async function migrateToDB(authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/config/migrate_to_db`, + method: 'get', + headers: authHeaders(token) + }) +} + export async function updateSettings(configs, authHost, token) { return await request({ baseURL: baseName(authHost), diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index bb6bd8c1..8fd63099 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,54 +1,55 @@ -import { fetchSettings, updateSettings, uploadMedia } from '@/api/settings' +import { fetchDescription, fetchSettings, migrateToDB, updateSettings, uploadMedia } from '@/api/settings' import { filterIgnored, parseTuples, valueHasTuples, wrapConfig } from './normalizers' const settings = { state: { + description: [], settings: { - 'activitypub': {}, - 'adapter': {}, - 'admin_token': {}, - 'assets': { mascots: {}}, - 'auth': {}, - 'auto_linker': { opts: {}}, - 'backends': {}, - 'chat': {}, - 'console': { colors: {}}, - 'credentials': {}, - 'database': {}, - 'ecto_repos': {}, - 'email_notifications': { digest: {}}, - 'emoji': { groups: {}}, - 'enabled': {}, - 'ex_syslogger': {}, - 'expose': {}, - 'fetch_initial_posts': {}, - 'format_encoders': {}, - 'frontend_configurations': { pleroma_fe: {}, masto_fe: {}}, - 'gopher': {}, - 'hackney_pools': { federation: {}, media: {}, upload: {}}, - 'handler': {}, - 'headers': {}, - 'http': { adapter: {}}, - 'http_security': {}, - 'instance': { poll_limits: {}}, - 'level': {}, - 'ldap': {}, - 'markup': {}, - 'max_age': {}, - 'media_proxy': { proxy_opts: {}}, - 'meta': {}, - 'methods': {}, - 'mrf_hellthread': {}, - 'mrf_keyword': { replace: {}}, - 'mrf_mention': {}, - 'mrf_normalize_markup': {}, - 'mrf_rejectnonpublic': {}, - 'mrf_simple': {}, - 'mrf_subchain': { match_actor: {}}, - 'mrf_user_allowlist': {}, - 'mrf_vocabulary': {}, - 'oauth2': {}, - 'password_authenticator': {}, + ':activitypub': {}, + ':adapter': {}, + ':admin_token': {}, + ':assets': { mascots: {}}, + ':auth': {}, + ':auto_linker': { opts: {}}, + ':backends': {}, + ':chat': {}, + ':console': { colors: {}}, + ':credentials': {}, + ':database': {}, + ':ecto_repos': {}, + ':email_notifications': { digest: {}}, + ':emoji': { groups: {}}, + ':enabled': {}, + ':ex_syslogger': {}, + ':expose': {}, + ':fetch_initial_posts': {}, + ':format_encoders': {}, + ':frontend_configurations': { pleroma_fe: {}, masto_fe: {}}, + ':gopher': {}, + ':hackney_pools': { federation: {}, media: {}, upload: {}}, + ':handler': {}, + ':headers': {}, + ':http': { adapter: {}}, + ':http_security': {}, + ':instance': { poll_limits: {}}, + ':level': {}, + ':ldap': {}, + ':markup': {}, + ':max_age': {}, + ':media_proxy': { proxy_opts: {}}, + ':meta': {}, + ':methods': {}, + ':mrf_hellthread': {}, + ':mrf_keyword': { replace: {}}, + ':mrf_mention': {}, + ':mrf_normalize_markup': {}, + ':mrf_rejectnonpublic': {}, + ':mrf_simple': {}, + ':mrf_subchain': { match_actor: {}}, + ':mrf_user_allowlist': {}, + ':mrf_vocabulary': {}, + ':oauth2': {}, + ':password_authenticator': {}, 'Pleroma.Captcha': {}, 'Pleroma.Captcha.Kocaptcha': {}, 'Pleroma.Emails.Mailer': {}, @@ -67,22 +68,22 @@ const settings = { { http: false, url: {}, render_errors: {}, pubsub: {}}, 'Pleroma.Web.Federator.RetryQueue': {}, 'Pleroma.Web.Metadata': {}, - 'port': {}, - 'priv_dir': {}, - 'queues': {}, - 'rate_limit': {}, - 'rich_media': {}, - 'suggestions': {}, - 'types': { value: {}}, + ':port': {}, + ':priv_dir': {}, + ':queues': {}, + ':rate_limit': {}, + ':rich_media': {}, + ':suggestions': {}, + ':types': { value: {}}, 'Ueberauth': {}, 'Ueberauth.Strategy.Facebook.OAuth': {}, 'Ueberauth.Strategy.Google.OAuth': {}, 'Ueberauth.Strategy.Microsoft.OAuth': {}, 'Ueberauth.Strategy.Twitter.OAuth': {}, - 'user': {}, - 'uri_schemes': {}, - 'vapid_details': {}, - 'webhook_url': {} + ':user': {}, + ':uri_schemes': {}, + ':vapid_details': {}, + ':webhook_url': {} }, ignoredIfNotEnabled: ['enabled', 'handler', 'password_authenticator', 'port', 'priv_dir'], loading: true @@ -91,14 +92,16 @@ const settings = { REWRITE_CONFIG: (state, { tab, data }) => { state.settings[tab] = data }, + SET_DESCRIPTION: (state, data) => { + state.description = data + }, SET_LOADING: (state, status) => { state.loading = status }, SET_SETTINGS: (state, data) => { - const newSettings = data.reduce((acc, config) => { - const key = config.key[0] === ':' ? config.key.substr(1) : config.key - const value = valueHasTuples(key, config.value) ? { value: config.value } : parseTuples(config.value, key) - acc[key] = { ...acc[key], ...value } + const newSettings = data.reduce((acc, { key, value }) => { + const parsedValue = valueHasTuples(key, value) ? { value } : parseTuples(value, key) + acc[key] = { ...acc[key], ...parsedValue } return acc }, state.settings) state.settings = newSettings @@ -115,9 +118,18 @@ const settings = { async FetchSettings({ commit, dispatch, getters }) { commit('SET_LOADING', true) const response = await fetchSettings(getters.authHost, getters.token) + const description = await fetchDescription(getters.authHost, getters.token) + if (response.data.configs.length === 0) { + dispatch('MigrateToDB') + dispatch('FetchSettings') + } + commit('SET_DESCRIPTION', description.data) commit('SET_SETTINGS', response.data.configs) commit('SET_LOADING', false) }, + async MigrateToDB({ getters }) { + await migrateToDB(getters.authHost, getters.token) + }, RewriteConfig({ commit }, { tab, data }) { commit('REWRITE_CONFIG', { tab, data }) },