Skip to content

Commit

Permalink
[Add] 🍒 Proxy Bing_SR URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Mar 20, 2024
1 parent 8e7fff9 commit d0ac338
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
15 changes: 15 additions & 0 deletions api/Opaluqu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"adams549659584/go-proxy-bingai/common"
"adams549659584/go-proxy-bingai/common/helper"
"net/http"
)

func Opaluqu(w http.ResponseWriter, r *http.Request) {
if !helper.CheckAuth(r) {
helper.UnauthorizedResult(w)
return
}
common.NewSingleHostReverseProxy(common.BING_SR_URT).ServeHTTP(w, r)
}
4 changes: 4 additions & 0 deletions cloudflare/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const WEB_CONFIG = {

const SYDNEY_ORIGIN = 'https://sydney.bing.com';
const BING_ORIGIN = 'https://www.bing.com';
const BING_SR_ORIGIN = 'https://sr.bing.com';
const EDGE_ORIGIN = 'https://edgeservices.bing.com';
const DESIGNER_ORIGIN = 'https://designer.microsoft.com';
const DESIGNER_CDN_ORIGIN = 'https://cdn.designerapp.osi.office.net';
Expand Down Expand Up @@ -115,6 +116,7 @@ const rewriteBody = async (res) => {
// @ts-ignore
body = decodedContent.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_SR_ORIGIN.replace("http://", "").replace("https://", ""), WEB_CONFIG.WORKER_URL.replace("http://", "").replace("https://", ""));
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');
Expand Down Expand Up @@ -459,6 +461,8 @@ export default {
targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search);
} else if (currentUrl.pathname.startsWith('/edgesvc')) {
targetUrl = new URL(EDGE_ORIGIN + currentUrl.pathname + currentUrl.search);
} else if (currentUrl.pathname.startsWith('/opaluqu')) {
targetUrl = new URL(BING_SR_ORIGIN + currentUrl.pathname + currentUrl.search);
} else if (currentUrl.pathname.startsWith('/designer/')) {
targetUrl = new URL(DESIGNER_ORIGIN + currentUrl.pathname.replaceAll('/designer/', '/') + currentUrl.search);
} else if (currentUrl.pathname.startsWith('/designer-cdn/')) {
Expand Down
3 changes: 3 additions & 0 deletions common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
BING_SYDNEY_URL, _ = url.Parse(BING_SYDNEY_DOMAIN)
BING_URL, _ = url.Parse("https://www.bing.com")
EDGE_SVC_URL, _ = url.Parse("https://edgeservices.bing.com")
BING_SR_URT, _ = url.Parse("https://sr.bing.com")
DISIGNER_URL, _ = url.Parse("https://designer.microsoft.com")
DISIGNER_CDN_URL, _ = url.Parse("https://cdn.designerapp.osi.office.net")
DISIGNER_APP_URL, _ = url.Parse("https://designerapp.officeapps.live.com")
Expand Down Expand Up @@ -333,6 +334,7 @@ func replaceResBody(originalBody string, originalScheme string, originalHost str
if originalScheme == "https" {
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_URL.Host, originalHost)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, EDGE_SVC_URL.Host, originalHost)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_SR_URT.Host, originalHost)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_CDN_URL.Host, originalHost+"/designer/cdn")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_EDOG_URL.Host, originalHost+"/designer/app-edog")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_DOCUMENT_URL.Host, originalHost+"/designer/document")
Expand All @@ -345,6 +347,7 @@ func replaceResBody(originalBody string, originalScheme string, originalHost str
originalDomain := fmt.Sprintf("%s://%s", originalScheme, originalHost)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_URL.String(), originalDomain)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, EDGE_SVC_URL.Host, originalHost)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_SR_URT.String(), originalDomain)
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_CDN_URL.String(), originalDomain+"/designer/cdn")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_EDOG_URL.String(), originalDomain+"/designer/app-edog")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_DOCUMENT_URL.String(), originalDomain+"/designer/document")
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {

http.HandleFunc("/edgesvc/", helper.Middleware(api.Edgesvc))
http.HandleFunc("/sydney/", helper.Middleware(api.Sydney))
http.HandleFunc("/opaluqu/", helper.Middleware(api.Opaluqu))

if common.IS_DEBUG_MODE {
http.HandleFunc("/web/", helper.Middleware(web.DebugWebHandler))
Expand Down
4 changes: 0 additions & 4 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
"src": "/edgesvc/.*",
"dest": "/api/edgesvc.go"
},
{
"src": "/sydney/.*",
"dest": "/api/sydney.go"
},
{
"src": "/web/.*",
"dest": "/api/web.go"
Expand Down

0 comments on commit d0ac338

Please sign in to comment.