Add kling (#200)

This commit is contained in:
HCode authored and GitHub committed 2025-03-12 23:08:22 +08:00
1 parent e12c9d96cc
commit 5f0ec79e83
43 files changed
+2718

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "add kling",
"packageName": "@acedatacloud/nexior",
"email": "1348977728@qq.com",
"dependentChangeType": "patch"
}
+3
View File
@@ -9,6 +9,9 @@
<el-menu-item v-if="site?.features?.hailuo?.enabled" index="/hailuo" @click="$router.push('/hailuo')">
{{ $t('common.nav.hailuo') }}
</el-menu-item>
<el-menu-item v-if="site?.features?.kling?.enabled" index="/kling" @click="$router.push('/kling')">
{{ $t('common.nav.kling') }}
</el-menu-item>
</el-menu>
</template>
+98
View File
@@ -0,0 +1,98 @@
<template>
<div class="panel">
<div class="config">
<prompt-input class="mb-4" />
<model-selector class="mb-4" />
<mode-selector class="mb-4" />
<ratio-selector class="mb-4" />
<start-image class="mb-4" />
<end-image class="mb-4" />
<cfg-scale-selector class="mb-4" />
<duration-selector class="mb-4" />
<negative-prompt-input class="mb-4" />
<div class="actions">
<el-button
v-if="config?.video_url !== undefined || config?.custom"
type="primary"
class="btn w-full"
round
@click="onGenerate"
>
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('kling.button.extend') }}
</el-button>
<el-button v-else type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('kling.button.generate') }}
</el-button>
</div>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ModelSelector from './config/ModelSelector.vue';
import ModeSelector from './config/ModeSelector.vue';
import DurationSelector from './config/DurationSelector.vue';
import RatioSelector from './config/RatioSelector.vue';
import StartImage from './config/StartImage.vue';
import EndImage from './config/EndImage.vue';
import CfgScaleSelector from './config/CfgScaleSelector.vue';
import PromptInput from './config/PromptInput.vue';
import NegativePromptInput from './config/NegativePromptInput.vue';
export default defineComponent({
name: 'PresetPanel',
components: {
ElButton,
FontAwesomeIcon,
PromptInput,
NegativePromptInput,
ModelSelector,
ModeSelector,
DurationSelector,
RatioSelector,
StartImage,
CfgScaleSelector,
EndImage
},
emits: ['generate'],
computed: {
config() {
return this.$store.state.kling?.config;
}
},
methods: {
onGenerate() {
this.$emit('generate');
}
}
});
</script>
<style lang="scss" scoped>
.panel {
height: 100%;
padding: 15px;
display: flex;
flex-direction: column;
flex: 1;
height: calc(100% - 40px);
.config {
width: 100%;
height: calc(100% - 50px);
flex: 1;
}
.actions {
height: 50px;
display: flex;
justify-content: center;
align-items: center;
.btn {
width: 100%;
}
}
}
</style>
+23
View File
@@ -0,0 +1,23 @@
<template>
<div class="panel detail">
<task-detail />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskDetail from './task/Detail.vue';
export default defineComponent({
name: 'DetailPanel',
components: {
TaskDetail
},
data() {
return {
job: 0
};
},
computed: {}
});
</script>
+77
View File
@@ -0,0 +1,77 @@
<template>
<div>
<el-card v-show="operating">
<content-input class="mb-4" />
<prompt-input class="mb-4" />
<preset-selector class="mb-4" />
<div class="actions">
<el-button type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('kling.button.generate') }}
</el-button>
</div>
</el-card>
<div>
<el-button type="primary" class="btn btn-operate" @click="operating = !operating">+</el-button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElButton, ElCard } from 'element-plus';
import PresetSelector from './config/PresetSelector2.vue';
import ContentInput from './config/ContentInput.vue';
import PromptInput from './config/PromptInput.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'OperationPanel',
components: {
ElButton,
ElCard,
PresetSelector,
ContentInput,
PromptInput,
FontAwesomeIcon
},
emits: ['generate'],
data() {
return {
operating: false
};
},
methods: {
onGenerate() {
this.$emit('generate');
this.operating = false;
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
width: 580px;
height: fit-content;
overflow-y: scroll;
position: absolute;
bottom: 70px;
left: calc(50% - 300px);
@media (max-width: 767px) {
width: 100%;
left: 0;
}
}
.btn-operate {
width: 50px;
height: 50px;
border-radius: 50%;
font-size: 24px;
line-height: 40px;
padding: 0;
margin: auto;
display: block;
}
</style>
+143
View File
@@ -0,0 +1,143 @@
<template>
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
<div v-if="tasks?.items === undefined" class="tasks">
<div v-for="_ in 3" :key="_" class="task placeholder">
<div class="left">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="image" class="avatar" />
</template>
</el-skeleton>
</div>
<div class="main">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="p" class="title" />
<el-skeleton-item variant="image" class="icon" />
</template>
</el-skeleton>
</div>
</div>
</div>
<div v-else-if="tasks?.items?.length && tasks?.items?.length > 0" class="tasks">
<!-- {{ tasks?.items }} -->
<task-preview v-for="(task, taskIndex) in tasks?.items" :key="taskIndex" :model-value="task" class="preview" />
</div>
<p v-if="tasks?.items?.length === 0" class="description">
{{ $t('kling.message.noTasks') }}
</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskPreview from './task/Preview.vue';
import { ElSkeleton, ElSkeletonItem } from 'element-plus';
export default defineComponent({
name: 'RecentPanel',
components: {
TaskPreview,
ElSkeleton,
ElSkeletonItem
},
emits: ['reach-top'],
data() {
return {
job: 0
};
},
computed: {
tasks() {
// reverse the order of the tasks.items
return {
...this.$store.state.kling?.tasks,
items: this.$store.state.kling?.tasks?.items?.slice()
};
}
},
methods: {
onHandleScroll() {
const el = this.$refs.panel as HTMLElement;
console.log('reach-top reach-top reach-top');
if (el.scrollTop === 0) {
this.$emit('reach-top');
}
}
}
});
</script>
<style lang="scss" scoped>
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
&.recent {
width: 100%;
height: 100%;
display: flex;
overflow-y: auto;
flex-direction: column;
.preview {
margin-right: 15px;
}
.description {
text-align: left;
font-size: 14px;
color: var(--el-text-color-secondary);
}
.tasks {
width: 100%;
.task {
margin-bottom: 15px;
width: 100%;
height: fit-content;
text-align: left;
&.placeholder {
display: flex;
flex-direction: row;
.left {
width: 70px;
padding: 10px;
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
}
.main {
width: calc(100% - 70px);
flex: 1;
padding: 10px;
margin-bottom: 10px;
.icon {
display: flex;
height: 200px;
width: 300px;
}
.title {
display: block;
width: 200px;
height: 20px;
margin-bottom: 15px;
}
}
}
.operations {
height: fit-content !important;
}
}
}
}
}
</style>
+40
View File
@@ -0,0 +1,40 @@
<template>
<div>
<vue-plyr :options="options" class="video">
<video controls crossorigin playsinline>
<source size="1080" :src="modelValue?.video_url" type="video/mp4" />
</video>
</vue-plyr>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
// @ts-ignore
import VuePlyr from '@skjnldsv/vue-plyr';
// @ts-ignore
import { IKlingVideo } from '@/models';
import '@skjnldsv/vue-plyr/dist/vue-plyr.css';
export default defineComponent({
name: 'VideoPlayer',
components: { VuePlyr },
props: {
modelValue: {
type: Object as () => IKlingVideo | undefined,
required: true
}
},
data() {
return {
options: { quality: { default: '1080p' } }
};
}
});
</script>
<style lang="scss" scoped>
.video {
max-width: 100%;
height: 450px;
}
</style>
@@ -0,0 +1,51 @@
<template>
<div>
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('kling.name.cfgScale') }}</span>
<info-icon :content="$t('kling.description.cfgScale')" />
</div>
<div class="flex justify-end items-center">
<el-input-number v-model="value" size="small" controls-position="right" />
</div>
</div>
<div class="w-full">
<el-slider v-model="value" :min="0" :max="1" :step="0.1" />
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSlider, ElInputNumber } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
import { KLING_DEFAULT_CFG_SCALE } from '@/constants';
export default defineComponent({
name: 'CfgScaleSelector',
components: {
ElSlider,
InfoIcon,
ElInputNumber
},
computed: {
value: {
get() {
return this.$store.state?.kling?.config?.cfg_scale;
},
set(val) {
console.debug('set cfg_scale', val);
this.$store.commit('kling/setConfig', {
...this.$store.state?.kling?.config,
cfg_scale: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = KLING_DEFAULT_CFG_SCALE;
}
}
});
</script>
@@ -0,0 +1,79 @@
<template>
<div class="field">
<h2 class="title font-bold">{{ $t('kling.name.duration') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('kling.placeholder.select')">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { KLING_DEFAULT_DURATION } from '@/constants';
export default defineComponent({
name: 'DurationSelector',
components: {
ElSelect,
ElOption
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
options: [
{
value: 5,
label: '5秒'
},
{
value: 10,
label: '10秒'
}
]
};
},
computed: {
value: {
get() {
return this.$store.state.kling?.config?.duration;
},
set(val) {
this.$store.commit('kling/setConfig', {
...this.$store.state.kling.config,
duration: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = KLING_DEFAULT_DURATION;
}
}
});
</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: 80px;
}
}
</style>
+127
View File
@@ -0,0 +1,127 @@
<template>
<div class="relative">
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('kling.name.endImage') }}</span>
<info-icon :content="$t('kling.description.uploadEndImage')" />
</div>
</div>
<el-upload
v-model:file-list="fileList"
name="file"
:limit="5"
class="upload-wrapper"
:multiple="false"
:action="uploadUrl"
list-type="picture"
: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('kling.button.uploadReferences') }}
</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';
interface IData {
fileList: UploadFiles;
uploadUrl: string;
}
export default defineComponent({
name: 'EndImage',
components: {
ElUpload,
ElButton,
InfoIcon,
FontAwesomeIcon
},
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);
},
value: {
get() {
return this.$store.state?.kling?.config?.start_image_url;
},
set(val: string) {
// this.$store.commit('kling/setConfig', {
// ...this.$store.state?.kling?.config,
// start_image_url: val
// });
}
}
},
mounted() {
if (!this.value) {
this.value = undefined;
}
this.onSetEndImageUrl();
},
methods: {
onExceed() {
ElMessage.warning(this.$t('kling.message.uploadReferencesExceed'));
},
onError() {
ElMessage.error(this.$t('kling.message.uploadReferencesError'));
},
onSetEndImageUrl() {
const url = this.urls?.[0];
this.$store.commit('kling/setConfig', {
...this.$store.state.kling?.config,
end_image_url: url
});
},
async onSuccess() {
this.onSetEndImageUrl();
}
}
});
</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>
@@ -0,0 +1,79 @@
<template>
<div class="field">
<h2 class="title font-bold">{{ $t('kling.name.mode') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('kling.placeholder.select')">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { KLING_DEFAULT_MODE } from '@/constants';
export default defineComponent({
name: 'ModeSelector',
components: {
ElSelect,
ElOption
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
options: [
{
value: 'std',
label: '标准'
},
{
value: 'pro',
label: '高速'
}
]
};
},
computed: {
value: {
get() {
return this.$store.state.kling?.config?.mode;
},
set(val) {
this.$store.commit('kling/setConfig', {
...this.$store.state.kling.config,
mode: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = KLING_DEFAULT_MODE;
}
}
});
</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: 80px;
}
}
</style>
@@ -0,0 +1,83 @@
<template>
<div class="field">
<h2 class="title font-bold">{{ $t('pika.name.model') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('pika.placeholder.select')">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { KLING_DEFAULT_MODEL } from '@/constants';
export default defineComponent({
name: 'ModelSelector',
components: {
ElSelect,
ElOption
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
options: [
{
value: 'kling-v1',
label: 'kling-v1'
},
{
value: 'kling-v1-5',
label: 'kling-v1-5'
},
{
value: 'kling-v1-6',
label: 'kling-v1-6'
}
]
};
},
computed: {
value: {
get() {
return this.$store.state.kling?.config?.model;
},
set(val) {
this.$store.commit('kling/setConfig', {
...this.$store.state.kling.config,
model: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = KLING_DEFAULT_MODEL;
}
}
});
</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: 80px;
}
}
</style>
@@ -0,0 +1,71 @@
<template>
<div class="field">
<div class="box">
<h2 class="title font-bold">{{ $t('kling.name.negativePrompt') }}</h2>
<info-icon :content="$t('kling.description.negativePrompt')" class="info" />
</div>
<el-input
v-model="prompt"
:rows="3"
type="textarea"
class="prompt"
:placeholder="$t('kling.placeholder.negativePrompt')"
:maxlength="200"
show-word-limit
/>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElInput } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
export const DEFAULT_NEGATIVE_PROMPT = '';
export default defineComponent({
name: 'NegativePromptInput',
components: {
ElInput,
InfoIcon
},
computed: {
prompt: {
get() {
return this.$store.state.kling?.config?.negative_prompt;
},
set(val) {
console.debug('set prompt', val);
this.$store.commit('kling/setConfig', {
...this.$store.state.kling?.config,
negative_prompt: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_NEGATIVE_PROMPT;
}
}
});
</script>
<style lang="scss" scoped>
.field {
.box {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; // Add this line to move the icon to the right
position: relative;
.title {
font-size: 14px;
margin-bottom: 10px;
}
}
.info {
margin-left: auto; // Ensure the icon stays on the right
}
}
</style>
@@ -0,0 +1,71 @@
<template>
<div class="field">
<div class="box">
<h2 class="title font-bold">{{ $t('kling.name.prompt') }}</h2>
<info-icon :content="$t('kling.description.prompt')" class="info" />
</div>
<el-input
v-model="prompt"
:rows="3"
type="textarea"
class="prompt"
:placeholder="$t('kling.placeholder.prompt')"
:maxlength="500"
show-word-limit
/>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElInput } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
export const DEFAULT_PROMPT = '';
export default defineComponent({
name: 'PromptInput',
components: {
ElInput,
InfoIcon
},
computed: {
prompt: {
get() {
return this.$store.state.kling?.config?.prompt;
},
set(val) {
console.debug('set prompt', val);
this.$store.commit('kling/setConfig', {
...this.$store.state.kling?.config,
prompt: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_PROMPT;
}
}
});
</script>
<style lang="scss" scoped>
.field {
.box {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; // Add this line to move the icon to the right
position: relative;
.title {
font-size: 14px;
margin-bottom: 10px;
}
}
.info {
margin-left: auto; // Ensure the icon stays on the right
}
}
</style>
@@ -0,0 +1,129 @@
<template>
<div>
<span class="text-sm font-bold mb-2 block">{{ $t('kling.name.ratio') }}</span>
<div class="items">
<div
v-for="(option, optionKey) in options"
:key="optionKey"
:class="{ active: active === optionKey, item: true }"
@click="value = option.value"
>
<div class="preview" :class="option.label">
<div class="rect" :style="{ width: option.width + 'px', height: option.height + 'px' }"></div>
</div>
<p class="name">
{{ option.label }}
</p>
</div>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { KLING_DEFAULT_ASPECT_RATIO } from '@/constants';
export default defineComponent({
name: 'RatioSelector',
data() {
return {
options: [
{
value: '1:1',
label: '1:1',
width: 20,
height: 20
},
{
value: '16:9',
label: '16:9',
width: 25,
height: 13
},
{
value: '9:16',
label: '9:16',
width: 13,
height: 25
}
]
};
},
computed: {
active() {
return this.options.findIndex((option) => option.value === this.value) || 0;
},
value: {
get() {
return this.$store.state?.kling?.config?.aspect_ratio;
},
set(val) {
console.debug('set ratio', val);
this.$store.commit('kling/setConfig', {
...this.$store.state?.kling?.config,
aspect_ratio: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = KLING_DEFAULT_ASPECT_RATIO;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 14px;
margin-bottom: 10px;
}
.items {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.item {
width: 48px;
height: 65px;
border: 2px solid var(--el-border-color);
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
border-radius: 5px;
.preview {
margin-top: 8px;
width: 30px;
height: 30px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
.rect {
border: 2px solid var(--el-border-color);
width: 20px;
height: 20px;
border-radius: 2px;
}
}
.name {
display: block;
font-size: 12px;
color: var(--el-text-color-primary);
}
&.active {
border-color: var(--el-color-primary);
.rect {
border-color: var(--el-color-primary);
}
}
}
}
</style>
+128
View File
@@ -0,0 +1,128 @@
<template>
<div class="relative">
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('kling.name.startImage') }}</span>
<info-icon :content="$t('kling.description.uploadStartImage')" />
</div>
</div>
<el-upload
v-model:file-list="fileList"
name="file"
:limit="5"
class="upload-wrapper"
:multiple="false"
:action="uploadUrl"
list-type="picture"
: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('kling.button.uploadReferences') }}
</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';
interface IData {
fileList: UploadFiles;
uploadUrl: string;
}
export default defineComponent({
name: 'StartImage',
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}`
};
},
urls() {
// @ts-ignore
return this.fileList.map((file: UploadFile) => file?.response?.file_url);
},
value: {
get() {
return this.$store.state?.kling?.config?.start_image_url;
},
set(val: string) {
// this.$store.commit('kling/setConfig', {
// ...this.$store.state?.kling?.config,
// start_image_url: val
// });
}
}
},
mounted() {
if (!this.value) {
this.value = undefined;
}
this.onSetStartImageUrl();
},
methods: {
onExceed() {
ElMessage.warning(this.$t('kling.message.uploadReferencesExceed'));
},
onError() {
ElMessage.error(this.$t('kling.message.uploadReferencesError'));
},
onSetStartImageUrl() {
const url = this.urls?.[0];
this.$store.commit('kling/setConfig', {
...this.$store.state?.kling?.config,
start_image_url: url
});
},
async onSuccess() {
this.onSetStartImageUrl();
}
}
});
</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>
+343
View File
@@ -0,0 +1,343 @@
<template>
<div class="preview">
<div class="left">
<el-image src="https://cdn.acedata.cloud/gtt64b.png" class="avatar" />
</div>
<div class="main">
<div class="bot">
{{ $t('kling.name.klingBot') }}
<span class="datetime">
{{ $dayjs.format('' + new Date(parseFloat(modelValue?.created_at || '') * 1000)) }}
</span>
</div>
<div class="info">
<p v-if="modelValue?.request?.prompt" class="prompt mt-2">
{{ modelValue?.request?.prompt }}
<span v-if="!modelValue?.response"> - ({{ $t('kling.status.pending') }}) </span>
<span
v-if="
modelValue?.response?.state === 'submitted' ||
modelValue?.response?.state === 'processing' ||
modelValue?.response?.state === 'pending' ||
modelValue?.response?.state === 'completed'
"
>
- ({{ $t('kling.status.processing') }})
</span>
</p>
</div>
<!-- Display success message -->
<div v-if="modelValue?.response?.success === true" :class="{ content: true, failed: true }">
<div class="image-wrapper">
<VideoPlayer :model-value="modelValue?.response" />
</div>
<div v-if="modelValue?.response.success" :class="{ operations: true, 'mt-2': true }">
<el-tooltip class="box-item" effect="dark" :content="$t('kling.message.downloadVideo')" placement="top-start">
<el-button
type="info"
size="small"
class="btn-action"
@click="onDownload($event, modelValue?.response.video_url)"
>
{{ $t('kling.button.download') }}
</el-button>
</el-tooltip>
</div>
<el-alert :closable="false" class="mt-2 success">
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('kling.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div v-if="modelValue?.response?.success === false" :class="{ content: true }">
<el-alert :closable="false" class="failure">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('kling.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('kling.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-circle-info" class="mr-1" />
{{ $t('kling.name.failureReason') }}:
{{ modelValue?.response?.error?.message }}
<copy-to-clipboard :content="modelValue?.response?.error?.message!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-hashtag" class="mr-1" />
{{ $t('kling.name.traceId') }}:
{{ modelValue?.response?.trace_id }}
<copy-to-clipboard :content="modelValue?.response?.trace_id" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div
v-if="
!modelValue?.response ||
modelValue?.response?.state === 'processing' ||
modelValue?.response?.state === 'pending'
"
:class="{ content: true }"
>
<el-alert :closable="false" class="info">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('kling.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('kling.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElAlert, ElButton, ElTooltip } from 'element-plus';
import { IKlingTask, IKlingGenerateResponse, IKlingVideo } from '@/models';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import VideoPlayer from '../VideoPlayer.vue';
export default defineComponent({
name: 'TaskPreview',
components: {
ElImage,
CopyToClipboard,
FontAwesomeIcon,
ElAlert,
VideoPlayer,
ElTooltip,
ElButton
},
props: {
modelValue: {
type: Object as () => IKlingTask | undefined,
required: true
}
},
data() {
return {};
},
computed: {
application() {
return this.$store.state.kling?.application;
},
config() {
return this.$store.state.kling?.config;
}
},
methods: {
// onExtend(event: MouseEvent, response: IKlingGenerateResponse) {
// event.stopPropagation();
// // extend url here
// console.debug('set config', response);
// this.$store.commit('kling/setConfig', {
// ...this.$store.state.kling?.config,
// video_id: response.video_id,
// prompt: response.prompt,
// action: 'extend',
// thumbnail_url: response.thumbnail_url,
// video_url: response.video_url
// });
// },
onDownload(event: MouseEvent, video_url: string) {
event.stopPropagation();
console.log('on download');
// download url here
window.open(video_url, '_blank');
},
onReload(event: Event) {
const target = event.target as HTMLImageElement;
// append a random url query to existing url query, to force reload the image
// extract exiting url query
const url = new URL(target.src);
// extract `retry` query
const retry = url.searchParams.get('retry');
if (!retry) {
// if no retry query, set it as random string
url.searchParams.set('retry', '1');
} else if (parseInt(retry) < 2) {
// if retry < 3, increase it by 1
url.searchParams.set('retry', (parseInt(retry) + 1).toString());
} else {
return;
}
// set the new url
target.src = url.toString();
},
onOpenVideo(url: string) {
window.open(url, '_blank');
}
}
});
</script>
<style lang="scss" scoped>
$left-width: 70px;
.preview {
width: 100%;
height: fit-content;
text-align: left;
display: flex;
flex-direction: row;
margin-bottom: 15px;
.left {
width: $left-width;
.avatar {
background-color: rgb(34, 34, 34);
padding: 2px;
width: 50px;
height: 50px;
margin: 10px;
border-radius: 50%;
}
}
.main {
flex: 1;
width: calc(100% - $left-width);
padding: 10px 10px 0 10px;
.bot {
font-size: 16px;
font-weight: bold;
color: rgb(46, 204, 113);
margin-bottom: 0;
margin-top: 0;
.datetime {
font-size: 12px;
font-weight: normal;
color: var(--el-text-color-secondary);
margin-left: 10px;
}
}
.info {
.prompt {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-regular);
margin-bottom: 10px;
}
}
.content {
.el-alert {
border-left-width: 2px;
border-left-style: solid;
&.failure {
border-color: var(--el-color-danger);
}
&.success {
border-color: var(--el-color-success);
}
&.info {
border-color: var(--el-color-info);
}
}
}
.image-wrapper {
position: relative;
width: fit-content;
min-height: 50px;
min-width: 100px;
.image {
max-height: 400px;
max-width: 500px;
display: block;
width: fit-content;
}
.btn-raw {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
display: none;
}
.play-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 48px;
color: white;
z-index: 500;
pointer-events: none; /* Ensure the icon doesn't interfere with hover */
}
&:hover {
.image {
filter: brightness(0.6);
}
.btn-raw {
display: block;
}
.play-icon {
display: none;
}
}
}
.operations {
display: flex;
justify-content: left;
flex-direction: row;
width: 100%;
align-items: baseline;
flex-wrap: wrap;
overflow: hidden;
text-align: center;
color: var(--el-text-color-regular);
font-size: 14px;
overflow-y: scroll;
&.full {
height: 70px;
}
.btn-action {
margin-bottom: 10px;
}
}
}
}
</style>
<style lang="scss">
.preview {
.image.error {
background: var(--el-bg-color-page);
.image-slot {
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.failure {
background: var(--el-fill-color-light);
width: 100%;
.el-alert__content {
p {
margin-bottom: 10px;
}
}
}
}
</style>
+1
View File
@@ -7,6 +7,7 @@ export * from './midjourney';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './kling';
export * from './flux';
export * from './hailuo';
export * from './headshots';
+8
View File
@@ -0,0 +1,8 @@
export const KLING_SERVICE_ID = '3369e077-2500-4263-86c7-cae0f0e7e843';
export const KLING_DEFAULT_MODEL = 'kling-v1';
export const KLING_DEFAULT_DURATION = 5;
export const KLING_DEFAULT_MODE = 'std';
export const KLING_DEFAULT_ASPECT_RATIO = '1:1';
export const KLING_DEFAULT_INGREDIENTS = false;
export const KLING_DEFAULT_CFG_SCALE = 0;
+1
View File
@@ -73,6 +73,7 @@ export const loadLocaleMessages = async (i18n: I18n, locale: string) => {
'qrart',
'luma',
'pika',
'kling',
'flux',
'hailuo',
'headshots',
+4
View File
@@ -323,6 +323,10 @@
"message": "Pika",
"description": "网站导航栏中的文本,用于显示Pika页面,请不要翻译此字段,必须保持为'Pika'"
},
"nav.kling": {
"message": "Kling",
"description": "网站导航栏中的文本,用于显示Kling页面,请不要翻译此字段,必须保持为'Kling'"
},
"nav.hailuo": {
"message": "Hailuo",
"description": "网站导航栏中的文本,用于显示Hailuo页面,请不要翻译此字段,必须保持为'Hailuo'"
+286
View File
@@ -0,0 +1,286 @@
{
"name.taskId": {
"message": "任务 ID",
"description": "任务的 ID"
},
"name.type": {
"message": "类型",
"description": "要生成的 Kling视频的内容类型,如'链接'、'文本'等"
},
"name.failure": {
"message": "失败",
"description": "任务的失败状态"
},
"name.failureReason": {
"message": "失败原因",
"description": "任务失败的原因"
},
"name.status": {
"message": "状态",
"description": "任务的状态"
},
"name.traceId": {
"message": "追踪 ID",
"description": "任务的追踪 ID"
},
"name.createdAt": {
"message": "创建时间",
"description": "生成 Kling 视频的日期和时间"
},
"name.cfgScale": {
"message": "自由度",
"description": "要生成的视频的参考图片"
},
"name.startImage": {
"message": "首帧参考图片",
"description": "要生成的视频的参考图片"
},
"name.negativePrompt": {
"message": "负向提示词",
"description": "生成视频的负向文本提示"
},
"name.endImage": {
"message": "尾帧参考图片",
"description": "要生成的视频的参考图片"
},
"name.videoUrl": {
"message": "自定义视频",
"description": "自定义视频"
},
"name.prompt": {
"message": "视频提示",
"description": "内容输入的提示"
},
"name.duration": {
"message": "视频时长",
"description": "视频的时长"
},
"name.ingredients": {
"message": "多图创建视频",
"description": "自定义扩展视频"
},
"name.model": {
"message": "模型版本",
"description": "要生成视频所采用的模型版本"
},
"name.ratio": {
"message": "视频比例",
"description": "要生成视频所采用的视频比例"
},
"name.mode": {
"message": "视频模式",
"description": "要生成视频所采用的模式"
},
"name.effect": {
"message": "视频效果",
"description": "风格参数的名称,用于在不同版本或风格的模型之间切换"
},
"name.ingredientsModel": {
"message": "成分模型",
"description": "要生成视频所采用的模型版本"
},
"name.klingBot": {
"message": "Kling Bot",
"description": "Kling 视频生成器的名称"
},
"description.ingredients": {
"message": "如果您想上传多张图片来生成自己的视频,请打开此按钮。",
"description": "参数'ingredients'的描述"
},
"description.imageUrl": {
"message": "在多图创建视频的任务重,它必须上传多张图片。",
"description": "参数'imageUrl'的描述"
},
"description.prompt": {
"message": "生成Kling视频的提示词",
"description": "参数'prompt'的描述"
},
"description.negativePrompt": {
"message": "负向文本提示,可选,不能超过200个字符",
"description": "参数'prompt'的描述"
},
"description.uploadStartImage": {
"message": "上传首帧图像作为生成的参考,最后的视频会参考首帧生成",
"description": "上传参考参数的描述"
},
"description.uploadEndImage": {
"message": "上传首帧图像作为生成的参考,最后的视频会参考首帧生成",
"description": "上传参考参数的描述"
},
"description.cfgScale": {
"message": "生成视频的自由度,可选[0,1]。值越大,相关性越强,",
"description": "上传参考参数的描述"
},
"status.pending": {
"message": "等待中",
"description": "任务的等待状态"
},
"status.processing": {
"message": "处理中",
"description": "任务的等待状态"
},
"placeholder.paddingNoise": {
"message": "请选择...",
"description": "填充噪音输入的占位符"
},
"placeholder.select": {
"message": "选择",
"description": "选择字段中的占位文本"
},
"placeholder.paddingLevel": {
"message": "请选择...",
"description": "填充级别的占位符"
},
"placeholder.prompt": {
"message": "输入要生成的视频风格的提示词,例如:moving",
"description": "提示字段中的占位文本"
},
"placeholder.negativePrompt": {
"message": "输入要生成的视频风格的负向提示词,不超过200字符",
"description": "提示字段中的占位文本"
},
"placeholder.position": {
"message": "请选择...",
"description": "位置输入的占位符"
},
"placeholder.aspectRatio": {
"message": "请选择...",
"description": "宽高比输入的占位符"
},
"placeholder.preset": {
"message": "请选择...",
"description": "预设输入的占位符"
},
"placeholder.markerShape": {
"message": "请选择...",
"description": "标记形状输入的占位符"
},
"placeholder.rotate": {
"message": "请选择...",
"description": "旋转输入的占位符"
},
"placeholder.subMarker": {
"message": "请选择...",
"description": "子标记输入的占位符"
},
"button.precise": {
"message": "精确",
"description": "生成Kling视频的按钮文本"
},
"button.creative": {
"message": "创意",
"description": "生成Kling视频的按钮文本"
},
"button.generate": {
"message": "生成",
"description": "生成Kling视频的按钮文本"
},
"button.extend": {
"message": "扩展视频",
"description": "扩展视频按钮文本"
},
"button.download": {
"message": "下载视频",
"description": "下载视频按钮文本"
},
"button.uploadImageUrl": {
"message": "上传图片",
"description": "上传图片的按钮文本"
},
"button.uploadVideoUrl": {
"message": "上传视频",
"description": "上传视频的按钮文本"
},
"button.uploadReferences": {
"message": "上传",
"description": "按钮文本,允许用户上传参考"
},
"message.uploadReferencesExceed": {
"message": "最多可上传 1 张图片",
"description": "上传的图片数量超过限制时的错误消息"
},
"message.uploadReferencesSuccess": {
"message": "成功上传图片",
"description": "成功上传图片时的成功消息"
},
"message.uploadReferencesError": {
"message": "上传图片失败,请稍后重试",
"description": "图片上传失败时的错误消息"
},
"message.startingTask": {
"message": "正在启动任务...",
"description": "绘图任务开始时的消息"
},
"message.startTaskSuccess": {
"message": "成功发起生成任务",
"description": "成功启动任务时的成功消息"
},
"message.startTaskFailed": {
"message": "发起任务失败,请联系管理员",
"description": "启动绘图任务失败时的错误消息"
},
"message.usedUp": {
"message": "您的积分已用完,请购买更多积分后继续使用",
"description": "已用完时的消息"
},
"message.generating": {
"message": "生成中...",
"description": "图像正在生成时的消息"
},
"message.downloadVideo": {
"message": "下载此视频",
"description": "图像正在生成时的消息"
},
"message.extendVideo": {
"message": "继续生成此视频",
"description": "图像正在生成时的消息"
},
"message.generateFailed": {
"message": "生成图像失败",
"description": "图像生成失败时的消息"
},
"message.uploadVideoExceed": {
"message": "上传首帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadVideoSizeExceed": {
"message": "上传文件大小不能超过 10MB!",
"description": "上传文件大小不能超过 10MB!时的错误信息"
},
"message.uploadVideoTypeFailed": {
"message": "上传文件必须是 MP4 格式!",
"description": "上传文件必须是 MP4 格式!的错误信息"
},
"message.uploadStartImageExceed": {
"message": "上传首帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadEndImageExceed": {
"message": "上传尾帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadStartImageError": {
"message": "上传首帧图片失败",
"description": "上传首帧图片失败时的错误信息"
},
"message.uploadVideoError": {
"message": "上传视频失败",
"description": "上传首帧图片失败时的错误信息"
},
"message.uploadEndImageError": {
"message": "上传尾帧图片失败",
"description": "上传尾帧图片失败时的错误信息"
},
"message.uploadDocumentsError": {
"message": "上传文档失败",
"description": "上传文档失败时的错误信息"
},
"message.noOperations": {
"message": "没有可用操作",
"description": "没有可用操作时的消息"
},
"message.noTasks": {
"message": "没有历史任务,请点击左方生成视频",
"description": "没有任务时的消息"
}
}
+8
View File
@@ -67,6 +67,10 @@
"message": "Pika",
"description": "展示在编辑框的标题"
},
"field.featuresKling": {
"message": "Kling",
"description": "展示在编辑框的标题"
},
"field.featuresHailuo": {
"message": "Hailuo",
"description": "展示在编辑框的标题"
@@ -283,6 +287,10 @@
"message": "打开或关闭 Pika 功能模块。",
"description": "Pika 功能的描述"
},
"message.featuresKling": {
"message": "打开或关闭 Kling 功能模块。",
"description": "Kling 功能的描述"
},
"message.featuresHailuo": {
"message": "打开或关闭 Hailuo 功能模块。",
"description": "Hailuo 功能的描述"
+83
View File
@@ -0,0 +1,83 @@
<template>
<div class="main">
<div class="config">
<video-navigator />
<slot name="config" />
</div>
<div class="result">
<slot name="result" />
</div>
<el-button round class="menu" @click="drawer = true">
<font-awesome-icon icon="fa-solid fa-gear" class="icon-menu" />
</el-button>
<el-drawer v-model="drawer" :with-header="false" size="340px" class="drawer">
<slot name="config" />
</el-drawer>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDrawer, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import VideoNavigator from '@/components/common/VideoNavigator.vue';
export default defineComponent({
name: 'LayoutKling',
components: {
ElDrawer,
ElButton,
FontAwesomeIcon,
VideoNavigator
},
data() {
return {
drawer: false
};
}
});
</script>
<style lang="scss" scoped>
.main {
flex: 1;
display: flex;
flex-direction: row;
.config {
width: 300px;
height: 100%;
overflow-y: scroll;
border-right: 1px solid var(--el-border-color);
}
.result {
height: 100%;
padding: 15px;
flex: 1;
width: calc(100% - 300px);
height: 100%;
display: flex;
flex-direction: column;
}
}
.menu {
display: none;
}
@media (max-width: 767px) {
.config {
display: none;
}
.result {
width: 100%;
}
.menu {
display: block;
position: fixed;
left: 15px;
top: 15px;
z-index: 2000;
}
}
</style>
+1
View File
@@ -14,6 +14,7 @@ export * from './credential';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './kling';
export * from './flux';
export * from './hailuo';
export * from './headshots';
+68
View File
@@ -0,0 +1,68 @@
export interface IKlingConfig {
action?: string;
mode?: string;
model?: string;
video_id?: string;
prompt?: string;
start_image_url?: string;
end_image_url?: string;
negative_prompt?: string;
aspect_ratio?: string;
duration?: number;
camera_control?: string;
cfg_scale?: number;
callback_url?: string;
}
export interface IKlingGenerateRequest {
action?: string;
mode?: string;
model?: string;
video_id?: string;
prompt?: string;
start_image_url?: string;
end_image_url?: string;
negative_prompt?: string;
aspect_ratio?: string;
duration?: number;
camera_control?: string;
cfg_scale?: number;
callback_url?: string;
mirror?: boolean;
}
export interface IKlingVideo {
id?: string;
video_url?: string;
video_id?: string;
duration?: number;
state?: string;
action?: string;
}
export interface IKlingGenerateResponse {
success: boolean;
task_id: string;
trace_id?: string;
video_url?: string;
video_id?: string;
duration?: number;
state?: string;
action?: string;
error?: {
code?: string;
message?: string;
};
}
export interface IKlingTask {
id: string;
created_at?: number;
request?: IKlingGenerateRequest;
response?: IKlingGenerateResponse;
}
export type IKlingTaskResponse = IKlingTask;
export interface IKlingTasksResponse {
count: number;
items: IKlingTask[];
}
+1
View File
@@ -5,6 +5,7 @@ export interface ISiteFeatures {
qrart?: any;
luma?: any;
pika?: any;
kling?: any;
hailuo?: any;
headshots?: any;
suno?: any;
+1
View File
@@ -14,6 +14,7 @@ export * from './credential';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './kling';
export * from './flux';
export * from './hailuo';
export * from './headshots';
+112
View File
@@ -0,0 +1,112 @@
import axios, { AxiosResponse } from 'axios';
import { IKlingGenerateRequest, IKlingGenerateResponse, IKlingTaskResponse, IKlingTasksResponse } from '@/models';
import { BASE_URL_API } from '@/constants';
class KlingOperator {
async task(id: string, options: { token: string }): Promise<AxiosResponse<IKlingTaskResponse>> {
return await axios.post(
`/kling/tasks`,
{
action: 'retrieve',
id: id
},
{
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${options.token}`,
'x-record-exempt': 'true'
},
baseURL: BASE_URL_API
}
);
}
async tasks(
filter: {
ids?: string[];
applicationId?: string;
userId?: string;
type?: string;
limit?: number;
offset?: number;
createdAtMax?: number;
createdAtMin?: number;
},
options: { token: string }
): Promise<AxiosResponse<IKlingTasksResponse>> {
return await axios.post(
`/kling/tasks`,
{
action: 'retrieve_batch',
...(filter.ids
? {
ids: filter.ids
}
: {}),
...(filter.applicationId
? {
application_id: filter.applicationId
}
: {}),
...(filter.userId
? {
user_id: filter.userId
}
: {}),
...(filter.type
? {
type: filter.type
}
: {}),
...(filter.limit !== undefined
? {
limit: filter.limit
}
: {}),
...(filter.offset !== undefined
? {
offset: filter.offset
}
: {}),
...(filter.createdAtMax !== undefined
? {
created_at_max: filter.createdAtMax
}
: {}),
...(filter.createdAtMin !== undefined
? {
created_at_min: filter.createdAtMin
}
: {})
},
{
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${options.token}`,
'x-record-exempt': 'true'
},
baseURL: BASE_URL_API
}
);
}
async generate(
data: IKlingGenerateRequest,
options: {
token: string;
}
): Promise<AxiosResponse<IKlingGenerateResponse>> {
return await axios.post('/kling/videos', data, {
headers: {
authorization: `Bearer ${options.token}`,
'content-type': 'application/json',
accept: 'application/x-ndjson'
},
baseURL: BASE_URL_API
});
}
}
export const klingOperator = new KlingOperator();
+234
View File
@@ -0,0 +1,234 @@
<template>
<layout>
<template #config>
<config-panel @generate="onGenerateVideo" />
</template>
<template #result>
<application-status
:initializing="initializing"
:application="application"
:applications="applications"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
@select="$store.dispatch('kling/setApplication', $event)"
/>
<recent-panel class="panel recent" @reach-top="onReachTop" />
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
</template>
</layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Kling.vue';
import ConfigPanel from '@/components/kling/ConfigPanel.vue';
import { applicationOperator, klingOperator } from '@/operators';
import { IApplicationDetailResponse, IKlingGenerateRequest, 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/kling/RecentPanel.vue';
import { IKlingTask } from '@/models';
const CALLBACK_URL = 'https://webhook.acedata.cloud/kling';
interface IData {
task: IKlingTask | undefined;
job: number;
timer: NodeJS.Timer;
}
export default defineComponent({
name: 'KlingIndex',
components: {
ConfigPanel,
Layout,
ApplicationStatus,
RecentPanel
},
data(): IData {
return {
task: undefined,
job: 0,
// @ts-ignore
timer: undefined
};
},
computed: {
loading() {
return this.$store.state.kling?.status?.getApplications === Status.Request;
},
service() {
return this.$store.state.kling.service;
},
credential() {
return this.$store.state.kling.credential;
},
config() {
return this.$store.state.kling.config;
},
initializing() {
return this.$store.state.kling.status.getApplications === Status.Request;
},
needApply() {
return this.$store.state.kling.status.getApplications === Status.Success && !this.application;
},
application() {
return this.$store.state.kling.application;
},
applications() {
return this.$store.state.kling.applications;
},
tasks() {
return this.$store.state.kling.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
}
},
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 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('kling/getService');
console.debug('end onGetService');
},
async onGetApplication() {
console.debug('start onGetApplication');
await this.$store.dispatch('kling/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(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('kling/getTasks', {
limit,
createdAtMin,
createdAtMax
});
},
async onGenerateVideo() {
const request = {
...this.config,
callback_url: CALLBACK_URL
} as IKlingGenerateRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.info(this.$t('kling.message.startingTask'));
klingOperator
.generate(request, {
token
})
.then(() => {
ElMessage.success(this.$t('kling.message.startTaskSuccess'));
this.$store.commit('kling/setConfig', {
config: undefined
});
})
.catch((error) => {
const response = error?.response?.data;
if (response?.error?.code === ERROR_CODE_USED_UP) {
ElMessage.error(this.$t('kling.message.usedUp'));
} else {
ElMessage.error(this.$t('kling.message.startTaskFailed'));
}
})
.finally(async () => {
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}
});
</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>
+1
View File
@@ -181,6 +181,7 @@
'suno',
'luma',
'pika',
'kling',
'flux',
'hailuo',
'headshots',
+3
View File
@@ -19,6 +19,9 @@ export const ROUTE_LUMA_HISTORY = 'luma-history';
export const ROUTE_PIKA_INDEX = 'pika-index';
export const ROUTE_PIKA_HISTORY = 'pika-history';
export const ROUTE_KLING_INDEX = 'kling-index';
export const ROUTE_KLING_HISTORY = 'kling-history';
export const ROUTE_FLUX_INDEX = 'flux-index';
export const ROUTE_FLUX_HISTORY = 'flux-history';
+2
View File
@@ -8,6 +8,7 @@ import chatdoc from './chatdoc';
import qrart from './qrart';
import luma from './luma';
import pika from './pika';
import kling from './kling';
import flux from './flux';
import hailuo from './hailuo';
import headshots from './headshots';
@@ -38,6 +39,7 @@ const routes = [
qrart,
luma,
pika,
kling,
flux,
hailuo,
headshots,
+16
View File
@@ -0,0 +1,16 @@
import { ROUTE_KLING_INDEX } from './constants';
export default {
path: '/kling',
meta: {
auth: true
},
component: () => import('@/layouts/Main.vue'),
children: [
{
path: '',
name: ROUTE_KLING_INDEX,
component: () => import('@/pages/kling/Index.vue')
}
]
};
+2
View File
@@ -5,6 +5,7 @@ import { IChatdocState } from '../chatdoc/models';
import { IQrartState } from '../qrart/models';
import { ILumaState } from '../luma/models';
import { IPikaState } from '../pika/models';
import { IKlingState } from '../kling/models';
import { IFluxState } from '../flux/models';
import { IHailuoState } from '../hailuo/models';
import { IHeadshotsState } from '../headshots/models';
@@ -37,6 +38,7 @@ export interface IRootState extends ICommonState {
qrart: IQrartState;
luma: ILumaState;
pika: IPikaState;
kling: IKlingState;
flux: IFluxState;
hailuo: IHailuoState;
headshots: IHeadshotsState;
+8
View File
@@ -4,6 +4,10 @@ import midjourneyState from '../midjourney/state';
import chatdocState from '../chatdoc/state';
import qrartState from '../qrart/state';
import lumaState from '../luma/state';
import pikaState from '../pika/state';
import klingState from '../kling/state';
import fluxState from '../flux/state';
import hailuoState from '../hailuo/state';
import sunoState from '../suno/state';
import headshotsState from '../headshots/state';
@@ -29,6 +33,10 @@ export default (): IRootState => {
midjourney: midjourneyState(),
qrart: qrartState(),
luma: lumaState(),
pika: pikaState(),
kling: klingState(),
flux: fluxState(),
hailuo: hailuoState(),
suno: sunoState(),
headshots: headshotsState()
};
+4
View File
@@ -6,6 +6,7 @@ import chatdoc from './chatdoc';
import qrart from './qrart';
import luma from './luma';
import pika from './pika';
import kling from './kling';
import flux from './flux';
import hailuo from './hailuo';
import headshots from './headshots';
@@ -17,6 +18,7 @@ import persistChatdoc from './chatdoc/persist';
import persistQrart from './qrart/persist';
import persistLuma from './luma/persist';
import persistPika from './pika/persist';
import persistKling from './kling/persist';
import persistFlux from './flux/persist';
import persistHailuo from './hailuo/persist';
import persistHeadshots from './headshots/persist';
@@ -31,6 +33,7 @@ const store = createStore({
qrart: qrart,
luma: luma,
pika: pika,
kling: kling,
flux: flux,
hailuo: hailuo,
headshots: headshots,
@@ -47,6 +50,7 @@ const store = createStore({
...persistQrart,
...persistLuma,
...persistPika,
...persistKling,
...persistFlux,
...persistHailuo,
...persistHeadshots,
+196
View File
@@ -0,0 +1,196 @@
import { applicationOperator, credentialOperator, klingOperator, serviceOperator } from '@/operators';
import { IKlingState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IKlingConfig, IKlingTask, IService } from '@/models';
import { Status } from '@/models/common';
import { KLING_SERVICE_ID } from '@/constants';
import { mergeAndSortLists } from '@/utils/merge';
import { getFinalApplication } from '@/utils';
export const resetAll = ({ commit }: ActionContext<IKlingState, IRootState>): void => {
commit('resetAll');
};
export const setApplication = async ({ commit, dispatch }: any, payload: IApplication): Promise<void> => {
console.debug('set application', payload);
commit('setApplication', payload);
if (!payload) {
console.debug('application is null, return');
return;
}
const credential = payload?.credentials?.find((credential) => credential?.host === window.location.origin);
if (credential) {
console.debug('credential exists, set credential', credential);
commit('setCredential', credential);
} else {
console.debug('credential not exists, start to create credential for application', payload);
await dispatch('createCredential');
}
};
export const setApplications = async ({ commit }: any, payload: IApplication[]): Promise<void> => {
console.debug('set applications', payload);
commit('setApplications', payload);
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
console.debug('set service', payload);
commit('setService', payload);
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
console.debug('set credential', payload);
commit('setCredential', payload);
};
export const createCredential = async ({ commit, state }: any): Promise<ICredential | undefined> => {
const application = state.application;
console.debug('prepare to create credential for application', application);
if (!application) {
console.error('Application not found');
return undefined;
}
console.debug('creating create credential for application', application);
const { data: credential } = await credentialOperator.create({
application_id: application?.id,
host: window.location.origin
});
console.debug('created credential success', credential);
commit('setCredential', credential);
console.debug('end createCredential');
return credential;
};
export const getService = async ({
commit,
state
}: ActionContext<IKlingState, IRootState>): Promise<IService | undefined> => {
state.status.getService = Status.Request;
try {
const { data: service } = await serviceOperator.get(KLING_SERVICE_ID);
state.status.getService = Status.Success;
commit('setService', service);
return service;
} catch (error) {
state.status.getService = Status.Error;
commit('setService', undefined);
}
};
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<IKlingState, IRootState>): Promise<IApplication[] | undefined> => {
console.debug('start to get applications for chat');
state.status.getApplications = Status.Request;
const currentApplication = state.application;
console.debug('current application', currentApplication);
try {
const { data: applications } = await applicationOperator.getAll({
user_id: rootState?.user?.id,
service_id: KLING_SERVICE_ID
});
state.status.getApplications = Status.Success;
commit('setApplications', applications.items);
const finalApplication = getFinalApplication(applications.items, currentApplication);
if (finalApplication) {
console.debug('set final application', finalApplication, finalApplication?.type);
commit('setApplication', finalApplication);
} else {
console.debug('set application undefined', undefined);
commit('setApplication', undefined);
}
return applications.items;
} catch (error) {
console.error('get applications failed', error);
state.status.getApplications = Status.Error;
commit('setApplications', undefined);
commit('setApplication', undefined);
}
};
export const setConfig = ({ commit }: any, payload: IKlingConfig) => {
commit('setConfig', payload);
};
export const setTasks = ({ commit }: any, payload: any) => {
commit('setTasks', payload);
};
export const setTasksItems = ({ commit }: any, payload: IKlingTask[]) => {
commit('setTasksItems', payload);
};
export const setTasksTotal = ({ commit }: any, payload: number) => {
commit('setTasksTotal', payload);
};
export const setTasksActive = ({ commit }: any, payload: IKlingTask) => {
commit('setTasksActive', payload);
};
export const getTasks = async (
{ commit, state, rootState }: ActionContext<IKlingState, IRootState>,
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<IKlingTask[]> => {
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
const credential = state.credential;
const token = credential?.token;
if (!token) {
return reject('no token');
}
klingOperator
.tasks(
{
userId: rootState?.user?.id,
createdAtMin,
createdAtMax,
type: 'videos'
},
{
token
}
)
.then((response) => {
console.debug('get videos tasks success', response.data.items);
// merge with existing tasks
const existingItems = state?.tasks?.items || [];
console.debug('existing items', existingItems);
const newItems = response.data.items || [];
console.debug('new items', newItems);
// sort and de-duplicate using created_at
const mergedItems = mergeAndSortLists(existingItems, newItems);
commit('setTasksItems', mergedItems);
commit('setTasksTotal', response.data.count);
resolve(response.data.items);
})
.catch((error) => {
return reject(error);
});
});
};
export default {
setService,
getService,
resetAll,
setCredential,
setConfig,
setApplication,
setApplications,
getApplications,
setTasks,
setTasksItems,
setTasksTotal,
setTasksActive,
getTasks,
createCredential
};
+14
View File
@@ -0,0 +1,14 @@
import { Module } from 'vuex';
import { IKlingState } from './models';
import actions from './actions';
import mutations from './mutations';
import state from './state';
export const kling: Module<IKlingState, any> = {
namespaced: true,
state,
mutations,
actions
};
export default kling;
+22
View File
@@ -0,0 +1,22 @@
import { IApplication, ICredential, IService, Status } from '@/models';
import { IKlingConfig, IKlingTask } from '@/models';
export interface IKlingState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: IKlingConfig | undefined;
tasks:
| {
items: IKlingTask[] | undefined;
total: number | undefined;
active: IKlingTask | undefined;
}
| undefined;
status: {
getService: Status;
getApplications: Status;
getTasks: Status;
};
}
+71
View File
@@ -0,0 +1,71 @@
import { IApplication, ICredential, IKlingConfig, IKlingTask, IService } from '@/models';
import { IKlingState } from './models';
export const resetAll = (state: IKlingState): void => {
state.service = undefined;
state.application = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
};
export const setService = (state: IKlingState, payload: IService): void => {
state.service = payload;
};
export const setCredential = (state: IKlingState, payload: ICredential): void => {
state.credential = payload;
};
export const setApplication = (state: IKlingState, payload: IApplication): void => {
state.application = payload;
};
export const setApplications = (state: IKlingState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setConfig = (state: IKlingState, payload: IKlingConfig): void => {
state.config = payload;
};
export const setTasksItems = (state: IKlingState, payload: IKlingTask[]): void => {
const newPayload = {
...state.tasks,
items: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksTotal = (state: IKlingState, payload: number): void => {
const newPayload = {
...state.tasks,
total: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksActive = (state: IKlingState, payload: IKlingTask): void => {
const newPayload = {
...state.tasks,
active: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasks = (state: IKlingState, payload: any): void => {
state.tasks = payload;
};
export default {
setTasks,
setApplication,
setApplications,
setConfig,
setCredential,
setService,
setTasksActive,
setTasksItems,
setTasksTotal,
resetAll
};
+1
View File
@@ -0,0 +1 @@
export default ['kling.credential', 'kling.application', 'kling.applications'];
+18
View File
@@ -0,0 +1,18 @@
import { IKlingState } from './models';
import { Status } from '@/models';
export default (): IKlingState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: undefined,
credential: undefined,
config: undefined,
status: {
getService: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};
};