-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
26 changed files
with
887 additions
and
12 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
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.19.1", | ||
"version": "2.19.2", | ||
"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,40 @@ | ||
import axios from 'axios'; | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { isNotEmptyString } from './utils/is'; | ||
import FormData from 'form-data' | ||
|
||
|
||
//req, res, next | ||
|
||
export const viggleProxyFileDo= async( req:Request, res:Response, next?:NextFunction)=>{ | ||
// if ( process.env.VIGGLE_KEY ) proxyReqOpts.headers['Authorization'] ='Bearer '+process.env.VIGGLE_KEY; | ||
// else proxyReqOpts.headers['Authorization'] ='Bearer '+process.env.OPENAI_API_KEY; | ||
console.log('req.originalUrl', req.originalUrl ); | ||
let API_BASE_URL = isNotEmptyString(process.env.OPENAI_API_BASE_URL) | ||
? process.env.OPENAI_API_BASE_URL | ||
: 'https://api.openai.com' | ||
API_BASE_URL= process.env.VIGGLE_SERVER?? API_BASE_URL | ||
if(req.file.buffer) { | ||
const fileBuffer = req.file.buffer; | ||
const formData = new FormData(); | ||
formData.append('file', fileBuffer, { filename: req.file.originalname } ); | ||
// formData.append('model', req.body.model ); | ||
try{ | ||
let url = `${API_BASE_URL}${req.originalUrl}` ; | ||
let responseBody = await axios.post( url , formData, { | ||
headers: { | ||
Authorization: 'Bearer '+ (process.env.VIGGLE_KEY??process.env.OPENAI_API_KEY) , | ||
'Content-Type': 'multipart/form-data', | ||
//'Mj-Version': pkg.version | ||
} | ||
}) ; | ||
res.json(responseBody.data ); | ||
}catch(e){ | ||
res.status( 400 ).json( {error: e } ); | ||
} | ||
|
||
}else{ | ||
res.status(400).json({'error':'uploader fail'}); | ||
} | ||
|
||
} |
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,138 @@ | ||
import { gptServerStore, homeStore, useAuthStore } from "@/store"; | ||
import { mlog } from "./mjapi"; | ||
import { sleep } from "./suno"; | ||
import { ViggleTask, viggleStore } from "./viggleStore"; | ||
|
||
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.VIGGLE_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.VIGGLE_KEY | ||
} | ||
headers= {...headers, ...bmi } | ||
return headers | ||
} | ||
|
||
export const getUrl=(url:string)=>{ | ||
if(url.indexOf('http')==0) return url; | ||
|
||
const pro_prefix= '';//url.indexOf('/pro')>-1?'/pro':'';//homeStore.myData.is_luma_pro?'/pro':'' | ||
// url= url.replaceAll('/pro','') | ||
if(gptServerStore.myData.VIGGLE_SERVER){ | ||
if(gptServerStore.myData.VIGGLE_SERVER.indexOf('/pro')>0){ | ||
return `${ gptServerStore.myData.VIGGLE_SERVER}/viggle${url}`; | ||
} | ||
return `${ gptServerStore.myData.VIGGLE_SERVER}${pro_prefix}/viggle${url}`; | ||
} | ||
return `${pro_prefix}/viggle${url}`; | ||
} | ||
|
||
export interface tagInfo { | ||
id: string; | ||
name: string; | ||
sort: number; | ||
} | ||
export interface ViggleTemplate { | ||
id: string; | ||
processedURL: string; | ||
processedHdURL: string; | ||
processedCoverURL: string; | ||
command?: string; | ||
webCommand?: string; | ||
description: string; | ||
webStatus?: number; | ||
dcStatus?: number; | ||
appStatus?: number; | ||
bgURL?: string; | ||
bgCoverURL?: string; | ||
displayURL?: string; | ||
displayHdURL?: string; | ||
displayCoverURL?: string; | ||
gifURL?: string; | ||
webPURL?: string; | ||
source?: string; | ||
sort?: number; | ||
width?: number; | ||
height?: number; | ||
} | ||
|
||
export const viggleFetch=(url:string,data?:any,opt2?:any )=>{ | ||
mlog('viggleFetch', 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 async function FeedViggleTask(id:string){ | ||
const ss = new viggleStore() | ||
for(let i=0; i<500;i++){ | ||
const d= await viggleFetch('/video-task/by-ids',{ids:[id]}) | ||
mlog('FeedViggleTask', d ) | ||
|
||
if(d.data && d.data.length>0){ | ||
let task= d.data[0] as ViggleTask; | ||
task.last_feed=new Date().getTime() | ||
ss.save( task ) | ||
homeStore.setMyData({act:'FeedViggleTask'}) | ||
if ( d.data[0].status==0) return | ||
} | ||
await sleep(2000) | ||
} | ||
|
||
} |
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,49 @@ | ||
import { ss } from "@/utils/storage"; | ||
|
||
export interface ViggleTask { | ||
taskID: string; | ||
name: string; | ||
status: number; | ||
videoDuration: number; | ||
bgMode: number; | ||
modelInfoID: number; | ||
optimize: boolean; | ||
watermark: number; | ||
freeCredits: number; | ||
planCredits: number; | ||
purchasedCredits: number; | ||
mqType: number; | ||
result: string; | ||
resultCover: string; | ||
createdAt: string; | ||
last_feed:number; | ||
} | ||
|
||
export class viggleStore{ | ||
//private id: string; | ||
private localKey='viggle-store'; | ||
public save(obj:ViggleTask ){ | ||
if(!obj.taskID ) throw "taskID must"; | ||
let arr= this.getObjs(); | ||
let i= arr.findIndex( v=>v.taskID==obj.taskID ); | ||
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.taskID== id ) | ||
} | ||
|
||
public getObjs():ViggleTask[]{ | ||
const obj = ss.get( this.localKey ) as undefined| ViggleTask[]; | ||
if(!obj) return []; | ||
return obj; | ||
} | ||
public getOneById(id:string):ViggleTask|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
Oops, something went wrong.