fix(upload): use the selected channel for the file upload in channel upload form

This commit is contained in:
upsiflu 2025-03-14 12:54:43 +01:00
parent e9ea8d6299
commit 681f3fced0
2 changed files with 21 additions and 14 deletions

View File

@ -66,7 +66,11 @@ const store = useStore()
const errors = ref([] as string[])
const values = reactive({
const values = reactive<{
channel: string; // Channel UUID
license: unknown;
album: unknown;
}>({
channel: props.channel?.uuid ?? null,
license: null,
album: null
@ -108,9 +112,9 @@ const isLoading = ref(false)
const selectedChannel = computed(() =>
props.channel
? props.channel
: availableChannels.value.count === 0
: availableChannels.value.length === 0
? (createEmptyChannel(), null)
: availableChannels.value.count === 1
: availableChannels.value.length === 1
? availableChannels.value[0]
: availableChannels.value.find(({ artist }) => artist.id === channelDropdownId.value)
)
@ -224,12 +228,6 @@ const beforeFileUpload = (newFile: VueUploadItem) => {
}
}
const baseImportMetadata = computed(() => ({
channel: values.channel,
import_status: 'draft',
import_metadata: { license: values.license, album: values.album }
}))
//
// Uploaded files
//
@ -561,7 +559,7 @@ ChannelCreateRequest: {
</select>
</div>
<album-select
v-if="selectedChannel && albumSelection"
v-if="selectedChannel && albumSelection && albumSelection.albums.length > 0"
v-model="albumSelection"
:class="['ui', 'field']"
/>
@ -697,11 +695,12 @@ ChannelCreateRequest: {
{{ t('components.channels.UploadForm.description.extensions', {extensions: store.state.ui.supportedExtensions.join(', ')}) }}
</Layout>
</Alert>
<file-upload-widget
<FileUploadWidget
v-if="selectedChannel && selectedChannel.uuid"
ref="upload"
v-model="files"
:class="['ui', 'button', 'channels']"
:data="baseImportMetadata"
:channel="selectedChannel.uuid"
@input-file="beforeFileUpload"
>
<div>
@ -719,6 +718,6 @@ ChannelCreateRequest: {
class="divider"
:size="32"
/>
</file-upload-widget>
</FileUploadWidget>
</Layout>
</template>

View File

@ -1,12 +1,18 @@
<script setup lang="ts">
import type { VueUploadItem } from 'vue-upload-component'
import type { components } from '~/generated/types'
import { useCookies } from '@vueuse/integrations/useCookies'
import { computed, ref, watch, getCurrentInstance } from 'vue'
import { useStore } from '~/store'
import FileUpload from 'vue-upload-component'
const props = defineProps<{
channel: components['schemas']['Channel']['uuid'];
}>()
const { get } = useCookies()
const instance = getCurrentInstance()
const attrs = instance?.attrs ?? {}
@ -36,13 +42,15 @@ const patchFileData = (file: VueUploadItem, data: Record<string, unknown> = {})
if (metadata) {
metadata = { ...metadata }
if (data.channel && !metadata.title) {
if (!('title' in metadata)) {
metadata.title = filename.replace(/\.[^/.]+$/, '')
}
data.import_metadata = JSON.stringify(metadata)
}
data.channel = props.channel
return data
}