Skip to content

Commit

Permalink
fix: fix klingai image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
adolphnov committed Dec 2, 2024
1 parent 9653c36 commit 8e664cc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/telegram/command/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ export class KlingAICommandHandler implements CommandHandler {
inputs: [] as any[],
};

if (context.MIDDLE_CONTEXT.originalMessageInfo?.type === 'image' && context.MIDDLE_CONTEXT.originalMessageInfo.id?.[0]) {
if (['image', 'photo'].includes(context.MIDDLE_CONTEXT.originalMessageInfo?.type) && context.MIDDLE_CONTEXT.originalMessageInfo.id?.[0]) {
const img_id = context.MIDDLE_CONTEXT.originalMessageInfo.id?.[0];
const img_url = await this.getFileUrl(img_id, context, headers);
log.info(`Uploaded image url: ${img_url}`);
Expand Down Expand Up @@ -784,7 +784,7 @@ export class KlingAICommandHandler implements CommandHandler {
const resp = await fetch(`https://klingai.com/api/task/status?taskId=${taskId}`, {
headers,
}).then(res => res.json());
if (resp.data?.status === 99) {
if (resp.data?.status === 5 || resp.data?.status === 99) {
const pics = resp.data.works.map(({ resource }: { resource: { resource: string } }) => ({
type: 'photo',
media: resource.resource,
Expand All @@ -793,7 +793,8 @@ export class KlingAICommandHandler implements CommandHandler {
log.info(`KlingAI image urls: ${pics.map((i: { media: any }) => i.media).join(', ')}`);
return sender.sendMediaGroup(pics);
}
console.error(JSON.stringify(resp.data, null, 2));
} else if (resp.data?.status !== 10) {
console.error(resp.data.message || JSON.stringify(resp.data));
throw new Error(`KlingAI Task failed, see logs for more details`);
}
if (Date.now() - startTime > MAX_WAIT_TIME) {
Expand Down

0 comments on commit 8e664cc

Please sign in to comment.