chase535
commited on
Commit
·
b47606f
1
Parent(s):
92b99f6
同步上游更新
Browse files- src/app/globals.scss +1 -5
- src/lib/utils.ts +14 -19
- src/pages/api/blob.jpg.ts +1 -1
- src/pages/api/create.ts +5 -4
- src/pages/api/image.ts +1 -1
- src/pages/api/kblob.ts +1 -1
- src/pages/api/sydney.ts +1 -1
src/app/globals.scss
CHANGED
@@ -398,12 +398,8 @@ body {
|
|
398 |
}
|
399 |
|
400 |
.scroll-button {
|
401 |
-
bottom:
|
402 |
z-index: 50;
|
403 |
-
|
404 |
-
@media (max-width: 767px) {
|
405 |
-
bottom: 8rem;
|
406 |
-
}
|
407 |
}
|
408 |
|
409 |
.header-title {
|
|
|
398 |
}
|
399 |
|
400 |
.scroll-button {
|
401 |
+
bottom: 8rem;
|
402 |
z-index: 50;
|
|
|
|
|
|
|
|
|
403 |
}
|
404 |
|
405 |
.header-title {
|
src/lib/utils.ts
CHANGED
@@ -163,34 +163,29 @@ export function mockUser(cookies: Partial<{ [key: string]: string }>) {
|
|
163 |
'User-Agent': ua!,
|
164 |
'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32',
|
165 |
'referer': 'https://www.bing.com/search?showconv=1&sendquery=1&q=Bing%20AI&form=MY02CJ&OCID=MY02CJ&OCID=MY02CJ&pl=launch',
|
166 |
-
cookie: `_U=${_U || defaultUID}; MUID=${MUID ||
|
167 |
}
|
168 |
}
|
169 |
|
170 |
-
export function createHeaders(cookies: Partial<{ [key: string]: string }>,
|
171 |
let {
|
172 |
BING_HEADER = process.env.BING_HEADER,
|
173 |
BING_IP = process.env.BING_IP || '',
|
174 |
IMAGE_ONLY = process.env.IMAGE_ONLY ?? '1',
|
175 |
} = cookies || {}
|
176 |
-
|
177 |
-
if (BING_HEADER) {
|
178 |
-
|
179 |
-
(imageOnly && type === 'image')
|
180 |
-
|| !imageOnly
|
181 |
-
) {
|
182 |
-
const headers = extraHeadersFromCookie({
|
183 |
-
BING_HEADER,
|
184 |
-
...cookies,
|
185 |
-
})
|
186 |
-
// headers['x-forwarded-for'] = BING_IP || randomIP()
|
187 |
-
headers['user-agent'] = parseUA(headers['user-agent'])
|
188 |
-
headers['referer'] = 'https://www.bing.com/search?showconv=1&sendquery=1&q=Bing%20AI&form=MY02CJ&OCID=MY02CJ&OCID=MY02CJ&pl=launch'
|
189 |
-
headers['x-ms-useragent'] = headers['x-ms-useragent'] || 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32'
|
190 |
-
return headers
|
191 |
-
}
|
192 |
}
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
}
|
195 |
|
196 |
export class WatchDog {
|
|
|
163 |
'User-Agent': ua!,
|
164 |
'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32',
|
165 |
'referer': 'https://www.bing.com/search?showconv=1&sendquery=1&q=Bing%20AI&form=MY02CJ&OCID=MY02CJ&OCID=MY02CJ&pl=launch',
|
166 |
+
cookie: `_U=${_U || defaultUID}; MUID=${MUID || randomString(32)}`,
|
167 |
}
|
168 |
}
|
169 |
|
170 |
+
export function createHeaders(cookies: Partial<{ [key: string]: string }>, useMock?: boolean) {
|
171 |
let {
|
172 |
BING_HEADER = process.env.BING_HEADER,
|
173 |
BING_IP = process.env.BING_IP || '',
|
174 |
IMAGE_ONLY = process.env.IMAGE_ONLY ?? '1',
|
175 |
} = cookies || {}
|
176 |
+
useMock = useMock ?? /^(1|true|yes)$/i.test(String(IMAGE_ONLY))
|
177 |
+
if (!BING_HEADER || useMock) {
|
178 |
+
return mockUser(cookies)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
}
|
180 |
+
const headers = extraHeadersFromCookie({
|
181 |
+
BING_HEADER,
|
182 |
+
...cookies,
|
183 |
+
})
|
184 |
+
headers['x-forwarded-for'] = BING_IP || randomIP()
|
185 |
+
headers['user-agent'] = parseUA(headers['user-agent'])
|
186 |
+
headers['referer'] = 'https://www.bing.com/search?showconv=1&sendquery=1&q=Bing%20AI&form=MY02CJ&OCID=MY02CJ&OCID=MY02CJ&pl=launch'
|
187 |
+
headers['x-ms-useragent'] = headers['x-ms-useragent'] || 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32'
|
188 |
+
return headers
|
189 |
}
|
190 |
|
191 |
export class WatchDog {
|
src/pages/api/blob.jpg.ts
CHANGED
@@ -14,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|
14 |
{
|
15 |
method: 'GET',
|
16 |
headers: {
|
17 |
-
...createHeaders(req.cookies,
|
18 |
Referer: 'https://www.bing.com/search?q=Bing+AI&showconv=1',
|
19 |
'Sec-Fetch-Dest': 'iframe',
|
20 |
},
|
|
|
14 |
{
|
15 |
method: 'GET',
|
16 |
headers: {
|
17 |
+
...createHeaders(req.cookies, false),
|
18 |
Referer: 'https://www.bing.com/search?q=Bing+AI&showconv=1',
|
19 |
'Sec-Fetch-Dest': 'iframe',
|
20 |
},
|
src/pages/api/create.ts
CHANGED
@@ -43,13 +43,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|
43 |
}
|
44 |
|
45 |
debug('headers', headers)
|
|
|
|
|
|
|
46 |
res.writeHead(200, {
|
47 |
'Content-Type': 'application/json',
|
48 |
})
|
49 |
-
|
50 |
-
|
51 |
-
// userIpAddress: endpoint && !endpoint.endsWith('.bing.com') ? await lookupPromise(endpoint.split('/')[0]) : headers['x-forwarded-for']
|
52 |
-
}))
|
53 |
return
|
54 |
}
|
55 |
await sleep(2000)
|
|
|
43 |
}
|
44 |
|
45 |
debug('headers', headers)
|
46 |
+
const cookies = [`BING_IP=${headers['x-forwarded-for']}`]
|
47 |
+
res.setHeader('set-cookie', cookies.map(cookie => `${cookie.trim()}; Max-Age=${86400 * 30}; Path=/;`))
|
48 |
+
|
49 |
res.writeHead(200, {
|
50 |
'Content-Type': 'application/json',
|
51 |
})
|
52 |
+
|
53 |
+
res.end(JSON.stringify(json))
|
|
|
|
|
54 |
return
|
55 |
}
|
56 |
await sleep(2000)
|
src/pages/api/image.ts
CHANGED
@@ -16,7 +16,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|
16 |
})
|
17 |
}
|
18 |
try {
|
19 |
-
const headers = createHeaders(req.cookies,
|
20 |
|
21 |
debug('headers', headers)
|
22 |
const response = await createImage(String(prompt), String(id), {
|
|
|
16 |
})
|
17 |
}
|
18 |
try {
|
19 |
+
const headers = createHeaders(req.cookies, false)
|
20 |
|
21 |
debug('headers', headers)
|
22 |
const response = await createImage(String(prompt), String(id), {
|
src/pages/api/kblob.ts
CHANGED
@@ -19,7 +19,7 @@ export const config = {
|
|
19 |
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
20 |
try {
|
21 |
const { knowledgeRequest, imageBase64 } = req.body as KBlobRequest
|
22 |
-
const headers = createHeaders(req.cookies,
|
23 |
|
24 |
const formData = new FormData()
|
25 |
formData.append('knowledgeRequest', JSON.stringify(knowledgeRequest))
|
|
|
19 |
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
20 |
try {
|
21 |
const { knowledgeRequest, imageBase64 } = req.body as KBlobRequest
|
22 |
+
const headers = createHeaders(req.cookies, false)
|
23 |
|
24 |
const formData = new FormData()
|
25 |
formData.append('knowledgeRequest', JSON.stringify(knowledgeRequest))
|
src/pages/api/sydney.ts
CHANGED
@@ -14,7 +14,7 @@ const { WS_ENDPOINT = 'sydney.bing.com' } = process.env
|
|
14 |
|
15 |
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
16 |
const conversationContext = req.body
|
17 |
-
const headers = createHeaders(req.cookies, req.cookies['BING_HEADER1']
|
18 |
const id = headers['x-forwarded-for']
|
19 |
// headers['x-forwarded-for'] = conversationContext?.userIpAddress || headers['x-forwarded-for']
|
20 |
|
|
|
14 |
|
15 |
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
16 |
const conversationContext = req.body
|
17 |
+
const headers = createHeaders(req.cookies, Boolean(req.cookies['BING_HEADER1']))
|
18 |
const id = headers['x-forwarded-for']
|
19 |
// headers['x-forwarded-for'] = conversationContext?.userIpAddress || headers['x-forwarded-for']
|
20 |
|