-
Notifications
You must be signed in to change notification settings - Fork 13.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
1 parent
842e02b
commit bfd58c5
Showing
35 changed files
with
2,055 additions
and
1,306 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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
package helper | ||
|
||
import ( | ||
"adams549659584/go-proxy-bingai/common" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type Response struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
Data interface{} `json:"data"` | ||
} | ||
|
||
func CommonResult(w http.ResponseWriter, code int, msg string, data interface{}) error { | ||
res := Response{ | ||
Code: code, | ||
Message: msg, | ||
Data: data, | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
err := json.NewEncoder(w).Encode(res) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func SuccessResult(w http.ResponseWriter, data interface{}) error { | ||
return CommonResult(w, http.StatusOK, "success", data) | ||
} | ||
|
||
func ErrorResult(w http.ResponseWriter, code int, msg string) error { | ||
return CommonResult(w, code, msg, nil) | ||
} | ||
|
||
func UnauthorizedResult(w http.ResponseWriter) error { | ||
return ErrorResult(w, http.StatusUnauthorized, "unauthorized") | ||
} | ||
|
||
func CheckAuth(r *http.Request) bool { | ||
isAuth := true | ||
if len(common.AUTH_KEY) > 0 { | ||
ckAuthKey, _ := r.Cookie(common.AUTH_KEY_COOKIE_NAME) | ||
isAuth = ckAuthKey != nil && len(ckAuthKey.Value) > 0 && common.AUTH_KEY == ckAuthKey.Value | ||
} | ||
return isAuth | ||
} |
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,15 @@ | ||
package api | ||
|
||
import ( | ||
"adams549659584/go-proxy-bingai/api/helper" | ||
"adams549659584/go-proxy-bingai/common" | ||
"net/http" | ||
) | ||
|
||
func Sydney(w http.ResponseWriter, r *http.Request) { | ||
if !helper.CheckAuth(r) { | ||
helper.UnauthorizedResult(w) | ||
return | ||
} | ||
common.NewSingleHostReverseProxy(common.BING_SYDNEY_URL).ServeHTTP(w, r) | ||
} |
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,24 @@ | ||
package api | ||
|
||
import ( | ||
"adams549659584/go-proxy-bingai/api/helper" | ||
"adams549659584/go-proxy-bingai/common" | ||
"net/http" | ||
) | ||
|
||
type SysConfig struct { | ||
// 是否系统配置 cookie | ||
IsSysCK bool `json:"isSysCK"` | ||
// 是否已授权 | ||
IsAuth bool `json:"isAuth"` | ||
SydneyBaseUrl string `json:"sydneyBaseUrl"` | ||
} | ||
|
||
func SysConf(w http.ResponseWriter, r *http.Request) { | ||
isAuth := helper.CheckAuth(r) | ||
conf := SysConfig{ | ||
IsSysCK: len(common.USER_TOKEN_LIST) > 0, | ||
IsAuth: isAuth, | ||
} | ||
helper.SuccessResult(w, conf) | ||
} |
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,124 @@ | ||
const SYDNEY_ORIGIN = 'https://sydney.bing.com'; | ||
const KEEP_REQ_HEADERS = [ | ||
'accept', | ||
'accept-encoding', | ||
'accept-language', | ||
'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', | ||
]; | ||
const IP_RANGE = [ | ||
['3.2.50.0', '3.5.31.255'], //192,000 | ||
['3.12.0.0', '3.23.255.255'], //786,432 | ||
['3.30.0.0', '3.33.34.255'], //205,568 | ||
['3.40.0.0', '3.63.255.255'], //1,572,864 | ||
['3.80.0.0', '3.95.255.255'], //1,048,576 | ||
['3.100.0.0', '3.103.255.255'], //262,144 | ||
['3.116.0.0', '3.119.255.255'], //262,144 | ||
['3.128.0.0', '3.247.255.255'], //7,864,320 | ||
]; | ||
|
||
/** | ||
* 随机整数 [min,max) | ||
* @param {number} min | ||
* @param {number} max | ||
* @returns | ||
*/ | ||
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min; | ||
|
||
/** | ||
* ip 转 int | ||
* @param {string} ip | ||
* @returns | ||
*/ | ||
const ipToInt = (ip) => { | ||
const ipArr = ip.split('.'); | ||
let result = 0; | ||
result += +ipArr[0] << 24; | ||
result += +ipArr[1] << 16; | ||
result += +ipArr[2] << 8; | ||
result += +ipArr[3]; | ||
return result; | ||
}; | ||
|
||
/** | ||
* int 转 ip | ||
* @param {number} intIP | ||
* @returns | ||
*/ | ||
const intToIp = (intIP) => { | ||
return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`; | ||
}; | ||
|
||
const getRandomIP = () => { | ||
const randIndex = getRandomInt(0, IP_RANGE.length); | ||
const startIp = IP_RANGE[randIndex][0]; | ||
const endIp = IP_RANGE[randIndex][1]; | ||
const startIPInt = ipToInt(startIp); | ||
const endIPInt = ipToInt(endIp); | ||
const randomInt = getRandomInt(startIPInt, endIPInt); | ||
const randomIP = intToIp(randomInt); | ||
return randomIP; | ||
}; | ||
|
||
export default { | ||
/** | ||
* fetch | ||
* @param {Request} request | ||
* @param {*} env | ||
* @param {*} ctx | ||
* @returns | ||
*/ | ||
async fetch(request, env, ctx) { | ||
const currentUrl = new URL(request.url); | ||
const targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search); | ||
|
||
const newHeaders = new Headers(); | ||
request.headers.forEach((value, key) => { | ||
// console.log(`old : ${key} : ${value}`); | ||
if (KEEP_REQ_HEADERS.includes(key)) { | ||
newHeaders.set(key, value); | ||
} | ||
}); | ||
newHeaders.set('host', targetUrl.host); | ||
newHeaders.set('origin', targetUrl.origin); | ||
newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI'); | ||
const randIP = getRandomIP(); | ||
// console.log('randIP : ', randIP); | ||
newHeaders.set('X-Forwarded-For', randIP); | ||
const oldUA = request.headers.get('user-agent'); | ||
const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android'); | ||
if (isMobile) { | ||
newHeaders.set( | ||
'user-agent', | ||
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012' | ||
); | ||
} else { | ||
newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35'); | ||
} | ||
|
||
// newHeaders.forEach((value, key) => console.log(`${key} : ${value}`)); | ||
const newReq = new Request(targetUrl, { | ||
method: request.method, | ||
headers: newHeaders, | ||
body: request.body, | ||
}); | ||
// console.log('request url : ', newReq.url); | ||
const res = await fetch(newReq); | ||
return res; | ||
// const newRes = new Response(res.body, res); | ||
// newRes.headers.set('access-control-allow-origin', '*'); | ||
// newRes.headers.set('access-control-allow-methods', '*'); | ||
// newRes.headers.set('access-control-allow-headers', '*'); | ||
// return newRes; | ||
}, | ||
}; |
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.
bfd58c5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
go-proxy-bingai – ./
go-proxy-bingai-adams549659584.vercel.app
go-proxy-bingai-git-master-adams549659584.vercel.app
go-proxy-bingai-two.vercel.app
bing-vercel.vcanbb.top
bfd58c5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assee
bfd58c5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you help me