2022-07-04 22:52:53 +00:00
|
|
|
import type { InitModule } from '~/types'
|
|
|
|
|
|
2022-04-18 10:24:47 +02:00
|
|
|
import { watch } from 'vue'
|
2022-04-18 00:43:58 +02:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
2022-04-23 14:48:29 +02:00
|
|
|
export const install: InitModule = async ({ store, router }) => {
|
2022-04-18 20:39:30 +02:00
|
|
|
await store.dispatch('instance/fetchFrontSettings')
|
2022-04-18 00:43:58 +02:00
|
|
|
watch(() => store.state.instance.instanceUrl, async () => {
|
|
|
|
|
const [{ data }] = await Promise.all([
|
|
|
|
|
axios.get('instance/nodeinfo/2.0/'),
|
|
|
|
|
store.dispatch('instance/fetchSettings')
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
store.commit('instance/nodeinfo', data)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search)
|
|
|
|
|
const serverUrl = urlParams.get('_server')
|
|
|
|
|
if (serverUrl) {
|
|
|
|
|
store.commit('instance/instanceUrl', serverUrl)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const url = urlParams.get('_url')
|
|
|
|
|
if (url) {
|
2022-07-30 18:44:49 +00:00
|
|
|
router.replace(url)
|
|
|
|
|
return
|
2022-04-18 00:43:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!store.state.instance.instanceUrl) {
|
2022-06-12 10:23:25 +00:00
|
|
|
const defaultInstanceUrl = store.state.instance.frontSettings.defaultServerUrl
|
2022-04-18 00:43:58 +02:00
|
|
|
store.commit('instance/instanceUrl', defaultInstanceUrl)
|
|
|
|
|
} else {
|
2022-06-24 20:12:54 +00:00
|
|
|
// NOTE: Needed to trigger initialization of axios / service worker / web socket
|
|
|
|
|
// TODO (wvffle): Check if it is really needed
|
2022-04-18 00:43:58 +02:00
|
|
|
store.commit('instance/instanceUrl', store.state.instance.instanceUrl)
|
|
|
|
|
}
|
|
|
|
|
}
|