aboutsummaryrefslogtreecommitdiff
path: root/src/boot/after_store.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/after_store.js')
-rw-r--r--src/boot/after_store.js105
1 files changed, 78 insertions, 27 deletions
diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index 0db03547..00ca74a2 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -8,38 +8,72 @@ import backendInteractorService from '../services/backend_interactor_service/bac
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
import { applyTheme } from '../services/style_setter/style_setter.js'
-const getStatusnetConfig = async ({ store }) => {
+let staticInitialResults = null
+
+const parsedInitialResults = () => {
+ if (!document.getElementById('initial-results')) {
+ return null
+ }
+ if (!staticInitialResults) {
+ staticInitialResults = JSON.parse(document.getElementById('initial-results').textContent)
+ }
+ return staticInitialResults
+}
+
+const decodeUTF8Base64 = (data) => {
+ const rawData = atob(data)
+ const array = Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)))
+ const text = new TextDecoder().decode(array)
+ return text
+}
+
+const preloadFetch = async (request) => {
+ const data = parsedInitialResults()
+ if (!data || !data[request]) {
+ return window.fetch(request)
+ }
+ const decoded = decodeUTF8Base64(data[request])
+ const requestData = JSON.parse(decoded)
+ return {
+ ok: true,
+ json: () => requestData,
+ text: () => requestData
+ }
+}
+
+const getInstanceConfig = async ({ store }) => {
try {
- const res = await window.fetch('/api/statusnet/config.json')
+ const res = await preloadFetch('/api/v1/instance')
if (res.ok) {
const data = await res.json()
- const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey, safeDMMentionsEnabled } = data.site
-
- store.dispatch('setInstanceOption', { name: 'name', value: name })
- store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') })
- store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) })
- store.dispatch('setInstanceOption', { name: 'server', value: server })
- store.dispatch('setInstanceOption', { name: 'safeDM', value: safeDMMentionsEnabled !== '0' })
-
- // TODO: default values for this stuff, added if to not make it break on
- // my dev config out of the box.
- if (uploadlimit) {
- store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) })
- store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) })
- store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) })
- store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) })
- }
+ const textlimit = data.max_toot_chars
+ const vapidPublicKey = data.pleroma.vapid_public_key
+
+ store.dispatch('setInstanceOption', { name: 'textlimit', value: textlimit })
if (vapidPublicKey) {
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
}
+ } else {
+ throw (res)
+ }
+ } catch (error) {
+ console.error('Could not load instance config, potentially fatal')
+ console.error(error)
+ }
+}
- return data.site.pleromafe
+const getBackendProvidedConfig = async ({ store }) => {
+ try {
+ const res = await window.fetch('/api/pleroma/frontend_configurations')
+ if (res.ok) {
+ const data = await res.json()
+ return data.pleroma_fe
} else {
throw (res)
}
} catch (error) {
- console.error('Could not load statusnet config, potentially fatal')
+ console.error('Could not load backend-provided frontend config, potentially fatal')
console.error(error)
}
}
@@ -132,7 +166,7 @@ const getTOS = async ({ store }) => {
const getInstancePanel = async ({ store }) => {
try {
- const res = await window.fetch('/instance/panel.html')
+ const res = await preloadFetch('/instance/panel.html')
if (res.ok) {
const html = await res.text()
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
@@ -189,24 +223,34 @@ const getAppSecret = async ({ store }) => {
const resolveStaffAccounts = ({ store, accounts }) => {
const nicknames = accounts.map(uri => uri.split('/').pop())
- nicknames.map(nickname => store.dispatch('fetchUser', nickname))
store.dispatch('setInstanceOption', { name: 'staffAccounts', value: nicknames })
}
const getNodeInfo = async ({ store }) => {
try {
- const res = await window.fetch('/nodeinfo/2.0.json')
+ const res = await preloadFetch('/nodeinfo/2.0.json')
if (res.ok) {
const data = await res.json()
const metadata = data.metadata
const features = metadata.features
+ store.dispatch('setInstanceOption', { name: 'name', value: metadata.nodeName })
+ store.dispatch('setInstanceOption', { name: 'registrationOpen', value: data.openRegistrations })
store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') })
+ store.dispatch('setInstanceOption', { name: 'safeDM', value: features.includes('safe_dm_mentions') })
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
+ store.dispatch('setInstanceOption', { name: 'pleromaChatMessagesAvailable', value: features.includes('pleroma_chat_messages') })
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') })
store.dispatch('setInstanceOption', { name: 'pollLimits', value: metadata.pollLimits })
store.dispatch('setInstanceOption', { name: 'mailerEnabled', value: metadata.mailerEnabled })
+ const uploadLimits = metadata.uploadLimits
+ store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadLimits.general) })
+ store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadLimits.avatar) })
+ store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadLimits.background) })
+ store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadLimits.banner) })
+ store.dispatch('setInstanceOption', { name: 'fieldsLimits', value: metadata.fieldsLimits })
+
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
@@ -257,7 +301,7 @@ const getNodeInfo = async ({ store }) => {
const setConfig = async ({ store }) => {
// apiConfig, staticConfig
- const configInfos = await Promise.all([getStatusnetConfig({ store }), getStaticConfig()])
+ const configInfos = await Promise.all([getBackendProvidedConfig({ store }), getStaticConfig()])
const apiConfig = configInfos[0]
const staticConfig = configInfos[1]
@@ -280,6 +324,11 @@ const checkOAuthToken = async ({ store }) => {
const afterStoreSetup = async ({ store, i18n }) => {
const width = windowWidth()
store.dispatch('setMobileLayout', width <= 800)
+
+ const overrides = window.___pleromafe_dev_overrides || {}
+ const server = (typeof overrides.target !== 'undefined') ? overrides.target : window.location.origin
+ store.dispatch('setInstanceOption', { name: 'server', value: server })
+
await setConfig({ store })
const { customTheme, customThemeSource } = store.state.config
@@ -299,16 +348,18 @@ const afterStoreSetup = async ({ store, i18n }) => {
}
// Now we can try getting the server settings and logging in
+ // Most of these are preloaded into the index.html so blocking is minimized
await Promise.all([
checkOAuthToken({ store }),
- getTOS({ store }),
getInstancePanel({ store }),
- getStickers({ store }),
- getNodeInfo({ store })
+ getNodeInfo({ store }),
+ getInstanceConfig({ store })
])
// Start fetching things that don't need to block the UI
store.dispatch('fetchMutes')
+ getTOS({ store })
+ getStickers({ store })
const router = new VueRouter({
mode: 'history',