Add veo videos (#251)

This commit is contained in:
HCode authored and GitHub committed 2025-08-07 10:42:26 +00:00
1 parent a0a7c30c53
commit 14873dde9b
185 files changed
+9497 -3699

No files matched your search

+164
View File
@@ -0,0 +1,164 @@
<template>
<layout>
<template #config>
<config-panel @generate="onGenerate" />
</template>
<template #result>
<recent-panel @reach-top="onReachTop" />
</template>
</layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Veo.vue';
import ConfigPanel from '@/components/veo/ConfigPanel.vue';
import { veoOperator } from '@/operators';
import { IVeoGenerateRequest, Status } from '@/models';
import { ElMessage } from 'element-plus';
import { ERROR_CODE_USED_UP } from '@/constants';
import RecentPanel from '@/components/veo/RecentPanel.vue';
import { IVeoTask } from '@/models';
const CALLBACK_URL = 'https://webhook.acedata.cloud/veo';
interface IData {
task: IVeoTask | undefined;
job: number;
}
export default defineComponent({
name: 'VeoIndex',
components: {
ConfigPanel,
Layout,
RecentPanel
},
inject: ['initialized'],
data(): IData {
return {
task: undefined,
job: 0
};
},
computed: {
loading() {
return this.$store.state.veo?.status?.getApplications === Status.Request;
},
credential() {
return this.$store.state.veo.credential;
},
config() {
return this.$store.state.veo.config;
},
tasks() {
return this.$store.state.veo.tasks;
}
},
watch: {
tasks: {
handler(value, oldValue) {
// scroll down if new tasks are added
if (value?.items?.length > oldValue?.items?.length) {
console.debug('new tasks detected');
// this.onScrollDown();
}
},
deep: true
},
initialized: {
async handler(newValue) {
if (newValue) {
console.debug('layout initialized');
await this.onGetTasks();
await this.onScrollDown();
this.job = setInterval(() => {
this.onGetTasks();
}, 5000);
}
},
immediate: true
}
},
async mounted() {
await this.onGetService();
},
async unmounted() {
clearInterval(this.job);
},
methods: {
async onReachTop() {
console.debug('reached top');
await this.onGetTasks({
createdAtMax: this.tasks?.items?.[0]?.created_at
});
},
async onGetService() {
console.debug('start onGetService');
await this.$store.dispatch('veo/getService');
console.debug('end onGetService');
},
async onGetApplication() {
console.debug('start onGetApplication');
await this.$store.dispatch('veo/getApplications');
console.debug('end onGetApplication');
await this.onGetTasks();
},
async onScrollDown() {
setTimeout(() => {
const el = document.querySelector('.tasks');
if (el) {
el.scrollTop = el.scrollHeight;
}
}, 500);
},
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
if (this.loading) {
console.debug('loading');
return;
}
console.debug('start onGetTasks', payload);
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
await this.$store.dispatch('veo/getTasks', {
limit,
createdAtMin,
createdAtMax
});
},
async onGenerate() {
const request = {
...this.config,
callback_url: CALLBACK_URL
} as IVeoGenerateRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.info(this.$t('veo.message.startingTask'));
veoOperator
.generate(request, {
token
})
.then(() => {
ElMessage.success(this.$t('veo.message.startTaskSuccess'));
})
.catch((error) => {
const response = error?.response?.data;
if (response?.error?.code === ERROR_CODE_USED_UP) {
ElMessage.error(this.$t('veo.message.usedUp'));
} else {
ElMessage.error(this.$t('veo.message.startTaskFailed'));
}
})
.finally(async () => {
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}
});
</script>