forked from adams549659584/go-proxy-bingai
-
Notifications
You must be signed in to change notification settings - Fork 7
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
17 changed files
with
823 additions
and
617 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Cloudfalre Worker Deploy | ||
on: | ||
push: | ||
branches: | ||
- master | ||
repository_dispatch: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v4.0.0 | ||
with: | ||
run_install: true | ||
version: 9 | ||
- name: Build | ||
run: pnpm run build-worker | ||
- name: Deploy Worker | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
command: 'deploy --keep-vars' |
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 |
---|---|---|
|
@@ -12,3 +12,6 @@ | |
.DS_Store | ||
|
||
release | ||
node_modules | ||
/_worker.js | ||
/worker.js |
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,16 +1,7 @@ | ||
#!/bin/bash | ||
|
||
cp -r web cloudflare/web | ||
|
||
rm cloudflare/web/web.go | ||
rm -rf go-proxy-bingai | ||
|
||
npm install | ||
npm run build-page | ||
shopt -s extglob | ||
rm -rf !(cloudflare) | ||
mv cloudflare/* . | ||
rm -rf cloudflare build.sh | ||
|
||
sed -i "s/if (currentUrl.pathname === '\/' || currentUrl.pathname.indexOf('\/web\/') === 0) {/if (currentUrl.pathname === '\/') {/g" worker.js | ||
sed -i "s/return home(currentUrl.pathname);/let res = new Response('', {\n status: 302,\n });\n res.headers.set('location', '\/web\/');\n return res;\n }\n if (currentUrl.pathname.indexOf('\/web\/') === 0) {\n return env.ASSETS.fetch(request);/g" worker.js | ||
rm -rf !(_worker.js|web) | ||
|
||
mv worker.js _worker.js |
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,28 @@ | ||
import { init_CUSTOM_OPTIONS } from "./src/OPTIONS" | ||
import { workerFetch } from './src/worker' | ||
|
||
|
||
export default { | ||
/** | ||
* fetch | ||
* @param {Request} request | ||
* @param {*} env | ||
* @param {*} ctx | ||
* @returns | ||
*/ | ||
async fetch(request, env, ctx) { | ||
init_CUSTOM_OPTIONS(env); | ||
const currentUrl = new URL(request.url); | ||
if (currentUrl.pathname === '/') { | ||
let res = new Response('', { | ||
status: 302, | ||
}); | ||
res.headers.set('location', '/web/'); | ||
return res; | ||
} | ||
if (currentUrl.pathname.indexOf('/web/') === 0) { | ||
return env.ASSETS.fetch(request); | ||
} | ||
return workerFetch(request, env, ctx); | ||
} | ||
} |
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,54 @@ | ||
import obfuscator from 'rollup-plugin-obfuscator'; | ||
import compiler from '@ampproject/rollup-plugin-closure-compiler'; | ||
|
||
// rollup.config.mjs | ||
// ---cut-start--- | ||
/** @type {import('rollup').RollupOptions} */ | ||
// ---cut-end--- | ||
export default { | ||
input: 'cloudflare/page.js', | ||
output: [ | ||
{ | ||
file: '_worker.js', | ||
format: 'es' | ||
} | ||
], | ||
plugins:[ | ||
obfuscator({ | ||
// global:false, | ||
// include:["cloudflare/src/OPTIONS.js","cloudflare/src/bingapi.js"], | ||
options: { | ||
// Your javascript-obfuscator options here | ||
// See what's allowed: https://github.com/javascript-obfuscator/javascript-obfuscator | ||
compact: false, | ||
controlFlowFlattening: false, | ||
deadCodeInjection: false, | ||
debugProtection: false, | ||
debugProtectionInterval: 0, | ||
disableConsoleOutput: false, | ||
identifierNamesGenerator: 'mangled', | ||
log: false, | ||
numbersToExpressions: false, | ||
renameGlobals: false, | ||
selfDefending: false, | ||
simplify: true, | ||
// splitStrings: true, | ||
// splitStringsChunkLength:10, | ||
stringArray: true, | ||
stringArrayEncoding: ['base64'], | ||
stringArrayIndexShift: true, | ||
stringArrayRotate: true, | ||
stringArrayShuffle: true, | ||
stringArrayWrappersCount: 1, | ||
stringArrayWrappersChainedCalls: true, | ||
stringArrayWrappersParametersMaxCount: 2, | ||
stringArrayWrappersType: 'variable', | ||
stringArrayThreshold: 1, | ||
unicodeEscapeSequence: false | ||
}, | ||
}), | ||
compiler({ | ||
compilation_level:"ADVANCED" | ||
}) | ||
] | ||
}; |
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,54 @@ | ||
import obfuscator from 'rollup-plugin-obfuscator'; | ||
import compiler from '@ampproject/rollup-plugin-closure-compiler'; | ||
|
||
// rollup.config.mjs | ||
// ---cut-start--- | ||
/** @type {import('rollup').RollupOptions} */ | ||
// ---cut-end--- | ||
export default { | ||
input: 'cloudflare/worker.js', | ||
output: [ | ||
{ | ||
file: 'worker.js', | ||
format: 'es', | ||
} | ||
], | ||
plugins:[ | ||
obfuscator({ | ||
// global:false, | ||
// include:["cloudflare/src/OPTIONS.js","cloudflare/src/bingapi.js"], | ||
options: { | ||
// Your javascript-obfuscator options here | ||
// See what's allowed: https://github.com/javascript-obfuscator/javascript-obfuscator | ||
compact: false, | ||
controlFlowFlattening: false, | ||
deadCodeInjection: false, | ||
debugProtection: false, | ||
debugProtectionInterval: 0, | ||
disableConsoleOutput: false, | ||
identifierNamesGenerator: 'mangled', | ||
log: false, | ||
numbersToExpressions: false, | ||
renameGlobals: false, | ||
selfDefending: false, | ||
simplify: true, | ||
// splitStrings: true, | ||
// splitStringsChunkLength:10, | ||
stringArray: true, | ||
stringArrayEncoding: ['base64'], | ||
stringArrayIndexShift: true, | ||
stringArrayRotate: true, | ||
stringArrayShuffle: true, | ||
stringArrayWrappersCount: 1, | ||
stringArrayWrappersChainedCalls: true, | ||
stringArrayWrappersParametersMaxCount: 2, | ||
stringArrayWrappersType: 'variable', | ||
stringArrayThreshold: 1, | ||
unicodeEscapeSequence: false | ||
}, | ||
}), | ||
compiler({ | ||
compilation_level:"ADVANCED" | ||
}) | ||
] | ||
}; |
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,77 @@ | ||
// 同查找 _U 一样, 查找 KievRPSSecAuth 的值并替换下方的xxx | ||
export const CUSTOM_OPTIONS = { | ||
KievRPSSecAuth: '', | ||
_RwBf: '', | ||
MUID: '', | ||
_U: '', | ||
|
||
BYPASS_SERVER: '', | ||
APIKEY: '', | ||
Go_Proxy_BingAI_BLANK_API_KEY: false, | ||
|
||
Go_Proxy_BingAI_AUTH_KEY: '', | ||
|
||
INFO: '', | ||
NIGHTLY: false, | ||
} | ||
|
||
export const WEB_CONFIG = { | ||
WORKER_URL: '', // 如无特殊需求请,保持为'' | ||
}; | ||
|
||
|
||
export const RAND_IP_COOKIE_NAME = 'BingAI_Rand_IP'; | ||
export const AUTH_KEY_COOKIE_NAME = 'BingAI_Auth_Key'; | ||
|
||
export const SYDNEY_ORIGIN = 'https://sydney.bing.com'; | ||
export const BING_ORIGIN = 'https://www.bing.com'; | ||
export const BING_SOURCE_ORIGIN = 'https://th.bing.com'; | ||
export const BING_SR_ORIGIN = 'https://sr.bing.com'; | ||
export const EDGE_ORIGIN = 'https://edgeservices.bing.com'; | ||
export const DESIGNER_ORIGIN = 'https://designer.microsoft.com'; | ||
export const DESIGNER_CDN_ORIGIN = 'https://cdn.designerapp.osi.office.net'; | ||
export const DESIGNER_APP_ORIGIN = 'https://designerapp.officeapps.live.com'; | ||
export const DESIGNER_APP_EDOG_ORIGIN = 'https://designerapp.edog.officeapps.live.com'; | ||
export const DESIGNER_DOCUMENT_ORIGIN = 'https://document.designerapp.officeapps.live.com'; | ||
export const DESIGNER_USERASSETS_ORIGIN = 'https://userassets.designerapp.officeapps.live.com'; | ||
export const DESIGNER_MEDIASUGGESTION_ORIGIN = 'https://mediasuggestion.designerapp.officeapps.live.com'; | ||
export const DESIGNER_RTC_ORIGIN = 'https://rtc.designerapp.officeapps.live.com'; | ||
export const KEEP_REQ_HEADERS = [ | ||
'accept', | ||
'accept-encoding', | ||
'accept-language', | ||
'authorization', | ||
'connection', | ||
'cookie', | ||
'upgrade', | ||
'user-agent', | ||
'sec-websocket-extensions', | ||
'sec-websocket-key', | ||
'sec-websocket-version', | ||
'x-request-id', | ||
'content-length', | ||
'content-type', | ||
'access-control-request-headers', | ||
'access-control-request-method', | ||
'sec-ms-gec', | ||
'sec-ms-gec-version', | ||
'x-client-data', | ||
'x-ms-client-request-id', | ||
'x-ms-useragent', | ||
]; | ||
|
||
|
||
|
||
|
||
export function init_CUSTOM_OPTIONS(env) { | ||
CUSTOM_OPTIONS.KievRPSSecAuth = env.USER_KievRPSSecAuth || ''; | ||
CUSTOM_OPTIONS._RwBf = env.USER_RwBf || ''; | ||
CUSTOM_OPTIONS.MUID = env.USER_MUID || ''; | ||
CUSTOM_OPTIONS._U = env.Go_Proxy_BingAI_USER_TOKEN || ''; | ||
CUSTOM_OPTIONS.BYPASS_SERVER = env.BYPASS_SERVER || ''; | ||
CUSTOM_OPTIONS.APIKEY = env.APIKEY || ''; | ||
CUSTOM_OPTIONS.Go_Proxy_BingAI_BLANK_API_KEY = (env.Go_Proxy_BingAI_BLANK_API_KEY != '' && env.Go_Proxy_BingAI_BLANK_API_KEY != undefined && env.Go_Proxy_BingAI_BLANK_API_KEY != null); | ||
CUSTOM_OPTIONS.INFO = env.INFO || ''; | ||
CUSTOM_OPTIONS.NIGHTLY = (env.NIGHTLY != '' && env.NIGHTLY != undefined && env.NIGHTLY != null); | ||
CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY = env.Go_Proxy_BingAI_AUTH_KEY != undefined && env.Go_Proxy_BingAI_AUTH_KEY != null && env.Go_Proxy_BingAI_AUTH_KEY != '' ? env.Go_Proxy_BingAI_AUTH_KEY.split(',') : []; | ||
} |
File renamed without changes.
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,30 @@ | ||
import { WEB_CONFIG, BING_ORIGIN, BING_SOURCE_ORIGIN, EDGE_ORIGIN, DESIGNER_ORIGIN, DESIGNER_CDN_ORIGIN, DESIGNER_APP_ORIGIN , DESIGNER_APP_EDOG_ORIGIN , DESIGNER_DOCUMENT_ORIGIN , DESIGNER_USERASSETS_ORIGIN , DESIGNER_MEDIASUGGESTION_ORIGIN, DESIGNER_RTC_ORIGIN } from "./OPTIONS.js" | ||
|
||
const replaceURL = (body) => { | ||
body = body.replaceAll(BING_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "")); | ||
body = body.replaceAll(EDGE_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "")); | ||
body = body.replaceAll(BING_SOURCE_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/th'); | ||
body = body.replaceAll(DESIGNER_CDN_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-cdn'); | ||
body = body.replaceAll(DESIGNER_APP_EDOG_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-app-edog'); | ||
body = body.replaceAll(DESIGNER_DOCUMENT_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-document'); | ||
body = body.replaceAll(DESIGNER_USERASSETS_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-userassets'); | ||
body = body.replaceAll(DESIGNER_MEDIASUGGESTION_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-mediasuggestion'); | ||
body = body.replaceAll(DESIGNER_RTC_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-rtc'); | ||
body = body.replaceAll(DESIGNER_APP_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer-app'); | ||
body = body.replaceAll(DESIGNER_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", "") + '/designer'); | ||
return body | ||
} | ||
|
||
export const rewriteBody = async (res) => { | ||
const content_type = res.headers.get("Content-Type") || ""; | ||
let encoding = null; | ||
let body = res.body; | ||
if (content_type.startsWith("text/html") || res.url.endsWith("js")) { | ||
let decodedContent = new TextDecoder("utf-8").decode(new Int8Array(await res.clone().arrayBuffer())); | ||
if (decodedContent) { | ||
// @ts-ignore | ||
body = replaceURL(decodedContent); | ||
} | ||
} | ||
return { body, encoding }; | ||
} |
Oops, something went wrong.