2022-10-31 20:29:56 +00:00
|
|
|
import {computed, reactive, toRefs} from 'vue'
|
2022-09-21 00:21:22 +00:00
|
|
|
import {defineStore, acceptHMRUpdate} from 'pinia'
|
2022-07-20 22:42:36 +00:00
|
|
|
import {parseURL} from 'ufo'
|
|
|
|
|
2022-11-01 13:06:27 +00:00
|
|
|
import {HTTPFactory} from '@/helpers/fetcher'
|
2020-11-21 16:38:40 +00:00
|
|
|
import {objectToCamelCase} from '@/helpers/case'
|
2022-09-24 13:20:40 +00:00
|
|
|
|
2022-10-01 15:58:39 +00:00
|
|
|
import type {IProvider} from '@/types/IProvider'
|
2023-03-03 14:36:59 +00:00
|
|
|
import type {MIGRATORS} from '@/views/migrate/migrators'
|
2022-10-01 15:58:39 +00:00
|
|
|
|
2022-09-24 13:20:40 +00:00
|
|
|
export interface ConfigState {
|
|
|
|
version: string,
|
|
|
|
frontendUrl: string,
|
|
|
|
motd: string,
|
|
|
|
linkSharingEnabled: boolean,
|
2022-10-01 15:03:10 +00:00
|
|
|
maxFileSize: string,
|
2022-09-24 13:20:40 +00:00
|
|
|
registrationEnabled: boolean,
|
2023-03-03 14:36:59 +00:00
|
|
|
availableMigrators: Array<keyof typeof MIGRATORS>,
|
2022-09-24 13:20:40 +00:00
|
|
|
taskAttachmentsEnabled: boolean,
|
|
|
|
totpEnabled: boolean,
|
2023-03-03 14:36:59 +00:00
|
|
|
enabledBackgroundProviders: Array<'unsplash' | 'upload'>,
|
2022-09-24 13:20:40 +00:00
|
|
|
legal: {
|
|
|
|
imprintUrl: string,
|
|
|
|
privacyPolicyUrl: string,
|
|
|
|
},
|
|
|
|
caldavEnabled: boolean,
|
|
|
|
userDeletionEnabled: boolean,
|
|
|
|
taskCommentsEnabled: boolean,
|
2023-09-01 16:09:19 +00:00
|
|
|
demoModeEnabled: boolean,
|
2022-09-24 13:20:40 +00:00
|
|
|
auth: {
|
|
|
|
local: {
|
|
|
|
enabled: boolean,
|
|
|
|
},
|
|
|
|
openidConnect: {
|
|
|
|
enabled: boolean,
|
|
|
|
redirectUrl: string,
|
2022-10-01 15:58:39 +00:00
|
|
|
providers: IProvider[],
|
2022-09-24 13:20:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-05-08 18:43:51 +00:00
|
|
|
|
2022-10-31 20:29:56 +00:00
|
|
|
export const useConfigStore = defineStore('config', () => {
|
|
|
|
const state = reactive({
|
2020-05-08 18:43:51 +00:00
|
|
|
// These are the api defaults.
|
|
|
|
version: '',
|
|
|
|
frontendUrl: '',
|
|
|
|
motd: '',
|
|
|
|
linkSharingEnabled: true,
|
|
|
|
maxFileSize: '20MB',
|
|
|
|
registrationEnabled: true,
|
|
|
|
availableMigrators: [],
|
|
|
|
taskAttachmentsEnabled: true,
|
2020-05-29 16:49:50 +00:00
|
|
|
totpEnabled: true,
|
2020-05-31 19:17:10 +00:00
|
|
|
enabledBackgroundProviders: [],
|
2020-07-18 19:39:30 +00:00
|
|
|
legal: {
|
|
|
|
imprintUrl: '',
|
|
|
|
privacyPolicyUrl: '',
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2020-10-03 12:58:33 +00:00
|
|
|
caldavEnabled: false,
|
2021-08-11 19:08:18 +00:00
|
|
|
userDeletionEnabled: true,
|
2021-09-26 11:44:13 +00:00
|
|
|
taskCommentsEnabled: true,
|
2023-09-01 16:09:19 +00:00
|
|
|
demoModeEnabled: false,
|
2020-11-21 16:38:40 +00:00
|
|
|
auth: {
|
|
|
|
local: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
openidConnect: {
|
|
|
|
enabled: false,
|
|
|
|
redirectUrl: '',
|
|
|
|
providers: [],
|
|
|
|
},
|
|
|
|
},
|
2022-10-31 20:29:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const migratorsEnabled = computed(() => state.availableMigrators?.length > 0)
|
|
|
|
const apiBase = computed(() => {
|
|
|
|
const {host, protocol} = parseURL(window.API_URL)
|
|
|
|
return protocol + '//' + host
|
|
|
|
})
|
|
|
|
|
|
|
|
function setConfig(config: ConfigState) {
|
|
|
|
Object.assign(state, config)
|
|
|
|
}
|
2023-03-03 14:36:59 +00:00
|
|
|
async function update(): Promise<boolean> {
|
2022-10-31 20:29:56 +00:00
|
|
|
const HTTP = HTTPFactory()
|
|
|
|
const {data: config} = await HTTP.get('info')
|
2023-07-05 15:37:07 +00:00
|
|
|
if (typeof config.version === 'undefined') {
|
|
|
|
return false
|
|
|
|
}
|
2022-10-31 20:29:56 +00:00
|
|
|
setConfig(objectToCamelCase(config))
|
2023-03-03 14:36:59 +00:00
|
|
|
const success = !!config
|
|
|
|
return success
|
2022-10-31 20:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...toRefs(state),
|
|
|
|
|
|
|
|
migratorsEnabled,
|
|
|
|
apiBase,
|
|
|
|
setConfig,
|
|
|
|
update,
|
|
|
|
}
|
|
|
|
|
2022-09-21 00:21:22 +00:00
|
|
|
})
|
2022-07-21 16:45:58 +00:00
|
|
|
|
2022-09-21 00:21:22 +00:00
|
|
|
// support hot reloading
|
|
|
|
if (import.meta.hot) {
|
|
|
|
import.meta.hot.accept(acceptHMRUpdate(useConfigStore, import.meta.hot))
|
|
|
|
}
|