some initial work on moving instance settings to pinia
This commit is contained in:
parent
20071d5a11
commit
9452b3084a
10 changed files with 559 additions and 195 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/* global process */
|
||||
|
||||
import vClickOutside from 'click-outside-vue3'
|
||||
import { get, set } from 'lodash'
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import VueVirtualScroller from 'vue-virtual-scroller'
|
||||
|
|
@ -22,6 +23,7 @@ import {
|
|||
import { useAnnouncementsStore } from 'src/stores/announcements'
|
||||
import { useAuthFlowStore } from 'src/stores/auth_flow'
|
||||
import { useI18nStore } from 'src/stores/i18n'
|
||||
import { useInstanceStore } from 'src/stores/instance'
|
||||
import { useInterfaceStore } from 'src/stores/interface'
|
||||
import { useOAuthStore } from 'src/stores/oauth'
|
||||
import App from '../App.vue'
|
||||
|
|
@ -78,30 +80,30 @@ const getInstanceConfig = async ({ store }) => {
|
|||
const textlimit = data.max_toot_chars
|
||||
const vapidPublicKey = data.pleroma.vapid_public_key
|
||||
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pleromaExtensionsAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.pleromaExtensionsAvailable',
|
||||
value: data.pleroma,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'textlimit',
|
||||
useInstanceStore().set({
|
||||
path: 'textlimit',
|
||||
value: textlimit,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'accountApprovalRequired',
|
||||
useInstanceStore().set({
|
||||
path: 'accountApprovalRequired',
|
||||
value: data.approval_required,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'birthdayRequired',
|
||||
useInstanceStore().set({
|
||||
path: 'birthdayRequired',
|
||||
value: !!data.pleroma?.metadata.birthday_required,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'birthdayMinAge',
|
||||
useInstanceStore().set({
|
||||
path: 'birthdayMinAge',
|
||||
value: data.pleroma?.metadata.birthday_min_age || 0,
|
||||
})
|
||||
|
||||
if (vapidPublicKey) {
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'vapidPublicKey',
|
||||
useInstanceStore().set({
|
||||
path: 'vapidPublicKey',
|
||||
value: vapidPublicKey,
|
||||
})
|
||||
}
|
||||
|
|
@ -156,19 +158,32 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => {
|
|||
let config = {}
|
||||
if (overrides.staticConfigPreference && env === 'development') {
|
||||
console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG')
|
||||
config = Object.assign({}, apiConfig, staticConfig)
|
||||
config = { ...apiConfig, ...staticConfig }
|
||||
} else {
|
||||
config = Object.assign({}, staticConfig, apiConfig)
|
||||
config = { ...staticConfig, ...apiConfig }
|
||||
}
|
||||
console.trace(config)
|
||||
|
||||
const copyInstanceOption = (name) => {
|
||||
if (typeof config[name] !== 'undefined') {
|
||||
store.dispatch('setInstanceOption', { name, value: config[name] })
|
||||
const copyInstanceIdentityOption = (path) => {
|
||||
if (get(config, path) !== undefined) {
|
||||
useInstanceStore().set({
|
||||
path: `instanceIdentity.${path}`,
|
||||
value: get(config, path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(staticOrApiConfigDefault).forEach(copyInstanceOption)
|
||||
Object.keys(instanceDefaultConfig).forEach(copyInstanceOption)
|
||||
const copyInstancePrefOption = (path) => {
|
||||
if (get(config, path) !== undefined) {
|
||||
useInstanceStore().set({
|
||||
path: `prefsStorage.${path}`,
|
||||
value: get(config, path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(staticOrApiConfigDefault).forEach(copyInstanceIdentityOption)
|
||||
Object.keys(instanceDefaultConfig).forEach(copyInstancePrefOption)
|
||||
|
||||
useAuthFlowStore().setInitialStrategy(config.loginMethod)
|
||||
}
|
||||
|
|
@ -178,7 +193,7 @@ const getTOS = async ({ store }) => {
|
|||
const res = await window.fetch('/static/terms-of-service.html')
|
||||
if (res.ok) {
|
||||
const html = await res.text()
|
||||
store.dispatch('setInstanceOption', { name: 'tos', value: html })
|
||||
useInstanceStore().set({ path: 'tos', value: html })
|
||||
} else {
|
||||
throw res
|
||||
}
|
||||
|
|
@ -192,8 +207,8 @@ const getInstancePanel = async ({ store }) => {
|
|||
const res = await preloadFetch('/instance/panel.html')
|
||||
if (res.ok) {
|
||||
const html = await res.text()
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'instanceSpecificPanelContent',
|
||||
useInstanceStore().set({
|
||||
path: 'instanceSpecificPanelContent',
|
||||
value: html,
|
||||
})
|
||||
} else {
|
||||
|
|
@ -227,7 +242,7 @@ const getStickers = async ({ store }) => {
|
|||
).sort((a, b) => {
|
||||
return a.meta.title.localeCompare(b.meta.title)
|
||||
})
|
||||
store.dispatch('setInstanceOption', { name: 'stickers', value: stickers })
|
||||
useInstanceStore().set({ path: 'stickers', value: stickers })
|
||||
} else {
|
||||
throw res
|
||||
}
|
||||
|
|
@ -248,8 +263,8 @@ const getAppSecret = async ({ store }) => {
|
|||
|
||||
const resolveStaffAccounts = ({ store, accounts }) => {
|
||||
const nicknames = accounts.map((uri) => uri.split('/').pop())
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'staffAccounts',
|
||||
useInstanceStore().set({
|
||||
path: 'staffAccounts',
|
||||
value: nicknames,
|
||||
})
|
||||
}
|
||||
|
|
@ -262,160 +277,160 @@ const getNodeInfo = async ({ store }) => {
|
|||
const data = await res.json()
|
||||
const metadata = data.metadata
|
||||
const features = metadata.features
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'name',
|
||||
useInstanceStore().set({
|
||||
path: 'name',
|
||||
value: metadata.nodeName,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'registrationOpen',
|
||||
useInstanceStore().set({
|
||||
path: 'registrationOpen',
|
||||
value: data.openRegistrations,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'mediaProxyAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.mediaProxyAvailable',
|
||||
value: features.includes('media_proxy'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'safeDM',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.safeDM',
|
||||
value: features.includes('safe_dm_mentions'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'shoutAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.shoutAvailable',
|
||||
value: features.includes('chat'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pleromaChatMessagesAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.pleromaChatMessagesAvailable',
|
||||
value: features.includes('pleroma_chat_messages'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pleromaCustomEmojiReactionsAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.pleromaCustomEmojiReactionsAvailable',
|
||||
value:
|
||||
features.includes('pleroma_custom_emoji_reactions') ||
|
||||
features.includes('custom_emoji_reactions'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pleromaBookmarkFoldersAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.pleromaBookmarkFoldersAvailable',
|
||||
value: features.includes('pleroma:bookmark_folders'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'gopherAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.gopherAvailable',
|
||||
value: features.includes('gopher'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pollsAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.pollsAvailable',
|
||||
value: features.includes('polls'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'editingAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.editingAvailable',
|
||||
value: features.includes('editing'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'pollLimits',
|
||||
useInstanceStore().set({
|
||||
path: 'pollLimits',
|
||||
value: metadata.pollLimits,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'mailerEnabled',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.mailerEnabled',
|
||||
value: metadata.mailerEnabled,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'quotingAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.quotingAvailable',
|
||||
value: features.includes('quote_posting'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'groupActorAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.groupActorAvailable',
|
||||
value: features.includes('pleroma:group_actors'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'blockExpiration',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.blockExpiration',
|
||||
value: features.includes('pleroma:block_expiration'),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'localBubbleInstances',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.localBubbleInstances',
|
||||
value: metadata.localBubbleInstances ?? [],
|
||||
})
|
||||
|
||||
const uploadLimits = metadata.uploadLimits
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'uploadlimit',
|
||||
useInstanceStore().set({
|
||||
path: 'uploadlimit',
|
||||
value: parseInt(uploadLimits.general),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'avatarlimit',
|
||||
useInstanceStore().set({
|
||||
path: 'avatarlimit',
|
||||
value: parseInt(uploadLimits.avatar),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'backgroundlimit',
|
||||
useInstanceStore().set({
|
||||
path: 'backgroundlimit',
|
||||
value: parseInt(uploadLimits.background),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'bannerlimit',
|
||||
useInstanceStore().set({
|
||||
path: 'bannerlimit',
|
||||
value: parseInt(uploadLimits.banner),
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'fieldsLimits',
|
||||
useInstanceStore().set({
|
||||
path: 'fieldsLimits',
|
||||
value: metadata.fieldsLimits,
|
||||
})
|
||||
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'restrictedNicknames',
|
||||
useInstanceStore().set({
|
||||
path: 'restrictedNicknames',
|
||||
value: metadata.restrictedNicknames,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'postFormats',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.postFormats',
|
||||
value: metadata.postFormats,
|
||||
})
|
||||
|
||||
const suggestions = metadata.suggestions
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'suggestionsEnabled',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.suggestionsEnabled',
|
||||
value: suggestions.enabled,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'suggestionsWeb',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.suggestionsWeb',
|
||||
value: suggestions.web,
|
||||
})
|
||||
|
||||
const software = data.software
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'backendVersion',
|
||||
useInstanceStore().set({
|
||||
path: 'backendVersion',
|
||||
value: software.version,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'backendRepository',
|
||||
useInstanceStore().set({
|
||||
path: 'backendRepository',
|
||||
value: software.repository,
|
||||
})
|
||||
|
||||
const priv = metadata.private
|
||||
store.dispatch('setInstanceOption', { name: 'private', value: priv })
|
||||
useInstanceStore().set({ path: 'private', value: priv })
|
||||
|
||||
const frontendVersion = window.___pleromafe_commit_hash
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'frontendVersion',
|
||||
useInstanceStore().set({
|
||||
path: 'frontendVersion',
|
||||
value: frontendVersion,
|
||||
})
|
||||
|
||||
const federation = metadata.federation
|
||||
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'tagPolicyAvailable',
|
||||
useInstanceStore().set({
|
||||
path: 'featureSet.tagPolicyAvailable',
|
||||
value:
|
||||
typeof federation.mrf_policies === 'undefined'
|
||||
? false
|
||||
: metadata.federation.mrf_policies.includes('TagPolicy'),
|
||||
})
|
||||
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'federationPolicy',
|
||||
useInstanceStore().set({
|
||||
path: 'federationPolicy',
|
||||
value: federation,
|
||||
})
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'federating',
|
||||
useInstanceStore().set({
|
||||
path: 'federating',
|
||||
value:
|
||||
typeof federation.enabled === 'undefined' ? true : federation.enabled,
|
||||
})
|
||||
|
||||
const accountActivationRequired = metadata.accountActivationRequired
|
||||
store.dispatch('setInstanceOption', {
|
||||
name: 'accountActivationRequired',
|
||||
useInstanceStore().set({
|
||||
path: 'accountActivationRequired',
|
||||
value: accountActivationRequired,
|
||||
})
|
||||
|
||||
|
|
@ -526,7 +541,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
|
|||
typeof overrides.target !== 'undefined'
|
||||
? overrides.target
|
||||
: window.location.origin
|
||||
store.dispatch('setInstanceOption', { name: 'server', value: server })
|
||||
useInstanceStore().set({ path: 'server', value: server })
|
||||
|
||||
await setConfig({ store })
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue