Skip to content

Commit

Permalink
[Fix] 😅 Vercel Deploy Out of Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Feb 4, 2024
1 parent 81ce4c6 commit 62b685e
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 212 deletions.
51 changes: 51 additions & 0 deletions api/designer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package api

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

func Designer(w http.ResponseWriter, r *http.Request) {
if !helper.CheckAuth(r) {
helper.UnauthorizedResult(w)
return
}
originalPath := r.URL.Path

if strings.Contains(originalPath, "/designer/cdn/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/cdn/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_CDN_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/app/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/app/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_APP_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/app-edog/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/app-edog/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_APP_EDOG_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/document/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/document/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_DOCUMENT_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/userassets/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/userassets/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_USERASSETS_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/rtc/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/rtc/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_RTC_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/mediasuggestion/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/mediasuggestion/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_MEDIASUGGESTION_URL).ServeHTTP(w, r)
return
} else if strings.Contains(originalPath, "/designer/") {
r.URL.Path = strings.ReplaceAll(r.URL.Path, "/designer/", "/")
common.NewSingleHostReverseProxy(common.DISIGNER_URL).ServeHTTP(w, r)
return
}
common.NewSingleHostReverseProxy(common.BING_URL).ServeHTTP(w, r)
}
15 changes: 0 additions & 15 deletions api/designer/designer-app-edog.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-app.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-cdn.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-document.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-mediasuggestion.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-rtc.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer-userassets.go

This file was deleted.

15 changes: 0 additions & 15 deletions api/designer/designer.go

This file was deleted.

67 changes: 18 additions & 49 deletions common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,13 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
if strings.Contains(req.Referer(), "web/compose.html") {
req.Header.Set("Referer", fmt.Sprintf("%s/edgesvc/compose", EDGE_SVC_URL.String()))
req.Header.Set("Origin", EDGE_SVC_URL.String())
} else if strings.Contains(originalPath, "/edgesvc/") {
} else if strings.Contains(originalPath, "/sydney/") {
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", EDGE_SVC_URL.String())
} else if strings.Contains(originalPath, "/designer/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_URL.String())
} else if strings.Contains(originalPath, "/designer-cdn/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-cdn/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_CDN_URL.String())
} else if strings.Contains(originalPath, "/designer-app/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-app/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_APP_URL.String())
} else if strings.Contains(originalPath, "/designer-app-edog/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-app-edog/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_APP_EDOG_URL.String())
} else if strings.Contains(originalPath, "/designer-document/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-document/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_DOCUMENT_URL.String())
} else if strings.Contains(originalPath, "/designer-userassets/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-userassets/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_USERASSETS_URL.String())
} else if strings.Contains(originalPath, "/designer-rtc/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-rtc/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_RTC_URL.String())
} else if strings.Contains(originalPath, "/designer-mediasuggestion/") {
req.URL.Path = strings.ReplaceAll(req.URL.Path, "/designer-mediasuggestion/", "/")
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", DISIGNER_MEDIASUGGESTION_URL.String())
req.Header.Set("Origin", BING_URL.String())
req.Header.Set("Host", BING_SYDNEY_URL.Host)
} else {
req.Header.Set("Referer", fmt.Sprintf("%s/search?q=Bing+AI", BING_URL.String()))
req.Header.Set("Origin", BING_URL.String())
req.Header.Set("Origin", target.String())
}

// 同一会话尽量保持相同的随机IP
Expand Down Expand Up @@ -359,25 +328,25 @@ 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, 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")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_USERASSETS_URL.Host, originalHost+"/designer-userassets")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_MEDIASUGGESTION_URL.Host, originalHost+"/designer-mediasuggestion")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_RTC_URL.Host, originalHost+"/designer-rtc")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_URL.Host, originalHost+"/designer-app")
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")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_USERASSETS_URL.Host, originalHost+"/designer/userassets")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_MEDIASUGGESTION_URL.Host, originalHost+"/designer/mediasuggestion")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_RTC_URL.Host, originalHost+"/designer/rtc")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_URL.Host, originalHost+"/designer/app")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_URL.Host, originalHost+"/designer")
} else {
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, 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")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_USERASSETS_URL.String(), originalDomain+"/designer-userassets")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_MEDIASUGGESTION_URL.String(), originalDomain+"/designer-mediasuggestion")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_RTC_URL.String(), originalDomain+"/designer-rtc")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_URL.String(), originalDomain+"/designer-app")
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")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_USERASSETS_URL.String(), originalDomain+"/designer/userassets")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_MEDIASUGGESTION_URL.String(), originalDomain+"/designer/mediasuggestion")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_RTC_URL.String(), originalDomain+"/designer/rtc")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_APP_URL.String(), originalDomain+"/designer/app")
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, DISIGNER_URL.String(), originalDomain+"/designer")
}

Expand Down
10 changes: 1 addition & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"adams549659584/go-proxy-bingai/api"
"adams549659584/go-proxy-bingai/api/designer"
v1 "adams549659584/go-proxy-bingai/api/v1"
"adams549659584/go-proxy-bingai/common"
"log"
Expand All @@ -26,14 +25,7 @@ func main() {
http.HandleFunc("/turing/captcha/challenge", api.ChallengeHandler)
http.HandleFunc("/challenge/verify", api.VerifyHandler)

http.HandleFunc("/designer/", designer.Designer)
http.HandleFunc("/designer-app/", designer.DesignerApp)
http.HandleFunc("/designer-app-edog/", designer.DesignerAppEdog)
http.HandleFunc("/designer-cdn/", designer.DesignerCDN)
http.HandleFunc("/designer-document/", designer.DesignerDocument)
http.HandleFunc("/designer-userassets/", designer.DesignerUserassets)
http.HandleFunc("/designer-mediasuggestion/", designer.DesignerMediasuggestion)
http.HandleFunc("/designer-rtc/", designer.DesignerRTC)
http.HandleFunc("/designer/", api.Designer)

http.HandleFunc("/edgesvc/", api.Edgesvc)
http.HandleFunc("/sydney/", api.Sydney)
Expand Down
36 changes: 2 additions & 34 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"version": 2,
"builds": [
{
"src": "/api/{index,web,sydney,edgesvc,sys-config,bypass,challenge,verify}.go",
"use": "@vercel/go"
},
{
"src": "/api/designer/{designer,designer-app,designer-app-edog,designer-cdn,designer-document,designer-mediasuggestion,designer-userassets,designer-rtc}.go",
"src": "/api/{index,web,sydney,edgesvc,designer,sys-config,bypass,challenge,verify}.go",
"use": "@vercel/go"
},
{
Expand Down Expand Up @@ -50,35 +46,7 @@
},
{
"src": "/designer/.*",
"dest": "/api/designer/designer.go"
},
{
"src": "/designer-app/.*",
"dest": "/api/designer/designer-app.go"
},
{
"src": "/designer-app-edog/.*",
"dest": "/api/designer/designer-app-edog.go"
},
{
"src": "/designer-cdn/.*",
"dest": "/api/designer/designer-cdn.go"
},
{
"src": "/designer-document/.*",
"dest": "/api/designer/designer-document.go"
},
{
"src": "/designer-mediasuggestion/.*",
"dest": "/api/designer/designer-mediasuggestion.go"
},
{
"src": "/designer-userassets/.*",
"dest": "/api/designer/designer-userassets.go"
},
{
"src": "/designer-rtc/.*",
"dest": "/api/designer/designer-rtc.go"
"dest": "/api/designer.go"
},
{
"src": "/edgesvc/.*",
Expand Down

0 comments on commit 62b685e

Please sign in to comment.