Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from jianjianai/dev
Browse files Browse the repository at this point in the history
go-bingai-pass
  • Loading branch information
jianjianai authored Jun 17, 2024
2 parents 344833f + 806b26c commit c3d4205
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"download-go-bingai-pass": "wget https://github.com/Harry-zklcdc/go-bingai-pass/releases/latest/download/go-bingai-pass.wasm -O go-bingai-pass.wasm",
"deploy": "wrangler deploy",
"deploy": "npm run build-worker && wrangler deploy",
"dev": "wrangler dev",
"build-worker-only": "rollup --config rollup.config.workers.mjs && cp go-bingai-pass.wasm ./dist/",
"build-page-only": "rollup --config rollup.config.pages.mjs && cp go-bingai-pass.wasm ./functions/",
Expand Down
17 changes: 14 additions & 3 deletions src/proxy/bingPorxyWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { verify } from './goBingaiPass';
import ChallengeResponseBody from '../html/ChallengeResponseBody.html'


const XForwardedForIP = usIps[Math.floor(Math.random() * usIps.length)][0];


/** websocket */
async function websocketPorxy(request: Request): Promise<Response> {
Expand Down Expand Up @@ -51,7 +51,7 @@ function injectionHtmlToBody(html: string, sc: string) {
return html.replace("<body>", `<body>${sc}`)
}

export const bingPorxyWorker = newProxyLinkHttp<Env>({
const bingProxyLink = newProxyLinkHttp<Env>({
async intercept(req, env) {//拦截
// 处理 websocket
const upgradeHeader = req.headers.get('Upgrade');
Expand Down Expand Up @@ -152,7 +152,9 @@ export const bingPorxyWorker = newProxyLinkHttp<Env>({
}

// XForwardedForIP 设置
(config.init.headers as Headers).set("X-forwarded-for", XForwardedForIP);
if(env.XForwardedForIP){
(config.init.headers as Headers).set("X-forwarded-for", env.XForwardedForIP);
}

{// origin 设置
const resHeaders = config.init.headers as Headers;
Expand Down Expand Up @@ -332,3 +334,12 @@ export const bingPorxyWorker = newProxyLinkHttp<Env>({
}
});

const XForwardedForIP = usIps[Math.floor(Math.random() * usIps.length)][0];
export const bingPorxyWorker = (req: Request,env:Env)=>{
// 初始化 环境变量
env.XForwardedForIP = env.XForwardedForIP || XForwardedForIP;
// 开始请求
return bingProxyLink(req,env);
}


9 changes: 6 additions & 3 deletions src/proxy/goBingaiPass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { fCFF } from '../go-bingai-pass/worker';

async function verifyFCFF(request: Request): Promise<Response> {
const cookie: string = request.headers.get('Cookie') || '';
async function verifyFCFF(request: Request,evn:Env): Promise<Response> {
let cookie: string = request.headers.get('Cookie') || '';
// if(evn.XForwardedForIP){
// cookie = `${cookie?(cookie+"; "):""}BingAI_Rand_IP=${evn.XForwardedForIP}`;
// }
const currentUrl = new URL(request.url);
const resData = await fCFF({
'IG': currentUrl.searchParams.get('IG'),
Expand Down Expand Up @@ -58,5 +61,5 @@ export async function verify(request: Request,evn:Env): Promise<Response> {
if(evn.BYPASS_SERVER){
return verifyPass(request,evn.BYPASS_SERVER);//使用远程服务器验证
}
return verifyFCFF(request);//本地验证
return verifyFCFF(request,evn);//本地验证
};
3 changes: 2 additions & 1 deletion worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Generated by Wrangler
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
interface Env {
BYPASS_SERVER?: string
BYPASS_SERVER?: string,
XForwardedForIP?: string
}

0 comments on commit c3d4205

Please sign in to comment.