Update pages/api/chatgpt4.js
Browse files- pages/api/chatgpt4.js +44 -1
pages/api/chatgpt4.js
CHANGED
|
@@ -10,6 +10,48 @@ export const config = {
|
|
| 10 |
"response": "text",
|
| 11 |
"testURL": "./api/chatgpt4?prompt=hello"
|
| 12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
export default async function handler(req, res) {
|
| 14 |
if (req.method === 'GET') {
|
| 15 |
// Extract prompt from the query parameters
|
|
@@ -38,7 +80,8 @@ export default async function handler(req, res) {
|
|
| 38 |
|
| 39 |
// Define the headers
|
| 40 |
const headers = {
|
| 41 |
-
'X-Wp-Nonce': restNonce
|
|
|
|
| 42 |
};
|
| 43 |
|
| 44 |
// Send POST request with headers
|
|
|
|
| 10 |
"response": "text",
|
| 11 |
"testURL": "./api/chatgpt4?prompt=hello"
|
| 12 |
}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
function generateUserAgent() {
|
| 16 |
+
const osList = [
|
| 17 |
+
"Windows NT 10.0; Win64; x64",
|
| 18 |
+
"Windows NT 10.0; WOW64",
|
| 19 |
+
"Windows NT 6.1; Win64; x64",
|
| 20 |
+
"Windows NT 6.1; WOW64",
|
| 21 |
+
"Macintosh; Intel Mac OS X 10_15_7",
|
| 22 |
+
"Macintosh; Intel Mac OS X 10_14_6",
|
| 23 |
+
"X11; Ubuntu; Linux x86_64",
|
| 24 |
+
"X11; Linux x86_64"
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
+
const webkitVersion = `${getRandomInt(500, 600)}.${getRandomInt(0, 99)}.${getRandomInt(0, 999)}`;
|
| 28 |
+
const chromeVersion = `Chrome/${getRandomInt(80, 90)}.${getRandomInt(0, 9999)}.${getRandomInt(0, 999)}`;
|
| 29 |
+
const safariVersion = `Safari/${getRandomInt(500, 600)}.${getRandomInt(0, 99)}.${getRandomInt(0, 999)}`;
|
| 30 |
+
const firefoxVersion = `Gecko/20100101 Firefox/${getRandomInt(80, 90)}.${getRandomInt(0, 99)}`;
|
| 31 |
+
|
| 32 |
+
const os = randomChoice(osList);
|
| 33 |
+
const browser = randomChoice(['Chrome', 'Safari']);
|
| 34 |
+
const engine = randomChoice(['Edge', 'OPR']) || 'Gecko/20100101 Firefox';
|
| 35 |
+
|
| 36 |
+
return `Mozilla/5.0 (${os}) AppleWebKit/${webkitVersion} (KHTML, like Gecko) ${browser}/${browser === 'Chrome' ? chromeVersion : safariVersion} ${engine}/${browser === 'Chrome' ? chromeVersion : firefoxVersion}`;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const userAgent = generateUserAgent();
|
| 40 |
+
const navigator = {
|
| 41 |
+
userAgent: userAgent,
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
console.log(userAgent);
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
function getRandomInt(min, max) {
|
| 48 |
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function randomChoice(arr) {
|
| 52 |
+
return arr[Math.floor(Math.random() * arr.length)];
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
export default async function handler(req, res) {
|
| 56 |
if (req.method === 'GET') {
|
| 57 |
// Extract prompt from the query parameters
|
|
|
|
| 80 |
|
| 81 |
// Define the headers
|
| 82 |
const headers = {
|
| 83 |
+
'X-Wp-Nonce': restNonce,
|
| 84 |
+
'User-Agent': generateUserAgent()
|
| 85 |
};
|
| 86 |
|
| 87 |
// Send POST request with headers
|