2018-02-17 20:22:52 +00:00
|
|
|
import axios from 'axios'
|
|
|
|
import logger from '@/logging'
|
2022-02-21 21:49:02 +00:00
|
|
|
import _ from 'lodash'
|
2018-02-17 20:22:52 +00:00
|
|
|
|
2018-08-11 12:20:08 +00:00
|
|
|
function getDefaultUrl () {
|
|
|
|
return (
|
|
|
|
window.location.protocol + '//' + window.location.hostname +
|
2019-01-17 11:17:29 +00:00
|
|
|
(window.location.port ? ':' + window.location.port : '') + '/'
|
2018-08-11 12:20:08 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-01-09 11:33:24 +00:00
|
|
|
function notifyServiceWorker (registration, message) {
|
|
|
|
if (registration && registration.active) {
|
|
|
|
registration.active.postMessage(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 20:22:52 +00:00
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
2018-03-01 23:13:45 +00:00
|
|
|
maxEvents: 200,
|
2018-07-26 17:51:55 +00:00
|
|
|
frontSettings: {},
|
2022-02-21 22:23:13 +00:00
|
|
|
instanceUrl: import.meta.env.VUE_APP_INSTANCE_URL,
|
2018-03-01 23:13:45 +00:00
|
|
|
events: [],
|
2019-01-17 11:17:29 +00:00
|
|
|
knownInstances: [],
|
2019-09-23 09:14:54 +00:00
|
|
|
nodeinfo: null,
|
2018-02-17 20:22:52 +00:00
|
|
|
settings: {
|
2018-02-24 14:28:09 +00:00
|
|
|
instance: {
|
|
|
|
name: {
|
|
|
|
value: ''
|
|
|
|
},
|
|
|
|
short_description: {
|
|
|
|
value: ''
|
|
|
|
},
|
|
|
|
long_description: {
|
|
|
|
value: ''
|
2019-09-23 09:30:25 +00:00
|
|
|
},
|
|
|
|
funkwhale_support_message_enabled: {
|
|
|
|
value: true
|
|
|
|
},
|
|
|
|
support_message: {
|
|
|
|
value: ''
|
2018-02-24 14:28:09 +00:00
|
|
|
}
|
|
|
|
},
|
2018-02-24 13:34:28 +00:00
|
|
|
users: {
|
|
|
|
registration_enabled: {
|
|
|
|
value: true
|
2018-09-06 18:35:02 +00:00
|
|
|
},
|
|
|
|
upload_quota: {
|
|
|
|
value: 0
|
2018-02-24 13:34:28 +00:00
|
|
|
}
|
|
|
|
},
|
2020-03-18 10:57:33 +00:00
|
|
|
moderation: {
|
|
|
|
signup_approval_enabled: {
|
2021-12-06 10:35:20 +00:00
|
|
|
value: false
|
2020-03-18 10:57:33 +00:00
|
|
|
},
|
2021-12-06 10:35:20 +00:00
|
|
|
signup_form_customization: { value: null }
|
2020-03-18 10:57:33 +00:00
|
|
|
},
|
2018-05-09 20:13:04 +00:00
|
|
|
subsonic: {
|
|
|
|
enabled: {
|
|
|
|
value: true
|
|
|
|
}
|
2021-12-06 10:35:20 +00:00
|
|
|
}
|
2018-02-17 20:22:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
settings: (state, value) => {
|
|
|
|
_.merge(state.settings, value)
|
2018-03-01 23:13:45 +00:00
|
|
|
},
|
|
|
|
event: (state, value) => {
|
|
|
|
state.events.unshift(value)
|
|
|
|
if (state.events.length > state.maxEvents) {
|
|
|
|
state.events = state.events.slice(0, state.maxEvents)
|
|
|
|
}
|
2018-03-25 15:36:02 +00:00
|
|
|
},
|
|
|
|
events: (state, value) => {
|
|
|
|
state.events = value
|
2018-06-23 05:24:34 +00:00
|
|
|
},
|
2019-09-23 09:14:54 +00:00
|
|
|
nodeinfo: (state, value) => {
|
|
|
|
state.nodeinfo = value
|
|
|
|
},
|
2018-07-26 17:51:55 +00:00
|
|
|
frontSettings: (state, value) => {
|
|
|
|
state.frontSettings = value
|
|
|
|
},
|
2018-06-23 05:24:34 +00:00
|
|
|
instanceUrl: (state, value) => {
|
2018-06-23 17:41:58 +00:00
|
|
|
if (value && !value.endsWith('/')) {
|
|
|
|
value = value + '/'
|
|
|
|
}
|
2018-06-23 05:24:34 +00:00
|
|
|
state.instanceUrl = value
|
2021-12-06 10:35:20 +00:00
|
|
|
notifyServiceWorker(state.registration, { command: 'serverChosen', serverUrl: state.instanceUrl })
|
2019-01-17 11:17:29 +00:00
|
|
|
// append the URL to the list (and remove existing one if needed)
|
|
|
|
if (value) {
|
2021-12-06 10:35:20 +00:00
|
|
|
const index = state.knownInstances.indexOf(value)
|
2019-01-17 11:17:29 +00:00
|
|
|
if (index > -1) {
|
2021-12-06 10:35:20 +00:00
|
|
|
state.knownInstances.splice(index, 1)
|
2019-01-17 11:17:29 +00:00
|
|
|
}
|
|
|
|
state.knownInstances.splice(0, 0, value)
|
|
|
|
}
|
2018-06-23 05:24:34 +00:00
|
|
|
if (!value) {
|
|
|
|
axios.defaults.baseURL = null
|
|
|
|
return
|
|
|
|
}
|
2021-12-06 10:35:20 +00:00
|
|
|
const suffix = 'api/v1/'
|
2018-06-23 17:41:58 +00:00
|
|
|
axios.defaults.baseURL = state.instanceUrl + suffix
|
2018-06-23 05:24:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getters: {
|
2018-08-11 12:20:08 +00:00
|
|
|
defaultUrl: (state) => () => {
|
|
|
|
return getDefaultUrl()
|
|
|
|
},
|
2018-06-23 05:24:34 +00:00
|
|
|
absoluteUrl: (state) => (relativeUrl) => {
|
|
|
|
if (relativeUrl.startsWith('http')) {
|
|
|
|
return relativeUrl
|
|
|
|
}
|
2018-06-24 12:34:27 +00:00
|
|
|
if (state.instanceUrl.endsWith('/') && relativeUrl.startsWith('/')) {
|
|
|
|
relativeUrl = relativeUrl.slice(1)
|
|
|
|
}
|
2018-08-11 12:20:08 +00:00
|
|
|
|
2021-12-06 10:35:20 +00:00
|
|
|
const instanceUrl = state.instanceUrl || getDefaultUrl()
|
2018-08-11 12:20:08 +00:00
|
|
|
return instanceUrl + relativeUrl
|
2020-02-05 14:06:07 +00:00
|
|
|
},
|
|
|
|
domain: (state) => {
|
2021-12-06 10:35:20 +00:00
|
|
|
const url = state.instanceUrl
|
|
|
|
const parser = document.createElement('a')
|
2020-02-05 14:06:07 +00:00
|
|
|
parser.href = url
|
|
|
|
return parser.hostname
|
2020-05-18 12:55:15 +00:00
|
|
|
},
|
|
|
|
appDomain: (state) => {
|
2022-05-05 18:40:03 +00:00
|
|
|
return location.hostname
|
2018-02-17 20:22:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2021-12-06 10:35:20 +00:00
|
|
|
setUrl ({ commit, dispatch }, url) {
|
2018-06-23 05:24:34 +00:00
|
|
|
commit('instanceUrl', url)
|
2021-12-06 10:35:20 +00:00
|
|
|
const modules = [
|
2018-06-23 05:24:34 +00:00
|
|
|
'auth',
|
|
|
|
'favorites',
|
2019-02-14 09:49:06 +00:00
|
|
|
'moderation',
|
2018-06-23 05:24:34 +00:00
|
|
|
'player',
|
|
|
|
'playlists',
|
|
|
|
'queue',
|
|
|
|
'radios'
|
|
|
|
]
|
|
|
|
modules.forEach(m => {
|
2021-12-06 10:35:20 +00:00
|
|
|
commit(`${m}/reset`, null, { root: true })
|
2018-06-23 05:24:34 +00:00
|
|
|
})
|
|
|
|
},
|
2019-03-15 14:52:30 +00:00
|
|
|
// Send a request to the login URL and save the returned JWT
|
2021-12-06 10:35:20 +00:00
|
|
|
fetchSettings ({ commit }, payload) {
|
2018-02-17 20:22:52 +00:00
|
|
|
return axios.get('instance/settings/').then(response => {
|
|
|
|
logger.default.info('Successfully fetched instance settings')
|
2021-12-06 10:35:20 +00:00
|
|
|
const sections = {}
|
2018-02-17 20:22:52 +00:00
|
|
|
response.data.forEach(e => {
|
|
|
|
sections[e.section] = {}
|
|
|
|
})
|
|
|
|
response.data.forEach(e => {
|
|
|
|
sections[e.section][e.name] = e
|
|
|
|
})
|
|
|
|
commit('settings', sections)
|
2018-02-24 13:55:08 +00:00
|
|
|
if (payload && payload.callback) {
|
2018-02-24 14:10:47 +00:00
|
|
|
payload.callback()
|
2018-02-24 13:34:28 +00:00
|
|
|
}
|
2018-02-17 20:22:52 +00:00
|
|
|
}, response => {
|
|
|
|
logger.default.error('Error while fetching settings', response.data)
|
|
|
|
})
|
2018-07-26 17:51:55 +00:00
|
|
|
},
|
2021-12-06 10:35:20 +00:00
|
|
|
fetchFrontSettings ({ commit }) {
|
2022-06-28 13:55:54 +00:00
|
|
|
return axios.get('/settings.json').then(response => {
|
2018-07-26 17:51:55 +00:00
|
|
|
commit('frontSettings', response.data)
|
|
|
|
}, response => {
|
|
|
|
logger.default.error('Error when fetching front-end configuration (or no customization available)')
|
|
|
|
})
|
2018-02-17 20:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|