mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-30 09:53:02 +00:00
Some checks failed
Deploy doc image to cf / deploy-production (push) Has been cancelled
Deploy doc image by kubeconfig / build-fastgpt-docs-images (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (push) Has been cancelled
Deploy doc image by kubeconfig / update-docs-image (push) Has been cancelled
* update: Add type * fix: update import statement for NextApiRequest type * fix: update imports to use type for LexicalEditor and EditorState * Refactor imports to use 'import type' for type-only imports across multiple files - Updated imports in various components and API files to use 'import type' for better clarity and to optimize TypeScript's type checking. - Ensured consistent usage of type imports in files related to chat, dataset, workflow, and user management. - Improved code readability and maintainability by distinguishing between value and type imports. * refactor: remove old ESLint configuration and add new rules - Deleted the old ESLint configuration file from the app project. - Added a new ESLint configuration file with updated rules and settings. - Changed imports to use type-only imports in various files for better clarity and performance. - Updated TypeScript configuration to remove unnecessary options. - Added an ESLint ignore file to exclude build and dependency directories from linting. * fix: update imports to use 'import type' for type-only imports in schema files
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import type { Page } from 'puppeteer';
|
|
import randomUseragent from 'random-useragent';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
const getRandomUserAgent = () => {
|
|
return randomUseragent.getRandom();
|
|
};
|
|
|
|
const getRandomPlatform = () => {
|
|
const platforms = ['Win32', 'MacIntel', 'Linux x86_64'];
|
|
return platforms[Math.floor(Math.random() * platforms.length)];
|
|
};
|
|
|
|
//代理池
|
|
const validateproxy = process.env.VALIDATE_PROXY ? JSON.parse(process.env.VALIDATE_PROXY) : [];
|
|
|
|
const getRandomProxy = () => {
|
|
return validateproxy.length > 0
|
|
? validateproxy[Math.floor(Math.random() * validateproxy.length)]
|
|
: null;
|
|
};
|
|
|
|
const getRandomLanguages = () => {
|
|
const languages = [
|
|
['zh-CN', 'zh', 'en'],
|
|
['en-US', 'en', 'fr'],
|
|
['es-ES', 'es', 'en']
|
|
];
|
|
return languages[Math.floor(Math.random() * languages.length)];
|
|
};
|
|
|
|
export const setupPage = async (page: Page): Promise<void> => {
|
|
const proxy = getRandomProxy();
|
|
if (proxy) {
|
|
await page.authenticate({
|
|
username: proxy.ip,
|
|
password: proxy.port.toString()
|
|
});
|
|
}
|
|
|
|
await page.evaluateOnNewDocument(() => {
|
|
const newProto = (navigator as any).__proto__;
|
|
delete newProto.webdriver;
|
|
(navigator as any).__proto__ = newProto;
|
|
(window as any).chrome = {};
|
|
(window as any).chrome.app = {
|
|
InstallState: 'testt',
|
|
RunningState: 'estt',
|
|
getDetails: 'stte',
|
|
getIsInstalled: 'ttes'
|
|
};
|
|
(window as any).chrome.csi = function () {};
|
|
(window as any).chrome.loadTimes = function () {};
|
|
(window as any).chrome.runtime = function () {};
|
|
Object.defineProperty(navigator, 'userAgent', {
|
|
get: () => getRandomUserAgent()
|
|
});
|
|
Object.defineProperty(navigator, 'platform', {
|
|
get: () => getRandomPlatform()
|
|
});
|
|
Object.defineProperty(navigator, 'plugins', {
|
|
get: () => [
|
|
{
|
|
description: 'Shockwave Flash',
|
|
filename: 'pepflashplayer.dll',
|
|
length: 1,
|
|
name: 'Shockwave Flash'
|
|
}
|
|
]
|
|
});
|
|
Object.defineProperty(navigator, 'languages', {
|
|
get: () => getRandomLanguages()
|
|
});
|
|
const originalQuery = (window.navigator.permissions as any).query;
|
|
(window.navigator.permissions as any).query = (parameters: any) =>
|
|
parameters.name === 'notifications'
|
|
? Promise.resolve({ state: Notification.permission } as PermissionStatus)
|
|
: originalQuery(parameters);
|
|
});
|
|
};
|