Add suno mp4 (#261)
This commit is contained in:
1 parent
b7a68e4656
commit
665b26d5fb
79 files changed
+2340
-1526
No files matched your search
@@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="flex-1 overflow-y-auto p-[15px]">
|
||||
<action-selector class="mb-4" />
|
||||
<prompt-input class="mb-4" />
|
||||
<image-url-input v-if="config?.action === 'edits'" class="mb-4" />
|
||||
<model-selector class="mb-4" />
|
||||
<count-selector class="mb-4" />
|
||||
</div>
|
||||
@@ -21,6 +23,8 @@ import { ElButton } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import ModelSelector from './config/ModelSelector.vue';
|
||||
import CountSelector from './config/CountSelector.vue';
|
||||
import ActionSelector from './config/ActionSelector.vue';
|
||||
import ImageUrlInput from './config/ImageUrlInput.vue';
|
||||
import PromptInput from './config/PromptInput.vue';
|
||||
import Consumption from '../common/Consumption.vue';
|
||||
import { getConsumption } from '@/utils';
|
||||
@@ -33,7 +37,9 @@ export default defineComponent({
|
||||
PromptInput,
|
||||
ModelSelector,
|
||||
CountSelector,
|
||||
Consumption
|
||||
Consumption,
|
||||
ActionSelector,
|
||||
ImageUrlInput
|
||||
},
|
||||
emits: ['generate'],
|
||||
computed: {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<template>
|
||||
<div class="field">
|
||||
<h2 class="title font-bold">{{ $t('flux.name.task') }}</h2>
|
||||
<el-select v-model="value" class="value" :placeholder="$t('flux.placeholder.select')">
|
||||
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSelect, ElOption } from 'element-plus';
|
||||
import { FLUX_DEFAULT_ACTION } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ActionSelector',
|
||||
components: {
|
||||
ElSelect,
|
||||
ElOption
|
||||
},
|
||||
props: {
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
emits: ['update:modelValue'],
|
||||
data() {
|
||||
return {
|
||||
options: [
|
||||
{
|
||||
value: 'generate',
|
||||
label: this.$t('flux.name.generate')
|
||||
},
|
||||
{
|
||||
value: 'edits',
|
||||
label: this.$t('flux.name.edits')
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
value: {
|
||||
get() {
|
||||
return this.$store.state.flux?.config?.action;
|
||||
},
|
||||
set(val: string) {
|
||||
this.$store.commit('flux/setConfig', {
|
||||
...this.$store.state.flux.config,
|
||||
action: val
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = FLUX_DEFAULT_ACTION;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.value {
|
||||
width: 160px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<div class="relative">
|
||||
<div class="flex justify-between">
|
||||
<div class="flex justify-start items-center">
|
||||
<span class="text-sm font-bold">{{ $t('flux.name.imageUrl') }}</span>
|
||||
<info-icon :content="$t('flux.description.imageUrl')" />
|
||||
</div>
|
||||
</div>
|
||||
<el-upload
|
||||
v-model:file-list="fileList"
|
||||
name="file"
|
||||
:limit="5"
|
||||
class="upload-wrapper"
|
||||
accept=".png,.jpg,.jpeg,.gif,.bmp,.webp"
|
||||
:multiple="true"
|
||||
list-type="picture"
|
||||
:action="uploadUrl"
|
||||
:on-exceed="onExceed"
|
||||
:on-error="onError"
|
||||
:headers="headers"
|
||||
>
|
||||
<template #file="{ file }">
|
||||
<image-preview
|
||||
:url="file.url || (file.response as any)?.file_url"
|
||||
:name="file.name"
|
||||
:percentage="file.percentage"
|
||||
@remove="fileList.splice(fileList.indexOf(file), 1)"
|
||||
/>
|
||||
</template>
|
||||
<el-button round type="primary" size="small" class="btn btn-upload">
|
||||
<font-awesome-icon icon="fa-solid fa-upload" class="icon mr-1" />
|
||||
{{ $t('flux.button.uploadImageUrl') }}
|
||||
</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 ImagePreview from '@/components/common/ImagePreview.vue';
|
||||
|
||||
interface IData {
|
||||
fileList: UploadFiles;
|
||||
uploadUrl: string;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ImageUrlInput',
|
||||
components: {
|
||||
ElUpload,
|
||||
ElButton,
|
||||
InfoIcon,
|
||||
FontAwesomeIcon,
|
||||
ImagePreview
|
||||
},
|
||||
emits: ['change'],
|
||||
data(): IData {
|
||||
return {
|
||||
fileList: [],
|
||||
uploadUrl: getBaseUrlPlatform() + '/api/v1/files/'
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
headers() {
|
||||
return {
|
||||
Authorization: `Bearer ${this.$store.state.token.access}`
|
||||
};
|
||||
},
|
||||
urls() {
|
||||
// @ts-ignore
|
||||
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
urls: {
|
||||
handler(val) {
|
||||
console.debug('URLs changed:', val);
|
||||
this.$store.commit('flux/setConfig', {
|
||||
...this.$store.state.flux.config,
|
||||
image_url: val[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onExceed() {
|
||||
ElMessage.warning(this.$t('flux.message.uploadStartImageExceed'));
|
||||
},
|
||||
onError() {
|
||||
ElMessage.error(this.$t('flux.message.uploadStartImageError'));
|
||||
}
|
||||
}
|
||||
});
|
||||
</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>
|
||||
@@ -37,14 +37,6 @@
|
||||
<el-button v-if="audio?.audio_url" size="small" round @click.stop="onExtend($event, audio)">{{
|
||||
$t('suno.button.extend')
|
||||
}}</el-button>
|
||||
<el-tooltip effect="dark" :content="$t('suno.button.video')" placement="top">
|
||||
<font-awesome-icon
|
||||
v-if="audio?.video_url"
|
||||
icon="fa-solid fa-clapperboard"
|
||||
class="icon icon-preview"
|
||||
@click="onPreview($event, audio?.video_url)"
|
||||
/>
|
||||
</el-tooltip>
|
||||
<el-dropdown>
|
||||
<span class="el-dropdown-link">
|
||||
<el-tooltip effect="dark" :content="$t('suno.button.download')" placement="top">
|
||||
@@ -57,8 +49,13 @@
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-if="audio?.video_url" @click.stop="onDownload($event, audio?.video_url)">
|
||||
{{ $t('suno.button.download_video') }}
|
||||
<el-dropdown-item :disabled="isFetchingVideoUrl" @click="handleVideoDownload(audio)">
|
||||
<div class="flex items-center min-w-[120px]">
|
||||
<el-icon v-if="isFetchingVideoUrl" class="is-loading mr-2">
|
||||
<Loading />
|
||||
</el-icon>
|
||||
<span>{{ $t('suno.button.download_video') }}</span>
|
||||
</div>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="audio?.audio_url" @click.stop="onDownload($event, audio?.audio_url)">
|
||||
{{ $t('suno.button.download_audio') }}
|
||||
@@ -109,8 +106,9 @@ import {
|
||||
ElDropdownItem,
|
||||
ElMessage
|
||||
} from 'element-plus';
|
||||
import { Loading } from '@element-plus/icons-vue';
|
||||
import { VideoPlay, VideoPause } from '@element-plus/icons-vue';
|
||||
import { ISunoAudioRequest, Status } from '@/models';
|
||||
import { ISunoMp4Request, ISunoAudioRequest, Status } from '@/models';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { sunoOperator } from '@/operators';
|
||||
@@ -129,7 +127,8 @@ export default defineComponent({
|
||||
VideoPause,
|
||||
ElDropdown,
|
||||
ElDropdownMenu,
|
||||
ElDropdownItem
|
||||
ElDropdownItem,
|
||||
Loading
|
||||
},
|
||||
props: {
|
||||
modelValue: {
|
||||
@@ -138,7 +137,9 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {};
|
||||
return {
|
||||
isFetchingVideoUrl: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
@@ -209,8 +210,10 @@ export default defineComponent({
|
||||
continue_at: audio.duration
|
||||
});
|
||||
},
|
||||
onDownload(event: MouseEvent, audioUrl: string) {
|
||||
event.stopPropagation();
|
||||
onDownload(event: MouseEvent | null, audioUrl: string) {
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
console.log('on download', audioUrl);
|
||||
const parsedUrl = new URL(audioUrl);
|
||||
const pathname = parsedUrl.pathname;
|
||||
@@ -224,6 +227,54 @@ export default defineComponent({
|
||||
// download url here
|
||||
// window.open(audioUrl, '_blank');
|
||||
},
|
||||
async handleVideoDownload(audio: ISunoAudio) {
|
||||
if (audio.video_url) {
|
||||
this.onDownload(null, audio.video_url);
|
||||
return;
|
||||
}
|
||||
if (this.isFetchingVideoUrl) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.isFetchingVideoUrl = true;
|
||||
// @ts-ignore
|
||||
const videoUrl = await this.fetchVideoUrlFromApi(audio?.id);
|
||||
console.log(`get videoUrl: ${videoUrl}`);
|
||||
audio.video_url = videoUrl;
|
||||
this.onDownload(null, videoUrl);
|
||||
} catch (error) {
|
||||
console.error('get videoUrl failed:', error);
|
||||
ElMessage.error(this.$t('suno.message.getVideoUrlFailed'));
|
||||
} finally {
|
||||
this.isFetchingVideoUrl = false;
|
||||
}
|
||||
},
|
||||
async fetchVideoUrlFromApi(audioId: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = {
|
||||
audio_id: audioId
|
||||
} as ISunoMp4Request;
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
console.error('no token specified');
|
||||
reject(new Error('No token specified'));
|
||||
return;
|
||||
}
|
||||
sunoOperator
|
||||
.mp4(request, { token })
|
||||
.then((response) => {
|
||||
const videoUrl = response.data?.data?.video_url;
|
||||
if (videoUrl) {
|
||||
resolve(videoUrl);
|
||||
} else {
|
||||
reject(new Error('Video URL not found in response'));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
onPreview(event: MouseEvent, videoUrl: string) {
|
||||
event.stopPropagation();
|
||||
console.log('on preview', videoUrl);
|
||||
|
||||
Reference in new issue
Block a user