2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<ScreenBase>
|
|
|
|
|
<template #header>
|
|
|
|
|
<ScreenHeader>Settings</ScreenHeader>
|
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<p v-if="storageDriver !== 'local'" class="textk-text-secondary">
|
2024-02-23 09:32:54 +00:00
|
|
|
|
Since you’re not using a cloud storage, there’s no need to set a media path.
|
|
|
|
|
</p>
|
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<form v-else class="space-y-6" @submit.prevent="confirmThenSave">
|
|
|
|
|
<FormRow>
|
|
|
|
|
<template #label>Media Path</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<template #help>
|
|
|
|
|
<span id="mediaPathHelp">
|
|
|
|
|
The <em>absolute</em> path to the server directory containing your media.
|
|
|
|
|
Koel will scan this directory for songs and extract any available information.<br>
|
|
|
|
|
Scanning may take a while, especially if you have a lot of songs, so be patient.
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
|
<TextInput
|
2022-04-21 22:20:21 +00:00
|
|
|
|
v-model="mediaPath"
|
|
|
|
|
aria-describedby="mediaPathHelp"
|
2022-04-15 14:24:30 +00:00
|
|
|
|
name="media_path"
|
2024-04-04 22:20:42 +00:00
|
|
|
|
class="w-full md:!w-2/3"
|
|
|
|
|
/>
|
|
|
|
|
</FormRow>
|
|
|
|
|
|
|
|
|
|
<FormRow>
|
|
|
|
|
<div>
|
|
|
|
|
<Btn type="submit">Scan</Btn>
|
|
|
|
|
</div>
|
|
|
|
|
</FormRow>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</form>
|
2024-04-04 22:20:42 +00:00
|
|
|
|
</ScreenBase>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import { computed, ref } from 'vue'
|
2024-02-09 15:45:38 +00:00
|
|
|
|
import { commonStore, settingStore } from '@/stores'
|
2022-11-19 18:04:21 +00:00
|
|
|
|
import { forceReloadWindow, parseValidationError } from '@/utils'
|
|
|
|
|
import { useDialogBox, useMessageToaster, useOverlay, useRouter } from '@/composables'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
2024-04-04 22:20:42 +00:00
|
|
|
|
import Btn from '@/components/ui/form/Btn.vue'
|
|
|
|
|
import TextInput from '@/components/ui/form/TextInput.vue'
|
|
|
|
|
import ScreenBase from '@/components/screens/ScreenBase.vue'
|
|
|
|
|
import FormRow from '@/components/ui/form/FormRow.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-11-18 17:45:38 +00:00
|
|
|
|
const { toastSuccess } = useMessageToaster()
|
|
|
|
|
const { showConfirmDialog, showErrorDialog } = useDialogBox()
|
2022-11-18 18:44:20 +00:00
|
|
|
|
const { go } = useRouter()
|
2022-11-19 18:04:21 +00:00
|
|
|
|
const { showOverlay, hideOverlay } = useOverlay()
|
2022-10-08 10:54:25 +00:00
|
|
|
|
|
2024-02-09 15:45:38 +00:00
|
|
|
|
const storageDriver = ref(commonStore.state.storage_driver)
|
2022-04-21 22:20:21 +00:00
|
|
|
|
const mediaPath = ref(settingStore.state.media_path)
|
|
|
|
|
const originalMediaPath = mediaPath.value
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const shouldWarn = computed(() => {
|
|
|
|
|
// Warn the user if the media path is not empty and about to change.
|
2022-04-21 22:20:21 +00:00
|
|
|
|
if (!originalMediaPath || !mediaPath.value) {
|
2022-04-15 17:00:08 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2024-02-09 15:45:38 +00:00
|
|
|
|
if (storageDriver.value !== 'local') {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 22:20:21 +00:00
|
|
|
|
return originalMediaPath !== mediaPath.value.trim()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const save = async () => {
|
2022-11-19 21:59:56 +00:00
|
|
|
|
showOverlay({ message: 'Scanning…' })
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
try {
|
2022-04-21 22:20:21 +00:00
|
|
|
|
await settingStore.update({ media_path: mediaPath.value })
|
2022-11-18 17:45:38 +00:00
|
|
|
|
toastSuccess('Settings saved.')
|
2022-04-15 17:00:08 +00:00
|
|
|
|
// Make sure we're back to home first.
|
2022-11-18 18:44:20 +00:00
|
|
|
|
go('home')
|
2022-04-15 17:00:08 +00:00
|
|
|
|
forceReloadWindow()
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
const msg = err.response.status === 422 ? parseValidationError(err.response.data)[0] : 'Unknown error.'
|
2022-11-18 17:45:38 +00:00
|
|
|
|
showErrorDialog(msg, 'Error')
|
2022-04-21 22:20:21 +00:00
|
|
|
|
} finally {
|
|
|
|
|
hideOverlay()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-26 09:51:19 +00:00
|
|
|
|
const confirmThenSave = async () => {
|
2022-04-15 17:00:08 +00:00
|
|
|
|
if (shouldWarn.value) {
|
2024-02-09 15:45:38 +00:00
|
|
|
|
await showConfirmDialog('Changing the media path will essentially remove all existing local data – songs, artists, \
|
|
|
|
|
albums, favorites, etc. Sure you want to proceed?', 'Confirm')
|
2022-07-26 09:51:19 +00:00
|
|
|
|
&& await save()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
} else {
|
2022-07-26 09:51:19 +00:00
|
|
|
|
await save()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
2022-04-15 17:00:08 +00:00
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</script>
|