Add hailuo (#168)
This commit is contained in:
1 parent
76313da5b1
commit
d3251fa84e
138 files changed
+9422
-3253
No files matched your search
@@ -0,0 +1,198 @@
|
||||
<template>
|
||||
<layout>
|
||||
<template #config>
|
||||
<config-panel @generate="onGenerateVideo" />
|
||||
</template>
|
||||
<template #result>
|
||||
<application-status
|
||||
:initializing="initializing"
|
||||
:application="application"
|
||||
:service="service"
|
||||
:need-apply="needApply"
|
||||
class="mb-4"
|
||||
@refresh="onGetApplication"
|
||||
/>
|
||||
<recent-panel class="panel recent" />
|
||||
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
||||
</template>
|
||||
</layout>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import Layout from '@/layouts/Hailuo.vue';
|
||||
import ConfigPanel from '@/components/hailuo/ConfigPanel.vue';
|
||||
import { applicationOperator, hailuoOperator } from '@/operators';
|
||||
import { IApplicationDetailResponse, IHailuoGenerateRequest, Status } from '@/models';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ERROR_CODE_DUPLICATION, ERROR_CODE_USED_UP } from '@/constants';
|
||||
import ApplicationStatus from '@/components/application/Status.vue';
|
||||
import RecentPanel from '@/components/hailuo/RecentPanel.vue';
|
||||
import { IHailuoTask } from '@/models';
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.acedata.cloud/hailuo';
|
||||
|
||||
interface IData {
|
||||
task: IHailuoTask | undefined;
|
||||
job: number;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'HailuoIndex',
|
||||
components: {
|
||||
ConfigPanel,
|
||||
Layout,
|
||||
ApplicationStatus,
|
||||
RecentPanel
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
task: undefined,
|
||||
job: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.hailuo?.status?.getApplications === Status.Request;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.hailuo.service;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.hailuo.credential;
|
||||
},
|
||||
config() {
|
||||
return this.$store.state.hailuo.config;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.hailuo.status.getApplications === Status.Request;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.hailuo.status.getApplications === Status.Success && !this.application;
|
||||
},
|
||||
application() {
|
||||
return this.$store.state.hailuo.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);
|
||||
},
|
||||
methods: {
|
||||
async onGetService() {
|
||||
console.debug('start onGetService');
|
||||
await this.$store.dispatch('hailuo/getService');
|
||||
console.debug('end onGetService');
|
||||
},
|
||||
async onGetApplication() {
|
||||
console.debug('start onGetApplication');
|
||||
await this.$store.dispatch('hailuo/getApplications');
|
||||
console.debug('end onGetApplication');
|
||||
await this.onGetTasks();
|
||||
},
|
||||
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 `.recent`
|
||||
const el = document.querySelector('.recent');
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
}, 500);
|
||||
},
|
||||
async onGetTasks() {
|
||||
if (this.loading) {
|
||||
console.debug('loading');
|
||||
return;
|
||||
}
|
||||
await this.$store.dispatch('hailuo/getTasks', {
|
||||
limit: 30,
|
||||
offset: 0
|
||||
});
|
||||
},
|
||||
async onGenerateVideo() {
|
||||
const request = {
|
||||
...this.config,
|
||||
callback_url: CALLBACK_URL
|
||||
} as IHailuoGenerateRequest;
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
console.error('no token specified');
|
||||
return;
|
||||
}
|
||||
ElMessage.info(this.$t('hailuo.message.startingTask'));
|
||||
hailuoOperator
|
||||
.generate(request, {
|
||||
token
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success(this.$t('hailuo.message.startTaskSuccess'));
|
||||
this.$store.commit('hailuo/setConfig', {
|
||||
config: undefined
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
const response = error?.response?.data;
|
||||
if (response?.error?.code === ERROR_CODE_USED_UP) {
|
||||
ElMessage.error(this.$t('hailuo.message.usedUp'));
|
||||
} else {
|
||||
ElMessage.error(this.$t('hailuo.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>
|
||||
@@ -181,6 +181,7 @@
|
||||
'suno',
|
||||
'luma',
|
||||
'pika',
|
||||
'hailuo',
|
||||
'headshots',
|
||||
'support'
|
||||
]"
|
||||
|
||||
Reference in new issue
Block a user