Skip to content

Commit

Permalink
v2.20.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dooy committed Sep 10, 2024
1 parent 6a33359 commit 9c88038
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 15 deletions.
3 changes: 3 additions & 0 deletions changlog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 功能升级日志

# 计划
# 2.20.8
- 😄 新增:可灵 kling 视频 绘图模块

# 2.20.7
- 😄 新增:runway 可以 extend
- 🐞 修复:ideogram 清空
Expand Down
2 changes: 1 addition & 1 deletion package.json
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]>",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "ChatGPT-MJ",
"version": "2.20.7"
"version": "2.20.8"
},
"tauri": {
"allowlist": {
Expand Down
126 changes: 126 additions & 0 deletions src/api/kling.ts
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)
}
}
58 changes: 58 additions & 0 deletions src/api/klingStore.ts
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]
}
}
6 changes: 5 additions & 1 deletion src/api/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,17 @@ export const openaiSetting= ( q:any,ms:MessageApiInjection )=>{
LUMA_SERVER:url,
RUNWAY_SERVER:url,
VIGGLE_SERVER:url,
IDEO_SERVER:url,
KLING_SERVER:url,

OPENAI_API_KEY:key,
MJ_API_SECRET:key,
SUNO_KEY:key,
LUMA_KEY:key,
RUNWAY_KEY:key,
VIGGLE_KEY:key
VIGGLE_KEY:key,
IDEO_KEY:url,
KLING_KEY:url,
} )
blurClean();
gptServerStore.setMyData( gptServerStore.myData );
Expand Down
15 changes: 14 additions & 1 deletion src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,20 @@ export default {
"ideoserver": "Ideogram Server",
"ideokeyPlaceholder": "API Key for Ideogram (optional)",
"ideopls": "Image description prompts",
"nohead": "Excludes"
"nohead": "Excludes",

klingabout: 'Kling About',
klingserver: 'Kling API Address',
klingkeyPlaceholder: 'Kling API Key (optional)',
klingkey: 'Kling Key',
mode: 'Mode',
duration: 'Duration',
negative_prompt: 'Place text without objects here',
std: 'High Performance',
pro: 'High Quality',
needImg: 'Please upload a reference image for it to take effect!',
seed: 'Seed number 1~2147483647',
klingInfo: 'Description: <li>1. High Quality is 3.5 times the price</li> <li>2. 10s is 2 times the price</li> <li>3. The last frame must have a reference image to take effect</li>'

},
"mjset": {
Expand Down
15 changes: 14 additions & 1 deletion src/locales/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,20 @@ export default {
"ideoserver": "Serveur Ideogram",
"ideokeyPlaceholder": "Clé API pour Ideogram (optionnelle)",
"ideopls": "Invites de description d'image",
"nohead": "Exclut"
"nohead": "Exclut",

klingabout: 'Kling À propos',
klingserver: 'Adresse API Kling',
klingkeyPlaceholder: 'Clé API Kling (facultatif)',
klingkey: 'Clé Kling',
mode: 'Mode',
duration: 'Durée',
negative_prompt: 'Mettez le texte sans objets ici',
std: 'Haute performance',
pro: 'Haute qualité',
needImg: 'Veuillez télécharger une image de référence pour qu’elle prenne effet !',
seed: 'Numéro de graine 1~2147483647',
klingInfo: 'Description : <li>1. Haute qualité coûte 3,5 fois le prix</li> <li>2. 10 secondes coûtent 2 fois le prix</li> <li>3. La dernière image doit avoir une image de référence pour prendre effet</li>'

},
"mjset": {
Expand Down
15 changes: 14 additions & 1 deletion src/locales/ko-KR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,20 @@ export default {
"ideoserver": "아이디어그램 서버",
"ideokeyPlaceholder": "아이디어그램의 API 키 (선택 사항)",
"ideopls": "이미지 설명 프롬프트",
"nohead": "포함하지 않음"
"nohead": "포함하지 않음",

klingabout: '클링 관련',
klingserver: '클링 API 주소',
klingkeyPlaceholder: '클링 API 키 (선택 사항)',
klingkey: '클링 키',
mode: '모드',
duration: '지속 시간',
negative_prompt: '여기에 객체가 없는 텍스트를 입력하세요',
std: '고성능',
pro: '고품질',
needImg: '효과를 보려면 참조 이미지를 업로드하세요!',
seed: '시드 번호 1~2147483647',
klingInfo: '설명: <li>1. 고품질은 가격의 3.5배입니다</li> <li>2. 10초는 가격의 2배입니다</li> <li>3. 마지막 프레임은 효과를 위해 참조 이미지가 필요합니다</li>'

},
"mjset": {
Expand Down
15 changes: 14 additions & 1 deletion src/locales/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,20 @@ export default {
"ideoserver": "Сервер Идеограммы",
"ideokeyPlaceholder": "API-ключ для Идеограммы (необязательно)",
"ideopls": "Подсказки для описания изображения",
"nohead": "Не включает"
"nohead": "Не включает",

klingabout: 'Клинг О',
klingserver: 'Адрес API Клинг',
klingkeyPlaceholder: 'API-ключ Клинг (необязательно)',
klingkey: 'Ключ Клинг',
mode: 'Режим',
duration: 'Продолжительность',
negative_prompt: 'Поместите текст без объектов сюда',
std: 'Высокая производительность',
pro: 'Высокое качество',
needImg: 'Пожалуйста, загрузите эталонное изображение, чтобы это заработало!',
seed: 'Число семени 1~2147483647',
klingInfo: 'Описание: <li>1. Высокое качество стоит в 3.5 раза дороже</li> <li>2. 10 секунд стоит в 2 раза дороже</li> <li>3. Последний кадр должен иметь эталонное изображение для действия</li>'


},
Expand Down
15 changes: 14 additions & 1 deletion src/locales/tr-TR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,20 @@ export default {
"ideoserver": "Ideogram Sunucusu",
"ideokeyPlaceholder": "Ideogram için API Anahtarı (isteğe bağlı)",
"ideopls": "Görüntü açıklama ipuçları",
"nohead": "Dahil değil"
"nohead": "Dahil değil",

klingabout: 'Kling Hakkında',
klingserver: 'Kling API Adresi',
klingkeyPlaceholder: 'Kling API Anahtarı (isteğe bağlı)',
klingkey: 'Kling Anahtarı',
mode: 'Mod',
duration: 'Süre',
negative_prompt: 'Nesne içermeyen metni buraya yerleştirin',
std: 'Yüksek Performans',
pro: 'Yüksek Kalite',
needImg: 'Etki etmesi için lütfen bir referans resmi yükleyin!',
seed: 'Tohum numarası 1~2147483647',
klingInfo: 'Açıklama: <li>1. Yüksek kalite fiyatın 3.5 katıdır</li> <li>2. 10 saniye fiyatın 2 katıdır</li> <li>3. Son kare etkili olması için bir referans resmine sahip olmalıdır</li>'
},
"mjset": {
"server": "Sunucu",
Expand Down
15 changes: 14 additions & 1 deletion src/locales/vi-VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,20 @@ export default {
"ideoserver": "Máy chủ Ideogram",
"ideokeyPlaceholder": "Khóa API cho Ideogram (tùy chọn)",
"ideopls": "Gợi ý mô tả hình ảnh",
"nohead": "Không bao gồm"
"nohead": "Không bao gồm",

klingabout: 'Liên quan đến Kling',
klingserver: 'Địa chỉ API Kling',
klingkeyPlaceholder: 'API Key Kling (tùy chọn)',
klingkey: 'Khóa Kling',
mode: 'Chế độ',
duration: 'Thời gian',
negative_prompt: 'Đặt văn bản không có đối tượng ở đây',
std: 'Hiệu suất cao',
pro: 'Chất lượng cao',
needImg: 'Vui lòng tải lên hình ảnh tham khảo để nó có hiệu lực!',
seed: 'Số hạt 1~2147483647',
klingInfo: 'Mô tả: <li>1. Chất lượng cao gấp 3,5 lần giá</li> <li>2. 10 giây gấp 2 lần giá</li> <li>3. Khung cuối cùng phải có hình ảnh tham khảo để có hiệu lực</li>'

},
"mjset": {
Expand Down
17 changes: 16 additions & 1 deletion src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,25 @@ export default {
,gpt_gx:'GPTs用g-*'

,ideoabout:'Ideogram 相关'
,ideoserver:'Ideogram 相关'
,ideoserver:'Ideogram 接口地址'
,ideokeyPlaceholder:'Ideogram 的API Key 可不填'
,ideopls:'图片描述 提示词'
,nohead:'不含'

,klingabout:'可灵 相关'
,klingserver:'可灵 接口地址'
,klingkeyPlaceholder:'可灵 的API Key 可不填'
,klingkey:'可灵 Key'
,mode:'模式'
,duration:'时长'
,negative_prompt:'不含物体的文字放这儿'
,std:'高性能'
,pro:'高表现'
,needImg:'请传参考图才生效!'
,seed:'种子数字 1~2147483647'
,klingInfo:'说明: <li>1. 高表现是3.5倍的价格</li> <li>2. 10s是2倍的价格</li> <li>3. 尾帧必须有参考图片才生效</li>'


},

draw: {
Expand Down
Loading

0 comments on commit 9c88038

Please sign in to comment.