Add suno upload (#164)

This commit is contained in:
HCode authored and GitHub committed 2025-01-20 13:08:51 +08:00
1 parent ea8a77b010
commit f0e5ec6f5e
59 files changed
+1334 -747

No files matched your search

+3 -9
View File
@@ -2,7 +2,7 @@
<div class="panel">
<div class="config">
<type-selector class="mb-4" />
<instrument-switch class="mb-4 instrument" />
<upload-audio class="mb-4" />
<prompt-input v-if="!config?.custom" class="mb-4" />
<lyric-input v-if="config?.custom && !config.instrumental" class="mb-4" />
<style-input v-if="config?.custom" class="mb-4" />
@@ -26,12 +26,12 @@
import { defineComponent } from 'vue';
import { ElButton } from 'element-plus';
import TypeSelector from './config/TypeSelector.vue';
import UploadAudio from './config/UploadAudio.vue';
import PromptInput from './config/PromptInput.vue';
import LyricInput from './config/LyricInput.vue';
import StyleInput from './config/StyleInput.vue';
import TitleInput from './config/TitleInput.vue';
import ExtendFromInput from './config/ExtendFromInput.vue';
import InstrumentSwitch from './config/InstrumentSwitch.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
@@ -40,10 +40,10 @@ export default defineComponent({
TypeSelector,
PromptInput,
LyricInput,
InstrumentSwitch,
StyleInput,
TitleInput,
ExtendFromInput,
UploadAudio,
FontAwesomeIcon,
ElButton
},
@@ -72,12 +72,6 @@ export default defineComponent({
height: calc(100% - 50px);
flex: 1;
position: relative;
.instrument {
position: absolute;
top: 50px;
right: -10px;
z-index: 1000;
}
}
.actions {
height: 50px;
@@ -1,61 +0,0 @@
<template>
<div class="field">
<el-switch v-model="instrumental" class="value mr-2" />
<h2 class="title inline-block">{{ $t('suno.name.instrumental') }}</h2>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSwitch } from 'element-plus';
export const DEFAULT_INSTRUMENTAL = false;
export default defineComponent({
name: 'InstrumentSwitch',
components: {
ElSwitch
},
data() {
return {};
},
computed: {
instrumental: {
get() {
return this.$store.state.suno?.config?.instrumental;
},
set(val) {
console.debug('set instrumental', val);
this.$store.commit('suno/setConfig', {
...this.$store.state.suno?.config,
instrumental: val
});
}
}
},
mounted() {
if (this.instrumental === undefined) {
this.instrumental = DEFAULT_INSTRUMENTAL;
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
width: 120px;
.title {
font-size: 14px;
margin: 0;
flex: 1;
}
.value {
width: 50px;
}
}
</style>
+20 -3
View File
@@ -1,9 +1,16 @@
<template>
<div class="field">
<div class="box">
<h2 class="title">{{ $t('suno.name.prompt') }}</h2>
<info-icon :content="$t('suno.description.prompt')" class="info" />
<div class="title-info">
<h2 class="title">{{ $t('suno.name.prompt') }}</h2>
<info-icon :content="$t('suno.description.prompt')" class="info" />
</div>
<div class="instrumental">
<el-switch v-model="instrumental" class="value mr-2" />
<h2 class="title inline-block">{{ $t('suno.name.instrumental') }}</h2>
</div>
</div>
<el-input
v-model="prompt"
:rows="3"
@@ -18,7 +25,7 @@
<script>
import { defineComponent } from 'vue';
import { ElInput } from 'element-plus';
import { ElInput, ElSwitch } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
export const DEFAULT_PROMPT = '';
@@ -27,6 +34,7 @@ export default defineComponent({
name: 'PromptInput',
components: {
ElInput,
ElSwitch,
InfoIcon
},
data() {
@@ -60,7 +68,16 @@ export default defineComponent({
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
position: relative;
.title-info {
display: flex;
align-items: center;
}
.instrumental {
right: 10px;
z-index: 1000;
}
.title {
font-size: 14px;
margin-bottom: 10px;
+166
View File
@@ -0,0 +1,166 @@
<template>
<div class="relative">
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('suno.name.referenceAudios') }}</span>
<info-icon :content="$t('suno.description.uploadAudios')" />
</div>
</div>
<el-upload
v-model:file-list="fileList"
name="file"
:limit="1"
class="upload-wrapper"
:action="uploadUrl"
accept=".mp3"
:show-file-list="true"
:on-exceed="onExceed"
:on-error="onError"
:on-success="onSuccess"
:headers="headers"
>
<el-button round type="primary" size="small" class="btn btn-upload">
<font-awesome-icon icon="fa-solid fa-upload" class="icon mr-1" />
{{ $t('suno.button.uploadAudios') }}
</el-button>
</el-upload>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElUpload, ElButton, UploadFiles, UploadFile, ElMessage } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { getBaseUrlPlatform } from '@/utils';
import InfoIcon from '@/components/common/InfoIcon.vue';
import { ISunoUploadRequest } from '@/models';
import { sunoOperator } from '@/operators';
interface IData {
fileList: UploadFiles;
uploadUrl: string;
}
export default defineComponent({
name: 'UploadAudio',
components: {
ElUpload,
ElButton,
InfoIcon,
FontAwesomeIcon
},
emits: ['change'],
data(): IData {
return {
fileList: [],
uploadUrl: getBaseUrlPlatform() + '/api/v1/files/'
};
},
computed: {
headers() {
return {
Authorization: `Bearer ${this.$store.state.token.access}`
};
},
credential() {
return this.$store.state.suno.credential;
},
config() {
return this.$store.state.suno.config;
},
urls() {
// @ts-ignore
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
},
value: {
get() {
return this.$store.state.suno?.config?.audio_id;
},
set(val: string[]) {}
}
},
watch: {
urls: {
handler(val) {
this.$emit('change', val);
}
}
},
mounted() {
if (!this.value) {
this.value = undefined;
}
this.onSetAudio();
},
methods: {
onExceed() {
ElMessage.warning(this.$t('suno.message.uploadReferencesExceed'));
},
onError() {
ElMessage.error(this.$t('suno.message.uploadReferencesError'));
},
async onSuccess() {
const url = this.urls?.[0];
await this.onGenerateAudioId(url);
},
async onGenerateAudioId(audio_url: string) {
const request = {
audio_url
} as ISunoUploadRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.info(this.$t('suno.message.startingUploadAudio'));
sunoOperator
.upload(request, {
token
})
.then((response) => {
console.debug('get upload music success', response.data);
const audio_id = response.data?.data.audio_id;
this.$store.commit('suno/setConfig', {
...this.$store.state.suno?.config,
audio_id: audio_id,
action: 'upload_extend'
});
ElMessage.success(this.$t('suno.message.startUploadAudioSuccess'));
})
.catch((error) => {
ElMessage.error(error?.response?.data?.error?.message || this.$t('suno.message.startUploadAudioFailed'));
});
},
onSetAudio() {
// const url = this.urls?.[0];
// this.$store.commit('suno/setConfig', {
// ...this.$store.state.suno?.config,
// audio_id: url
// });
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 14px;
margin-bottom: 0;
width: 30%;
}
.btn.btn-upload {
position: absolute;
top: 5px;
right: 0;
}
</style>
<style lang="scss">
.upload-wrapper {
height: auto;
display: flex;
.el-upload-list {
margin: 0;
width: 100%;
}
}
</style>