Skip to content

Commit

Permalink
chore: ⚡ 未登录不显示聊天历史、屏蔽大多数日志请求、ua 区分手机电脑
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 17, 2023
1 parent 8ca6c9d commit 128fbb8
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 151 deletions.
23 changes: 19 additions & 4 deletions common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
// req.Header.Set("User-Agent", "iPhone Mobile "+ua)
// }
}
req.Header.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")

ua := req.UserAgent()
isMobile := strings.Contains(ua, "Mobile") || strings.Contains(ua, "Android")

// m pc 画图大小不一样
if isMobile {
req.Header.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 {
req.Header.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")
}

for hKey, _ := range req.Header {
if _, ok := KEEP_REQ_HEADER_MAP[hKey]; !ok {
Expand Down Expand Up @@ -269,10 +278,16 @@ func getRandCookie(req *http.Request) (int, string) {

func replaceResBody(originalBody string, originalScheme string, originalHost string) string {
modifiedBodyStr := originalBody
originalDomain := fmt.Sprintf("%s://%s", originalScheme, originalHost)

if strings.Contains(modifiedBodyStr, BING_URL.String()) {
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_URL.String(), originalDomain)
if originalScheme == "https" {
if strings.Contains(modifiedBodyStr, BING_URL.Host) {
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_URL.Host, originalHost)
}
} else {
originalDomain := fmt.Sprintf("%s://%s", originalScheme, originalHost)
if strings.Contains(modifiedBodyStr, BING_URL.String()) {
modifiedBodyStr = strings.ReplaceAll(modifiedBodyStr, BING_URL.String(), originalDomain)
}
}

// 对话暂时支持国内网络,而且 Vercel 还不支持 Websocket ,先不用
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-proxy-bingai",
"version": "1.6.5",
"version": "1.6.6",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
26 changes: 13 additions & 13 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/public/js/bing/chat/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ _G = {
DA: 'PUSE01',
SUIH: 'FfN6lYBDNDOEzj4vnSOJqQ',
adc: 'b_ad',
EF: { cookss: 1, bmcov: 1, crossdomainfix: 1, bmasynctrigger: 1, bmasynctrigger3: 1, newtabsloppyclick: 1, chevroncheckmousemove: 1 },
// logsb 启用 sendBeacon 推送日志,并在 sendBeacon 阻止
EF: { cookss: 1, bmcov: 1, crossdomainfix: 1, bmasynctrigger: 1, bmasynctrigger3: 1, newtabsloppyclick: 1, chevroncheckmousemove: 1, logsb: 1 },
gpUrl: '/fd/ls/GLinkPing.aspx?',
};
_G.lsUrl = '/fd/ls/l?IG=' + _G.IG;
Expand Down
23 changes: 19 additions & 4 deletions frontend/src/views/chat/components/ChatPrompt/ChatPrompt.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { onMounted, ref, computed } from 'vue';
import { NEmpty, NButton } from 'naive-ui';
import conversationCssText from '@/assets/css/conversation.css?raw';
import { usePromptStore, type IPrompt } from '@/stores/modules/prompt';
Expand Down Expand Up @@ -28,6 +28,10 @@ const randIpCookieName = 'BingAI_Rand_IP';
const isPromptScrolling = ref(false);
const promptItemHeight = 130;
const isShowHistory = computed(() => {
return (CIB.vm.isMobile && CIB.vm.sidePanel.isVisibleMobile) || (!CIB.vm.isMobile && CIB.vm.sidePanel.isVisibleDesktop);
});
onMounted(async () => {
await initChat();
// show
Expand All @@ -50,6 +54,10 @@ const initChat = async () => {
const checkUserToken = () => {
const userCookieVal = cookies.get(userTokenCookieName);
if (!userCookieVal) {
// 未登录不显示历史记录
CIB.vm.sidePanel.isVisibleMobile = false;
CIB.vm.sidePanel.isVisibleDesktop = false;
// 创建会话id
tryCreateConversationId();
}
};
Expand Down Expand Up @@ -165,7 +173,7 @@ const handleInputTextKey = (ev: KeyboardEvent) => {
switch (ev.key) {
case 'ArrowUp':
{
ev.preventDefault();
// ev.preventDefault();
if (selectedPromptIndex.value > 0) {
selectedPromptIndex.value--;
if (scrollbarRef.value) {
Expand All @@ -176,7 +184,7 @@ const handleInputTextKey = (ev: KeyboardEvent) => {
break;
case 'ArrowDown':
{
ev.preventDefault();
// ev.preventDefault();
if (selectedPromptIndex.value < searchPromptList.value.length - 1) {
selectedPromptIndex.value++;
if (scrollbarRef.value) {
Expand Down Expand Up @@ -224,7 +232,14 @@ const handlePromptListScroll = () => {
<template>
<LoadingSpinner :is-show="isShowLoading" />
<main>
<div v-if="isShowChatPrompt" class="box-border fixed bottom-[110px] w-full flex justify-center px-[14px] md:px-[170px] xl:px-[220px] z-999">
<div
v-if="isShowChatPrompt"
class="box-border fixed bottom-[110px] w-full flex justify-center px-[14px] md:px-[34px] z-999"
:class="{
'md:px-[170px]': isShowHistory,
'xl:px-[220px]': isShowHistory,
}"
>
<div class="w-0 md:w-[60px]"></div>
<VirtualList
ref="scrollbarRef"
Expand Down
Loading

0 comments on commit 128fbb8

Please sign in to comment.