afterStoreSetup: refactor.
This commit is contained in:
parent
1387dfb889
commit
c030e62254
1 changed files with 128 additions and 112 deletions
|
@ -4,119 +4,137 @@ 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 })
|
||||||
store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') })
|
store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') })
|
||||||
store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) })
|
store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) })
|
||||||
store.dispatch('setInstanceOption', { name: 'server', value: server })
|
store.dispatch('setInstanceOption', { name: 'server', value: server })
|
||||||
|
|
||||||
// TODO: default values for this stuff, added if to not make it break on
|
// TODO: default values for this stuff, added if to not make it break on
|
||||||
// my dev config out of the box.
|
// my dev config out of the box.
|
||||||
if (uploadlimit) {
|
if (uploadlimit) {
|
||||||
store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) })
|
store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) })
|
||||||
store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) })
|
store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) })
|
||||||
store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) })
|
store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) })
|
||||||
store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) })
|
store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vapidPublicKey) {
|
||||||
|
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.site.pleromafe
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Could not load statusnet config, potentially fatal')
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getStaticConfig = async () => {
|
||||||
|
try {
|
||||||
|
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(error)
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const setSettings = async ({ apiConfig, staticConfig, store }) => {
|
||||||
|
const overrides = window.___pleromafe_dev_overrides || {}
|
||||||
|
const env = window.___pleromafe_mode.NODE_ENV
|
||||||
|
|
||||||
|
// This takes static config and overrides properties that are present in apiConfig
|
||||||
|
let config = {}
|
||||||
|
if (overrides.staticConfigPreference && env === 'development') {
|
||||||
|
console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG')
|
||||||
|
config = Object.assign({}, apiConfig, staticConfig)
|
||||||
|
} else {
|
||||||
|
config = Object.assign({}, staticConfig, apiConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyInstanceOption = (name) => {
|
||||||
|
store.dispatch('setInstanceOption', { name, value: config[name] })
|
||||||
|
}
|
||||||
|
|
||||||
|
copyInstanceOption('nsfwCensorImage')
|
||||||
|
copyInstanceOption('background')
|
||||||
|
copyInstanceOption('hidePostStats')
|
||||||
|
copyInstanceOption('hideUserStats')
|
||||||
|
copyInstanceOption('hideFilteredStatuses')
|
||||||
|
copyInstanceOption('logo')
|
||||||
|
|
||||||
|
store.dispatch('setInstanceOption', {
|
||||||
|
name: 'logoMask',
|
||||||
|
value: typeof config.logoMask === 'undefined'
|
||||||
|
? true
|
||||||
|
: config.logoMask
|
||||||
|
})
|
||||||
|
|
||||||
|
store.dispatch('setInstanceOption', {
|
||||||
|
name: 'logoMargin',
|
||||||
|
value: typeof config.logoMargin === 'undefined'
|
||||||
|
? 0
|
||||||
|
: config.logoMargin
|
||||||
|
})
|
||||||
|
|
||||||
|
copyInstanceOption('redirectRootNoLogin')
|
||||||
|
copyInstanceOption('redirectRootLogin')
|
||||||
|
copyInstanceOption('showInstanceSpecificPanel')
|
||||||
|
copyInstanceOption('scopeOptionsEnabled')
|
||||||
|
copyInstanceOption('formattingOptionsEnabled')
|
||||||
|
copyInstanceOption('collapseMessageWithSubject')
|
||||||
|
copyInstanceOption('loginMethod')
|
||||||
|
copyInstanceOption('scopeCopy')
|
||||||
|
copyInstanceOption('subjectLineBehavior')
|
||||||
|
copyInstanceOption('postContentType')
|
||||||
|
copyInstanceOption('alwaysShowSubjectInput')
|
||||||
|
copyInstanceOption('noAttachmentLinks')
|
||||||
|
copyInstanceOption('showFeaturesPanel')
|
||||||
|
|
||||||
|
if ((config.chatDisabled)) {
|
||||||
|
store.dispatch('disableChat')
|
||||||
|
} else {
|
||||||
|
store.dispatch('initializeSocket')
|
||||||
|
}
|
||||||
|
|
||||||
|
return store.dispatch('setTheme', config['theme'])
|
||||||
|
}
|
||||||
|
|
||||||
|
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({
|
||||||
|
mode: 'history',
|
||||||
|
routes: routes(store),
|
||||||
|
scrollBehavior: (to, _from, savedPosition) => {
|
||||||
|
if (to.matched.some(m => m.meta.dontScroll)) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
return savedPosition || { x: 0, y: 0 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (vapidPublicKey) {
|
/* eslint-disable no-new */
|
||||||
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
|
new Vue({
|
||||||
}
|
router,
|
||||||
|
store,
|
||||||
var apiConfig = data.site.pleromafe
|
i18n,
|
||||||
|
el: '#app',
|
||||||
window.fetch('/static/config.json')
|
render: h => h(App)
|
||||||
.then((res) => res.json())
|
})
|
||||||
.catch((err) => {
|
|
||||||
console.warn('Failed to load static/config.json, continuing without it.')
|
|
||||||
console.warn(err)
|
|
||||||
return {}
|
|
||||||
})
|
|
||||||
.then((staticConfig) => {
|
|
||||||
const overrides = window.___pleromafe_dev_overrides || {}
|
|
||||||
const env = window.___pleromafe_mode.NODE_ENV
|
|
||||||
|
|
||||||
// This takes static config and overrides properties that are present in apiConfig
|
|
||||||
let config = {}
|
|
||||||
if (overrides.staticConfigPreference && env === 'development') {
|
|
||||||
console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG')
|
|
||||||
config = Object.assign({}, apiConfig, staticConfig)
|
|
||||||
} else {
|
|
||||||
config = Object.assign({}, staticConfig, apiConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
const copyInstanceOption = (name) => {
|
|
||||||
store.dispatch('setInstanceOption', {name, value: config[name]})
|
|
||||||
}
|
|
||||||
|
|
||||||
copyInstanceOption('nsfwCensorImage')
|
|
||||||
copyInstanceOption('background')
|
|
||||||
copyInstanceOption('hidePostStats')
|
|
||||||
copyInstanceOption('hideUserStats')
|
|
||||||
copyInstanceOption('hideFilteredStatuses')
|
|
||||||
copyInstanceOption('logo')
|
|
||||||
|
|
||||||
store.dispatch('setInstanceOption', {
|
|
||||||
name: 'logoMask',
|
|
||||||
value: typeof config.logoMask === 'undefined'
|
|
||||||
? true
|
|
||||||
: config.logoMask
|
|
||||||
})
|
|
||||||
|
|
||||||
store.dispatch('setInstanceOption', {
|
|
||||||
name: 'logoMargin',
|
|
||||||
value: typeof config.logoMargin === 'undefined'
|
|
||||||
? 0
|
|
||||||
: config.logoMargin
|
|
||||||
})
|
|
||||||
|
|
||||||
copyInstanceOption('redirectRootNoLogin')
|
|
||||||
copyInstanceOption('redirectRootLogin')
|
|
||||||
copyInstanceOption('showInstanceSpecificPanel')
|
|
||||||
copyInstanceOption('scopeOptionsEnabled')
|
|
||||||
copyInstanceOption('formattingOptionsEnabled')
|
|
||||||
copyInstanceOption('collapseMessageWithSubject')
|
|
||||||
copyInstanceOption('loginMethod')
|
|
||||||
copyInstanceOption('scopeCopy')
|
|
||||||
copyInstanceOption('subjectLineBehavior')
|
|
||||||
copyInstanceOption('postContentType')
|
|
||||||
copyInstanceOption('alwaysShowSubjectInput')
|
|
||||||
copyInstanceOption('noAttachmentLinks')
|
|
||||||
copyInstanceOption('showFeaturesPanel')
|
|
||||||
|
|
||||||
if (config.chatDisabled) {
|
|
||||||
store.dispatch('disableChat')
|
|
||||||
}
|
|
||||||
|
|
||||||
return store.dispatch('setTheme', config['theme'])
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
const router = new VueRouter({
|
|
||||||
mode: 'history',
|
|
||||||
routes: routes(store),
|
|
||||||
scrollBehavior: (to, _from, savedPosition) => {
|
|
||||||
if (to.matched.some(m => m.meta.dontScroll)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return savedPosition || { x: 0, y: 0 }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
|
||||||
new Vue({
|
|
||||||
router,
|
|
||||||
store,
|
|
||||||
i18n,
|
|
||||||
el: '#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