forked from AkkomaGang/akkoma-fe
afterStoreSetup: refactor.
This commit is contained in:
parent
1387dfb889
commit
c030e62254
1 changed files with 128 additions and 112 deletions
|
@ -4,10 +4,10 @@ import routes from './routes'
|
||||||
|
|
||||||
import App from '../App.vue'
|
import App from '../App.vue'
|
||||||
|
|
||||||
const afterStoreSetup = ({ store, i18n }) => {
|
const getStatusnetConfig = async ({ store }) => {
|
||||||
window.fetch('/api/statusnet/config.json')
|
try {
|
||||||
.then((res) => res.json())
|
const res = await window.fetch('/api/statusnet/config.json')
|
||||||
.then((data) => {
|
const data = await res.json()
|
||||||
const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site
|
const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site
|
||||||
|
|
||||||
store.dispatch('setInstanceOption', { name: 'name', value: name })
|
store.dispatch('setInstanceOption', { name: 'name', value: name })
|
||||||
|
@ -28,16 +28,25 @@ const afterStoreSetup = ({ store, i18n }) => {
|
||||||
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
||||||
}
|
}
|
||||||
|
|
||||||
var apiConfig = data.site.pleromafe
|
return data.site.pleromafe
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Could not load statusnet config, potentially fatal')
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.fetch('/static/config.json')
|
const getStaticConfig = async () => {
|
||||||
.then((res) => res.json())
|
try {
|
||||||
.catch((err) => {
|
const res = await window.fetch('/static/config.json')
|
||||||
|
return res.json()
|
||||||
|
} catch (error) {
|
||||||
console.warn('Failed to load static/config.json, continuing without it.')
|
console.warn('Failed to load static/config.json, continuing without it.')
|
||||||
console.warn(err)
|
console.warn(error)
|
||||||
return {}
|
return {}
|
||||||
})
|
}
|
||||||
.then((staticConfig) => {
|
}
|
||||||
|
|
||||||
|
const setSettings = async ({ apiConfig, staticConfig, store }) => {
|
||||||
const overrides = window.___pleromafe_dev_overrides || {}
|
const overrides = window.___pleromafe_dev_overrides || {}
|
||||||
const env = window.___pleromafe_mode.NODE_ENV
|
const env = window.___pleromafe_mode.NODE_ENV
|
||||||
|
|
||||||
|
@ -89,13 +98,24 @@ const afterStoreSetup = ({ store, i18n }) => {
|
||||||
copyInstanceOption('noAttachmentLinks')
|
copyInstanceOption('noAttachmentLinks')
|
||||||
copyInstanceOption('showFeaturesPanel')
|
copyInstanceOption('showFeaturesPanel')
|
||||||
|
|
||||||
if (config.chatDisabled) {
|
if ((config.chatDisabled)) {
|
||||||
store.dispatch('disableChat')
|
store.dispatch('disableChat')
|
||||||
|
} else {
|
||||||
|
store.dispatch('initializeSocket')
|
||||||
}
|
}
|
||||||
|
|
||||||
return store.dispatch('setTheme', config['theme'])
|
return store.dispatch('setTheme', config['theme'])
|
||||||
})
|
}
|
||||||
.then(() => {
|
|
||||||
|
const afterStoreSetup = async ({ store, i18n }) => {
|
||||||
|
const apiConfig = await getStatusnetConfig({ store })
|
||||||
|
const staticConfig = await getStaticConfig()
|
||||||
|
await setSettings({ store, apiConfig, staticConfig })
|
||||||
|
// Now we have the server settings and can try logging in
|
||||||
|
if (store.state.oauth.token) {
|
||||||
|
store.dispatch('loginUser', store.state.oauth.token)
|
||||||
|
}
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
routes: routes(store),
|
routes: routes(store),
|
||||||
|
@ -115,8 +135,6 @@ const afterStoreSetup = ({ store, i18n }) => {
|
||||||
el: '#app',
|
el: '#app',
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
window.fetch('/static/terms-of-service.html')
|
window.fetch('/static/terms-of-service.html')
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
|
@ -157,7 +175,7 @@ const afterStoreSetup = ({ store, i18n }) => {
|
||||||
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
|
||||||
})
|
})
|
||||||
|
|
||||||
window.fetch('/nodeinfo/2.0.json')
|
return window.fetch('/nodeinfo/2.0.json')
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const metadata = data.metadata
|
const metadata = data.metadata
|
||||||
|
@ -167,8 +185,6 @@ const afterStoreSetup = ({ store, i18n }) => {
|
||||||
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
|
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
|
||||||
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
|
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
|
||||||
|
|
||||||
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
|
|
||||||
|
|
||||||
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
|
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
|
||||||
|
|
||||||
const suggestions = metadata.suggestions
|
const suggestions = metadata.suggestions
|
||||||
|
|
Loading…
Reference in a new issue