From 5f0ec79e8334b7f4e8fb87d947f6057d0ee1ca9b Mon Sep 17 00:00:00 2001 From: HCode <71808213+hyf-github-user@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:08:22 +0800 Subject: [PATCH] Add kling (#200) --- ...-92767ad9-d24d-453c-8742-ce201e63cba5.json | 7 + src/components/common/VideoNavigator.vue | 3 + src/components/kling/ConfigPanel.vue | 98 +++++ src/components/kling/DetailPanel.vue | 23 ++ src/components/kling/OperationPanel.vue | 77 ++++ src/components/kling/RecentPanel.vue | 143 ++++++++ src/components/kling/VideoPlayer.vue | 40 ++ .../kling/config/CfgScaleSelector.vue | 51 +++ .../kling/config/DurationSelector.vue | 79 ++++ src/components/kling/config/EndImage.vue | 127 +++++++ src/components/kling/config/ModeSelector.vue | 79 ++++ src/components/kling/config/ModelSelector.vue | 83 +++++ .../kling/config/NegativePromptInput.vue | 71 ++++ src/components/kling/config/PromptInput.vue | 71 ++++ src/components/kling/config/RatioSelector.vue | 129 +++++++ src/components/kling/config/StartImage.vue | 128 +++++++ src/components/kling/task/Preview.vue | 343 ++++++++++++++++++ src/constants/index.ts | 1 + src/constants/kling.ts | 8 + src/i18n/index.ts | 1 + src/i18n/zh-CN/common.json | 4 + src/i18n/zh-CN/kling.json | 286 +++++++++++++++ src/i18n/zh-CN/site.json | 8 + src/layouts/Kling.vue | 83 +++++ src/models/index.ts | 1 + src/models/kling.ts | 68 ++++ src/models/site.ts | 1 + src/operators/index.ts | 1 + src/operators/kling.ts | 112 ++++++ src/pages/kling/Index.vue | 234 ++++++++++++ src/pages/site/Index.vue | 1 + src/router/constants.ts | 3 + src/router/index.ts | 2 + src/router/kling.ts | 16 + src/store/common/models.ts | 2 + src/store/common/state.ts | 8 + src/store/index.ts | 4 + src/store/kling/actions.ts | 196 ++++++++++ src/store/kling/index.ts | 14 + src/store/kling/models.ts | 22 ++ src/store/kling/mutations.ts | 71 ++++ src/store/kling/persist.ts | 1 + src/store/kling/state.ts | 18 + 43 files changed, 2718 insertions(+) create mode 100644 change/@acedatacloud-nexior-92767ad9-d24d-453c-8742-ce201e63cba5.json create mode 100644 src/components/kling/ConfigPanel.vue create mode 100644 src/components/kling/DetailPanel.vue create mode 100644 src/components/kling/OperationPanel.vue create mode 100644 src/components/kling/RecentPanel.vue create mode 100644 src/components/kling/VideoPlayer.vue create mode 100644 src/components/kling/config/CfgScaleSelector.vue create mode 100644 src/components/kling/config/DurationSelector.vue create mode 100644 src/components/kling/config/EndImage.vue create mode 100644 src/components/kling/config/ModeSelector.vue create mode 100644 src/components/kling/config/ModelSelector.vue create mode 100644 src/components/kling/config/NegativePromptInput.vue create mode 100644 src/components/kling/config/PromptInput.vue create mode 100644 src/components/kling/config/RatioSelector.vue create mode 100644 src/components/kling/config/StartImage.vue create mode 100644 src/components/kling/task/Preview.vue create mode 100644 src/constants/kling.ts create mode 100644 src/i18n/zh-CN/kling.json create mode 100644 src/layouts/Kling.vue create mode 100644 src/models/kling.ts create mode 100644 src/operators/kling.ts create mode 100644 src/pages/kling/Index.vue create mode 100644 src/router/kling.ts create mode 100644 src/store/kling/actions.ts create mode 100644 src/store/kling/index.ts create mode 100644 src/store/kling/models.ts create mode 100644 src/store/kling/mutations.ts create mode 100644 src/store/kling/persist.ts create mode 100644 src/store/kling/state.ts diff --git a/change/@acedatacloud-nexior-92767ad9-d24d-453c-8742-ce201e63cba5.json b/change/@acedatacloud-nexior-92767ad9-d24d-453c-8742-ce201e63cba5.json new file mode 100644 index 00000000..cb8b36d6 --- /dev/null +++ b/change/@acedatacloud-nexior-92767ad9-d24d-453c-8742-ce201e63cba5.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "add kling", + "packageName": "@acedatacloud/nexior", + "email": "1348977728@qq.com", + "dependentChangeType": "patch" +} diff --git a/src/components/common/VideoNavigator.vue b/src/components/common/VideoNavigator.vue index f533389f..615cdb0d 100644 --- a/src/components/common/VideoNavigator.vue +++ b/src/components/common/VideoNavigator.vue @@ -9,6 +9,9 @@ {{ $t('common.nav.hailuo') }} + + {{ $t('common.nav.kling') }} + diff --git a/src/components/kling/ConfigPanel.vue b/src/components/kling/ConfigPanel.vue new file mode 100644 index 00000000..9ea9df65 --- /dev/null +++ b/src/components/kling/ConfigPanel.vue @@ -0,0 +1,98 @@ + + + + + diff --git a/src/components/kling/DetailPanel.vue b/src/components/kling/DetailPanel.vue new file mode 100644 index 00000000..fae99a5f --- /dev/null +++ b/src/components/kling/DetailPanel.vue @@ -0,0 +1,23 @@ + + + diff --git a/src/components/kling/OperationPanel.vue b/src/components/kling/OperationPanel.vue new file mode 100644 index 00000000..47d7a73c --- /dev/null +++ b/src/components/kling/OperationPanel.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/src/components/kling/RecentPanel.vue b/src/components/kling/RecentPanel.vue new file mode 100644 index 00000000..006511f7 --- /dev/null +++ b/src/components/kling/RecentPanel.vue @@ -0,0 +1,143 @@ + + + + + diff --git a/src/components/kling/VideoPlayer.vue b/src/components/kling/VideoPlayer.vue new file mode 100644 index 00000000..45b2fa73 --- /dev/null +++ b/src/components/kling/VideoPlayer.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/components/kling/config/CfgScaleSelector.vue b/src/components/kling/config/CfgScaleSelector.vue new file mode 100644 index 00000000..92ffc090 --- /dev/null +++ b/src/components/kling/config/CfgScaleSelector.vue @@ -0,0 +1,51 @@ + + + diff --git a/src/components/kling/config/DurationSelector.vue b/src/components/kling/config/DurationSelector.vue new file mode 100644 index 00000000..0d4febd1 --- /dev/null +++ b/src/components/kling/config/DurationSelector.vue @@ -0,0 +1,79 @@ + + + + + diff --git a/src/components/kling/config/EndImage.vue b/src/components/kling/config/EndImage.vue new file mode 100644 index 00000000..0ab8cb7e --- /dev/null +++ b/src/components/kling/config/EndImage.vue @@ -0,0 +1,127 @@ + + + + + + + diff --git a/src/components/kling/config/ModeSelector.vue b/src/components/kling/config/ModeSelector.vue new file mode 100644 index 00000000..4c87717f --- /dev/null +++ b/src/components/kling/config/ModeSelector.vue @@ -0,0 +1,79 @@ + + + + + diff --git a/src/components/kling/config/ModelSelector.vue b/src/components/kling/config/ModelSelector.vue new file mode 100644 index 00000000..dc9a1749 --- /dev/null +++ b/src/components/kling/config/ModelSelector.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/components/kling/config/NegativePromptInput.vue b/src/components/kling/config/NegativePromptInput.vue new file mode 100644 index 00000000..795a929d --- /dev/null +++ b/src/components/kling/config/NegativePromptInput.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/components/kling/config/PromptInput.vue b/src/components/kling/config/PromptInput.vue new file mode 100644 index 00000000..fdbf778e --- /dev/null +++ b/src/components/kling/config/PromptInput.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/components/kling/config/RatioSelector.vue b/src/components/kling/config/RatioSelector.vue new file mode 100644 index 00000000..a6aca91c --- /dev/null +++ b/src/components/kling/config/RatioSelector.vue @@ -0,0 +1,129 @@ + + + + + diff --git a/src/components/kling/config/StartImage.vue b/src/components/kling/config/StartImage.vue new file mode 100644 index 00000000..a1e6fa52 --- /dev/null +++ b/src/components/kling/config/StartImage.vue @@ -0,0 +1,128 @@ + + + + + + + diff --git a/src/components/kling/task/Preview.vue b/src/components/kling/task/Preview.vue new file mode 100644 index 00000000..b5795c9a --- /dev/null +++ b/src/components/kling/task/Preview.vue @@ -0,0 +1,343 @@ + + + + + + + diff --git a/src/constants/index.ts b/src/constants/index.ts index 2a2bb562..a6918147 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -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'; diff --git a/src/constants/kling.ts b/src/constants/kling.ts new file mode 100644 index 00000000..f8a9fa4f --- /dev/null +++ b/src/constants/kling.ts @@ -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; diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 44502bec..cbf21d75 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -73,6 +73,7 @@ export const loadLocaleMessages = async (i18n: I18n, locale: string) => { 'qrart', 'luma', 'pika', + 'kling', 'flux', 'hailuo', 'headshots', diff --git a/src/i18n/zh-CN/common.json b/src/i18n/zh-CN/common.json index b24bc370..5b5fb519 100644 --- a/src/i18n/zh-CN/common.json +++ b/src/i18n/zh-CN/common.json @@ -323,6 +323,10 @@ "message": "Pika", "description": "网站导航栏中的文本,用于显示Pika页面,请不要翻译此字段,必须保持为'Pika'" }, + "nav.kling": { + "message": "Kling", + "description": "网站导航栏中的文本,用于显示Kling页面,请不要翻译此字段,必须保持为'Kling'" + }, "nav.hailuo": { "message": "Hailuo", "description": "网站导航栏中的文本,用于显示Hailuo页面,请不要翻译此字段,必须保持为'Hailuo'" diff --git a/src/i18n/zh-CN/kling.json b/src/i18n/zh-CN/kling.json new file mode 100644 index 00000000..a364cd62 --- /dev/null +++ b/src/i18n/zh-CN/kling.json @@ -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": "没有任务时的消息" + } +} diff --git a/src/i18n/zh-CN/site.json b/src/i18n/zh-CN/site.json index 50be8f8f..08f2f709 100644 --- a/src/i18n/zh-CN/site.json +++ b/src/i18n/zh-CN/site.json @@ -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 功能的描述" diff --git a/src/layouts/Kling.vue b/src/layouts/Kling.vue new file mode 100644 index 00000000..d3670de2 --- /dev/null +++ b/src/layouts/Kling.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/models/index.ts b/src/models/index.ts index 159b3147..32891392 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -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'; diff --git a/src/models/kling.ts b/src/models/kling.ts new file mode 100644 index 00000000..ed6d673f --- /dev/null +++ b/src/models/kling.ts @@ -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[]; +} diff --git a/src/models/site.ts b/src/models/site.ts index bc9c67ce..e27e206a 100644 --- a/src/models/site.ts +++ b/src/models/site.ts @@ -5,6 +5,7 @@ export interface ISiteFeatures { qrart?: any; luma?: any; pika?: any; + kling?: any; hailuo?: any; headshots?: any; suno?: any; diff --git a/src/operators/index.ts b/src/operators/index.ts index c2326067..7d172060 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -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'; diff --git a/src/operators/kling.ts b/src/operators/kling.ts new file mode 100644 index 00000000..1756c9ce --- /dev/null +++ b/src/operators/kling.ts @@ -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> { + 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> { + 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> { + 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(); diff --git a/src/pages/kling/Index.vue b/src/pages/kling/Index.vue new file mode 100644 index 00000000..72d3666f --- /dev/null +++ b/src/pages/kling/Index.vue @@ -0,0 +1,234 @@ + + + + + diff --git a/src/pages/site/Index.vue b/src/pages/site/Index.vue index 36e80272..95e63c27 100644 --- a/src/pages/site/Index.vue +++ b/src/pages/site/Index.vue @@ -181,6 +181,7 @@ 'suno', 'luma', 'pika', + 'kling', 'flux', 'hailuo', 'headshots', diff --git a/src/router/constants.ts b/src/router/constants.ts index 098d2176..07264b80 100644 --- a/src/router/constants.ts +++ b/src/router/constants.ts @@ -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'; diff --git a/src/router/index.ts b/src/router/index.ts index ee7b483a..24b3402c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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, diff --git a/src/router/kling.ts b/src/router/kling.ts new file mode 100644 index 00000000..86706f0d --- /dev/null +++ b/src/router/kling.ts @@ -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') + } + ] +}; diff --git a/src/store/common/models.ts b/src/store/common/models.ts index c71fd948..6da9b4af 100644 --- a/src/store/common/models.ts +++ b/src/store/common/models.ts @@ -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; diff --git a/src/store/common/state.ts b/src/store/common/state.ts index a9d26a38..28897721 100644 --- a/src/store/common/state.ts +++ b/src/store/common/state.ts @@ -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() }; diff --git a/src/store/index.ts b/src/store/index.ts index 234bf437..2caf101a 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -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, diff --git a/src/store/kling/actions.ts b/src/store/kling/actions.ts new file mode 100644 index 00000000..e1bc9076 --- /dev/null +++ b/src/store/kling/actions.ts @@ -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): void => { + commit('resetAll'); +}; + +export const setApplication = async ({ commit, dispatch }: any, payload: IApplication): Promise => { + 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 => { + console.debug('set applications', payload); + commit('setApplications', payload); +}; + +export const setService = async ({ commit }: any, payload: IService): Promise => { + console.debug('set service', payload); + commit('setService', payload); +}; + +export const setCredential = async ({ commit }: any, payload: ICredential): Promise => { + console.debug('set credential', payload); + commit('setCredential', payload); +}; + +export const createCredential = async ({ commit, state }: any): Promise => { + 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): Promise => { + 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): Promise => { + 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, + { + offset, + limit, + createdAtMin, + createdAtMax + }: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number } +): Promise => { + 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 +}; diff --git a/src/store/kling/index.ts b/src/store/kling/index.ts new file mode 100644 index 00000000..4a4dbba2 --- /dev/null +++ b/src/store/kling/index.ts @@ -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 = { + namespaced: true, + state, + mutations, + actions +}; + +export default kling; diff --git a/src/store/kling/models.ts b/src/store/kling/models.ts new file mode 100644 index 00000000..9c990f23 --- /dev/null +++ b/src/store/kling/models.ts @@ -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; + }; +} diff --git a/src/store/kling/mutations.ts b/src/store/kling/mutations.ts new file mode 100644 index 00000000..dc2b533b --- /dev/null +++ b/src/store/kling/mutations.ts @@ -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 +}; diff --git a/src/store/kling/persist.ts b/src/store/kling/persist.ts new file mode 100644 index 00000000..8d4e5ace --- /dev/null +++ b/src/store/kling/persist.ts @@ -0,0 +1 @@ +export default ['kling.credential', 'kling.application', 'kling.applications']; diff --git a/src/store/kling/state.ts b/src/store/kling/state.ts new file mode 100644 index 00000000..6512dd12 --- /dev/null +++ b/src/store/kling/state.ts @@ -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 + } + }; +};