-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
735 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# 功能升级日志 | ||
|
||
# 计划 | ||
# 2.20.8 | ||
- 😄 新增:可灵 kling 视频 绘图模块 | ||
|
||
# 2.20.7 | ||
- 😄 新增:runway 可以 extend | ||
- 🐞 修复:ideogram 清空 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "chatgpt-web-midjourney-proxy", | ||
"version": "2.20.7", | ||
"version": "2.20.8", | ||
"private": false, | ||
"description": "ChatGPT Web Midjourney Proxy", | ||
"author": "Dooy <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { gptServerStore, homeStore, useAuthStore } from "@/store"; | ||
import { mlog } from "./mjapi"; | ||
import { KlingTask, klingStore } from "./klingStore"; | ||
import { sleep } from "./suno"; | ||
|
||
|
||
|
||
function getHeaderAuthorization(){ | ||
let headers={} | ||
if( homeStore.myData.vtoken ){ | ||
const vtokenh={ 'x-vtoken': homeStore.myData.vtoken ,'x-ctoken': homeStore.myData.ctoken}; | ||
headers= {...headers, ...vtokenh} | ||
} | ||
if(!gptServerStore.myData.KLING_KEY){ | ||
const authStore = useAuthStore() | ||
if( authStore.token ) { | ||
const bmi= { 'x-ptoken': authStore.token }; | ||
headers= {...headers, ...bmi } | ||
return headers; | ||
} | ||
return headers | ||
} | ||
const bmi={ | ||
'Authorization': 'Bearer ' +gptServerStore.myData.KLING_KEY | ||
} | ||
headers= {...headers, ...bmi } | ||
return headers | ||
} | ||
|
||
export const getUrl=(url:string)=>{ | ||
if(url.indexOf('http')==0) return url; | ||
|
||
const pro_prefix= '';//homeStore.myData.is_luma_pro?'/pro':'' | ||
url= url.replaceAll('/pro','') | ||
if(gptServerStore.myData.KLING_SERVER ){ | ||
|
||
return `${ gptServerStore.myData.RUNWAY_SERVER}${pro_prefix}/kling${url}`; | ||
} | ||
return `${pro_prefix}/kling${url}`; | ||
} | ||
|
||
|
||
export const klingFetch=(url:string,data?:any,opt2?:any )=>{ | ||
mlog('runwayFetch', url ); | ||
let headers= opt2?.upFile?{}: {'Content-Type':'application/json'} | ||
|
||
if(opt2 && opt2.headers ) headers= opt2.headers; | ||
|
||
headers={...headers,...getHeaderAuthorization()} | ||
|
||
return new Promise<any>((resolve, reject) => { | ||
let opt:RequestInit ={method:'GET'}; | ||
|
||
opt.headers= headers ; | ||
if(opt2?.upFile ){ | ||
opt.method='POST'; | ||
opt.body=data as FormData ; | ||
} | ||
else if(data) { | ||
opt.body= JSON.stringify(data) ; | ||
opt.method='POST'; | ||
} | ||
fetch(getUrl(url), opt ) | ||
.then( async (d) =>{ | ||
if (!d.ok) { | ||
let msg = '发生错误: '+ d.status | ||
try{ | ||
let bjson:any = await d.json(); | ||
msg = '('+ d.status+')发生错误: '+(bjson?.error?.message??'' ) | ||
}catch( e ){ | ||
} | ||
homeStore.myData.ms && homeStore.myData.ms.error(msg ) | ||
throw new Error( msg ); | ||
} | ||
|
||
d.json().then(d=> resolve(d)).catch(e=>{ | ||
|
||
homeStore.myData.ms && homeStore.myData.ms.error('发生错误'+ e ) | ||
reject(e) | ||
} | ||
)}) | ||
.catch(e=>{ | ||
if (e.name === 'TypeError' && e.message === 'Failed to fetch') { | ||
homeStore.myData.ms && homeStore.myData.ms.error('跨域|CORS error' ) | ||
} | ||
else homeStore.myData.ms && homeStore.myData.ms.error('发生错误:'+e ) | ||
mlog('e', e.stat ) | ||
reject(e) | ||
}) | ||
}) | ||
|
||
} | ||
|
||
export const klingFeed= async(id:string,cat:string,prompt:string)=>{ | ||
const sunoS = new klingStore(); | ||
let url= '/v1/images/generations/' //images或videos | ||
if (cat=='text2video'){ | ||
url='/v1/videos/text2video/'; | ||
} | ||
if(cat=='image2video'){ | ||
url='/v1/videos/image2video/'; | ||
} | ||
url= url+id; | ||
for(let i=0; i<200;i++){ | ||
try{ | ||
|
||
let a= await klingFetch( url ) | ||
let task= a as KlingTask; | ||
task.last_feed=new Date().getTime() | ||
task.cat= cat | ||
if(prompt){ | ||
task.prompt= prompt | ||
} | ||
//ss.save( task ) | ||
//mlog("a",a ) | ||
sunoS.save( task ) | ||
homeStore.setMyData({act:'KlingFeed'}); | ||
if( task.data.task_status =='failed' || 'succeed'== task.data.task_status ){ | ||
break; | ||
} | ||
}catch(e){ | ||
break; | ||
} | ||
await sleep(5200) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ss } from "@/utils/storage"; | ||
|
||
|
||
export interface KlingTask { | ||
cat?: string //类别 | ||
prompt?: string //提示词 | ||
last_feed?: number //最后更新时间 | ||
code: number; | ||
message: string; | ||
request_id: string; | ||
data: { | ||
task_id: string; | ||
task_status: string; | ||
task_status_msg: string; | ||
created_at: number; | ||
updated_at: number; | ||
task_result?: { | ||
images: Array<{ | ||
index: number; | ||
url: string; | ||
}> | null; | ||
videos: Array<{ | ||
id: string; | ||
url: string; | ||
duration: string; | ||
}> | null; | ||
}; | ||
}; | ||
} | ||
|
||
export class klingStore{ | ||
//private id: string; | ||
private localKey='kling-store'; | ||
public save(obj:KlingTask ){ | ||
if(!obj.data.task_id ) throw "taskID must"; | ||
let arr= this.getObjs(); | ||
let i= arr.findIndex( v=>v.data.task_id==obj.data.task_id ); | ||
if(i>-1) arr[i]= obj; | ||
else arr.push(obj); | ||
ss.set(this.localKey, arr ); | ||
return this; | ||
} | ||
public findIndex(id:string){ | ||
return this.getObjs().findIndex( v=>v.data.task_id == id ) | ||
} | ||
|
||
public getObjs():KlingTask[]{ | ||
const obj = ss.get( this.localKey ) as undefined| KlingTask[]; | ||
if(!obj) return []; | ||
return obj; | ||
} | ||
public getOneById(id:string):KlingTask|null{ | ||
const i= this.findIndex(id) | ||
if(i<0) return null; | ||
let arr= this.getObjs(); | ||
return arr[i] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.