aboutsummaryrefslogtreecommitdiff
path: root/src/boot/after_store.js
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2020-06-27 12:26:19 +0300
committerShpuld Shpuldson <shp@cock.li>2020-06-27 12:26:19 +0300
commit5ab62c4cb8bc2ccf718d0b60749bcc03fba54784 (patch)
tree43fb3643d1be79b288de469a96b19cb019b50480 /src/boot/after_store.js
parenta2c5175d14b322062f8fc07b11a6a45f1d5aba4f (diff)
parent4d52b8bf56c44a217b2cc97414bf13104691d7f9 (diff)
make use of api/v1/instance
Diffstat (limited to 'src/boot/after_store.js')
-rw-r--r--src/boot/after_store.js61
1 files changed, 39 insertions, 22 deletions
diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index 0c213ea3..01074b8c 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -33,38 +33,39 @@ const preloadFetch = async (request) => {
}
}
-const getStatusnetConfig = async ({ store }) => {
+const getInstanceConfig = async ({ store }) => {
try {
- const res = await preloadFetch('/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)
}
}
@@ -225,13 +226,23 @@ const getNodeInfo = async ({ store }) => {
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: '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 })
@@ -282,7 +293,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]
@@ -305,6 +316,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
@@ -329,7 +345,8 @@ const afterStoreSetup = async ({ store, i18n }) => {
getTOS({ store }),
getInstancePanel({ store }),
getStickers({ store }),
- getNodeInfo({ store })
+ getNodeInfo({ store }),
+ getInstanceConfig({ store })
])
// Start fetching things that don't need to block the UI