Skip to content

Commit

Permalink
chore: 细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 12, 2023
1 parent 7f0cfde commit e22958b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bingo",
"version": "0.6.3",
"version": "0.6.4",
"private": true,
"scripts": {
"dev": "cross-env DEBUG=bingo* next dev --hostname 0.0.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/chat-notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getAction(error: ChatError, reset: () => void) {
reset()
return (
<div>
你已达到每日最大发送消息次数,请<a href={`#dialog="settings"`}>更换账号</a>或隔一天后重试
请求次数过快,已被限流,请稍候重试...
</div>
)
}
Expand Down Expand Up @@ -41,7 +41,7 @@ function getAction(error: ChatError, reset: () => void) {
if (error.code === ErrorCode.CONVERSATION_LIMIT) {
return (
<div>
当前话题已中止,请点
当前话题已中止,请点击
<a href={`#dialog="reset"`}>重新开始</a>
开启新的对话
</div>
Expand Down
37 changes: 19 additions & 18 deletions src/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export function Settings() {
toast.error('用户信息格式不正确')
return
}
if (RegExp.$1 === 'cn' && checked === false) {
toast.error('你配置的中文域名 cn.bing.com 仅支持画图')
if (RegExp.$1 === 'cn') {
toast.error('你配置的国内域名 cn.bing.com 仅支持画图')
setImageOnly(true)
return
}
setImageOnly(checked)
Expand Down Expand Up @@ -80,7 +81,9 @@ export function Settings() {
placeholder="在此填写用户信息,格式: curl 'https://www.bing.com/turing/captcha/challenge' ..."
onChange={e => {
setCurlValue(e.target.value)
setImageOnly(!Boolean(e.target.value))
if (!/^\s*curl ['"]https:\/\/www\.bing\.com\/turing\/captcha\/challenge['"]/.test(e.target.value)) {
setImageOnly(true)
}
}}
/>
<div className="flex gap-2">
Expand All @@ -93,23 +96,21 @@ export function Settings() {
className={`${imageOnly ? 'translate-x-6' : 'translate-x-1'} inline-block h-4 w-4 transform rounded-full bg-white transition`}
/>
</Switch>
用户信息仅用于画图(账号异常时使用)
尝试修复用户信息异常
</div>

{!imageOnly && (
<div className="flex gap-2">
<Switch
checked={enabledHistory}
className={`${enabledHistory ? 'bg-blue-600' : 'bg-gray-200'} relative inline-flex h-6 w-11 items-center rounded-full`}
onChange={(checked: boolean) => setHistory(checked)}
>
<span
className={`${enabledHistory ? 'translate-x-6' : 'translate-x-1'} inline-block h-4 w-4 transform rounded-full bg-white transition`}
/>
</Switch>
启用历史记录
</div>
)}
<div className="flex gap-2">
<Switch
checked={enabledHistory}
className={`${enabledHistory ? 'bg-blue-600' : 'bg-gray-200'} relative inline-flex h-6 w-11 items-center rounded-full`}
onChange={(checked: boolean) => setHistory(checked)}
>
<span
className={`${enabledHistory ? 'translate-x-6' : 'translate-x-1'} inline-block h-4 w-4 transform rounded-full bg-white transition`}
/>
</Switch>
启用历史记录
</div>

<Button variant="ghost" className="bg-[#F5F5F5] hover:bg-[#F2F2F2]" onClick={() => copyToClipboard(btoa(curlValue))}>
转成 BING_HEADER 并复制
Expand Down
11 changes: 9 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function extraHeadersFromCookie(cookies: Partial<{ [key: string]: string
}

export function parseCookie(cookie: string, cookieName: string) {
if (!cookie || !cookieName) return ''
const targetCookie = new RegExp(`(?:[; ]|^)${cookieName}=([^;]*)`).test(cookie) ? RegExp.$1 : cookie
return targetCookie ? decodeURIComponent(targetCookie).trim() : cookie.indexOf('=') === -1 ? cookie.trim() : ''
}
Expand Down Expand Up @@ -140,18 +141,24 @@ export function parseUA(ua?: string, default_ua = DEFAULT_UA) {

export function mockUser(cookies: Partial<{ [key: string]: string }>) {
const {
BING_HEADER,
BING_UA = process.env.BING_UA,
BING_IP = '',
} = cookies
const ua = parseUA(BING_UA)

const { _U, MUID } = parseCookies(extraHeadersFromCookie({
BING_HEADER,
...cookies,
}).cookie, ['MUID'])

return {
'x-forwarded-for': BING_IP || randomIP(),
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'User-Agent': ua!,
'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32',
cookie: `_U=${defaultUID}; MUID=${muid()}`,
cookie: `_U=${_U || defaultUID}; MUID=${MUID || muid()}`,
}
}

Expand All @@ -170,7 +177,7 @@ export function createHeaders(cookies: Partial<{ [key: string]: string }>, type?
const headers = extraHeadersFromCookie({
BING_HEADER,
...cookies,
}) || {}
})
headers['x-forwarded-for'] = BING_IP || randomIP()
return headers
}
Expand Down

0 comments on commit e22958b

Please sign in to comment.