Add SUNO support (#82)

Co-authored-by: Germey <germey@acedata.cloud>
This commit is contained in:
HCodeandGermey authored and GitHub committed 2024-07-27 18:34:43 +00:00
1 parent ffdf6cbbdf
commit a46fc4ef3c
237 files changed
+9933 -4641

No files matched your search

+5 -3
View File
@@ -33,15 +33,15 @@
</el-table-column>
<el-table-column :label="$t('distribution.field.price')" width="100px">
<template #default="scope">
<span class="price">¥{{ scope.row?.price?.toFixed(2) }}</span>
<span class="price">{{ getPriceString({ value: scope.row?.price }) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.reward')" width="100px">
<template #default="scope">
<span class="description">¥{{ scope.row?.reward?.toFixed(2) }}</span>
<span class="description">{{ getPriceString({ value: scope.row?.reward }) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('distribution.field.percentage')" width="100px">
<el-table-column :label="$t('distribution.field.percentage')" width="120px">
<template #default="scope">
<span class="description">{{ scope.row.percentage }}%</span>
</template>
@@ -73,6 +73,7 @@ import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { ElRow, ElCol, ElTable, ElTableColumn, ElCard } from 'element-plus';
import { distributionHistoryOperator } from '@/operators/distribution';
import { IDistributionHistory, IDistributionStatus } from '@/models';
import { getPriceString } from '@/utils';
interface IData {
distributionHistories: IDistributionHistory[];
@@ -121,6 +122,7 @@ export default defineComponent({
this.onFetchData();
},
methods: {
getPriceString,
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
+6 -7
View File
@@ -23,16 +23,16 @@
<span class="description">{{ scope.row?.username }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.email')" width="300px">
<template #default="scope">
<span class="description">{{ scope.row?.email }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.nickname')" width="200px">
<template #default="scope">
<span class="description">{{ scope.row.nickname }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('user.field.isVerified')">
<template #default="scope">
<el-switch :model-value="scope.row?.is_verified" />
</template>
</el-table-column>
<el-table-column :label="$t('user.field.dateJoined')">
<template #default="scope">
<span class="created-at">{{ $dayjs.format(scope.row.date_joined) }}</span>
@@ -57,7 +57,7 @@
import { defineComponent } from 'vue';
import Pagination from '@/components/common/Pagination.vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { ElRow, ElCol, ElTable, ElTableColumn, ElCard, ElSwitch } from 'element-plus';
import { ElRow, ElCol, ElTable, ElTableColumn, ElCard } from 'element-plus';
import { userOperator } from '@/operators';
import { IUser } from '@/models';
@@ -74,7 +74,6 @@ export default defineComponent({
Pagination,
CopyToClipboard,
ElRow,
ElSwitch,
ElCol,
ElTable,
ElTableColumn,
+14 -6
View File
@@ -142,7 +142,6 @@
</div>
</div>
<div
v-if="false"
id="suno"
class="block"
@click="
@@ -161,8 +160,8 @@
</el-button>
</el-col>
<el-col :md="16" :xs="24" class="preview">
<img class="image desktop" />
<img class="image mobile" />
<img src="https://cdn.acedata.cloud/2m8fn.png" class="image desktop" />
<img src="https://cdn.acedata.cloud/23knvs.png" class="image mobile" />
</el-col>
</el-row>
</div>
@@ -279,6 +278,15 @@ export default defineComponent({
icon: 'fa-solid fa-qrcode'
}
]
: []),
...(this.site?.features?.suno?.enabled
? [
{
title: this.$t('index.title.suno'),
subtitle: this.$t('index.subtitle.suno'),
icon: 'fa-solid fa-music'
}
]
: [])
];
}
@@ -364,9 +372,9 @@ export default defineComponent({
font-weight: bold;
margin-bottom: 50px;
text-align: left;
-webkit-text-fill-color: transparent;
background-clip: text;
background-image: linear-gradient(90deg, #277186, #7752ff 40%, #5f98fa 60%, #44beff);
// -webkit-text-fill-color: transparent;
// background-clip: text;
// background-image: linear-gradient(90deg, #277186, #7752ff 40%, #5f98fa 60%, #44beff);
}
h3.subtitle {
font-size: 30px;
+1 -1
View File
@@ -174,7 +174,7 @@
<el-divider />
<el-form :model="site" class="form" label-width="auto" style="max-width: 600px">
<el-form-item
v-for="(feature, featureIndex) in ['chat', 'midjourney', 'chatdoc', 'qrart', 'support']"
v-for="(feature, featureIndex) in ['chat', 'midjourney', 'qrart', 'suno', 'support']"
:key="featureIndex"
:label="$t('site.field.features' + feature.charAt(0).toUpperCase() + feature.slice(1))"
>
+197
View File
@@ -0,0 +1,197 @@
<template>
<layout>
<template #config>
<config-panel @generate="onGenerateAudio" />
</template>
<template #result>
<application-status
:initializing="initializing"
:application="application"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
/>
<recent-panel class="panel recent" />
</template>
<template #preview>
<preview-panel />
</template>
</layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Suno.vue';
import { applicationOperator, sunoOperator } from '@/operators';
import { IApplicationDetailResponse, ISunoAudioRequest, Status } from '@/models';
import { ElMessage } from 'element-plus';
import ApplicationStatus from '@/components/application/Status.vue';
import { ISunoTask } from '@/models';
import { ERROR_CODE_DUPLICATION } from '@/constants';
import ConfigPanel from '@/components/suno/ConfigPanel.vue';
import RecentPanel from '@/components/suno/RecentPanel.vue';
import PreviewPanel from '@/components/suno/PreviewPanel.vue';
const CALLBACK_URL = 'https://webhook.acedata.cloud/suno';
interface IData {
task: ISunoTask | undefined;
job: number;
timer: NodeJS.Timer;
}
export default defineComponent({
name: 'SunoIndex',
components: {
Layout,
ApplicationStatus,
ConfigPanel,
RecentPanel,
PreviewPanel
},
data(): IData {
return {
task: undefined,
job: 0,
// @ts-ignore
timer: undefined
};
},
computed: {
loading() {
return this.$store.state.suno?.status?.getApplication === Status.Request;
},
service() {
return this.$store.state.suno.service;
},
credential() {
return this.$store.state.suno.credential;
},
config() {
return this.$store.state.suno.config;
},
initializing() {
return this.$store.state.suno.status.getApplication === Status.Request;
},
needApply() {
return this.$store.state.suno.status.getApplication === Status.Success && !this.application;
},
application() {
return this.$store.state.suno.application;
}
},
async mounted() {
await this.onGetService();
await this.onGetApplication();
await this.onScrollDown();
await this.onGetTasks();
await this.onScrollDown();
// @ts-ignore
this.job = setInterval(() => {
this.onGetTasks();
}, 5000);
},
async unmounted() {
clearInterval(this.job);
clearInterval(this.timer);
},
methods: {
async onGetService() {
console.debug('start onGetService');
await this.$store.dispatch('suno/getService');
console.debug('end onGetService');
},
async onGetApplication() {
console.debug('start onGetApplication');
await this.$store.dispatch('suno/getApplication');
console.debug('end onGetApplication');
},
onApply() {
applicationOperator
.create({
// @ts-ignore
application: this.application
})
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
this.application = data;
ElMessage.success(this.$t('application.message.applySuccessfully'));
})
.catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied'));
}
});
},
async onScrollDown() {
setTimeout(() => {
// scroll to bottom for `.tasks`
const el = document.querySelector('.tasks');
if (el) {
el.scrollTop = el.scrollHeight;
}
}, 500);
},
async onGetTasks() {
if (this.loading) {
console.debug('loading');
return;
}
await this.$store.dispatch('suno/getTasks', {
limit: 30,
offset: 0
});
},
async onGenerateAudio() {
const request = {
...this.config,
callback_url: CALLBACK_URL
} as ISunoAudioRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.success(this.$t('suno.message.startingTask'));
sunoOperator
.audio(request, {
token
})
.then(() => {
ElMessage.success(this.$t('suno.message.startTaskSuccess'));
})
.catch(() => {
ElMessage.error(this.$t('suno.message.startTaskFailed'));
})
.finally(async () => {
await this.onGetTasks();
await this.onScrollDown();
});
}
}
});
</script>
<style lang="scss" scoped>
.status {
margin-bottom: 10px;
}
.panel {
&.detail {
width: 100%;
flex: 1;
overflow-y: scroll;
}
&.recent {
height: 100%;
width: 100%;
margin-bottom: 10px;
position: relative;
justify-content: initial;
}
&.operation {
position: relative;
}
}
</style>