cherry-studio/packages/shared/config/constant.ts
beyondkmp efda20c143
feat: support bypass proxy (#8791)
* feat(ProxyManager): implement SelectiveDispatcher for localhost handling

- Added SelectiveDispatcher to manage proxy and direct connections based on the hostname.
- Introduced isLocalhost function to check for localhost addresses.
- Updated ProxyManager to bypass proxy for localhost in dispatch methods and set proxy bypass rules.
- Enhanced global dispatcher setup to utilize SelectiveDispatcher for both EnvHttpProxyAgent and SOCKS dispatcher.

* refactor(ProxyManager): update axios configuration to use fetch adapter

- Changed axios to use the 'fetch' adapter for proxy requests.
- Removed previous proxy settings for axios, streamlining the configuration.
- Updated HTTP methods to bind with the new proxy agent.

* feat(Proxy): add support for proxy bypass rules

- Updated IPC handler to accept optional bypass rules for proxy configuration.
- Enhanced ProxyManager to store and utilize bypass rules for localhost and other specified addresses.
- Modified settings and UI components to allow users to input and manage bypass rules.
- Added translations for bypass rules in multiple languages.

* feat(ProxyManager): add HTTP_PROXY environment variable support

- Added support for the HTTP_PROXY environment variable in ProxyManager to enhance proxy configuration capabilities.

* lint

* refactor(ProxyManager): optimize bypass rules handling

- Updated bypass rules initialization to split the rules string into an array for improved performance.
- Simplified the isByPass function to directly check against the array of bypass rules.
- Enhanced configuration handling to ensure bypass rules are correctly parsed from the provided settings.

* refactor(ProxyManager): streamline bypass rules initialization

- Consolidated the initialization of bypass rules by directly splitting the default rules string into an array.
- Updated configuration handling to ensure bypass rules are correctly assigned without redundant splitting.

* style(GeneralSettings): adjust proxy bypass rules input width to improve UI layout

* refactor(ProxyManager): enhance proxy configuration logging and handling

- Added proxy bypass rules to the configuration method for improved flexibility.
- Updated logging to include bypass rules for better debugging.
- Refactored the setGlobalProxy method to accept configuration parameters directly, streamlining proxy setup.
- Adjusted the useAppInit hook to handle proxy settings more cleanly.

* refactor(ProxyManager): implement close and destroy methods for proxy dispatcher

- Added close and destroy methods to the SelectiveDispatcher class for better resource management.
- Updated ProxyManager to handle the lifecycle of the proxyDispatcher, ensuring proper closure and destruction.
- Enhanced error handling during dispatcher closure and destruction to prevent resource leaks.

* refactor(ProxyManager): manage proxy agent lifecycle

- Introduced proxyAgent property to ProxyManager for better management of the proxy agent.
- Implemented error handling during the destruction of the proxy agent to prevent potential issues.
- Updated the proxy setup process to ensure the proxy agent is correctly initialized and cleaned up.

* refactor(ProxyManager): centralize default bypass rules management

- Moved default bypass rules to a shared constant for consistency across components.
- Updated ProxyManager and GeneralSettings to utilize the centralized bypass rules.
- Adjusted migration logic to set default bypass rules from the shared constant, ensuring uniformity in configuration.
2025-08-04 19:24:28 +08:00

211 lines
4.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { languages } from './languages'
export const imageExts = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
export const videoExts = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv']
export const audioExts = ['.mp3', '.wav', '.ogg', '.flac', '.aac']
export const documentExts = ['.pdf', '.doc', '.docx', '.pptx', '.xlsx', '.odt', '.odp', '.ods']
export const thirdPartyApplicationExts = ['.draftsExport']
export const bookExts = ['.epub']
/**
* A flat array of all file extensions known by the linguist database.
* This is the primary source for identifying code files.
*/
const linguistExtSet = new Set<string>()
for (const lang of Object.values(languages)) {
if (lang.extensions) {
for (const ext of lang.extensions) {
linguistExtSet.add(ext)
}
}
}
export const codeLangExts = Array.from(linguistExtSet)
/**
* A categorized map of custom text-based file extensions that are NOT included
* in the linguist database. This is for special cases or project-specific files.
*/
export const customTextExts = new Map([
[
'language',
[
'.R', // R
'.ets', // OpenHarmony,
'.uniswap', // DeFi
'.usf', // Unreal shader format
'.ush' // Unreal shader header
]
],
[
'template',
[
'.vm' // Velocity
]
],
[
'config',
[
'.babelrc', // Babel
'.bashrc',
'.browserslistrc',
'.conf',
'.config', // 通用配置
'.dockerignore', // Docker ignore
'.eslintignore',
'.eslintrc', // ESLint
'.fishrc', // Fish shell配置
'.htaccess', // Apache配置
'.npmignore',
'.npmrc', // npm
'.prettierignore',
'.prettierrc', // Prettier
'.rc',
'.robots', // robots.txt
'.yarnrc',
'.zshrc'
]
],
[
'document',
[
'.authors', // 作者文件
'.changelog', // 变更日志
'.license', // 许可证
'.nfo', // 信息文件
'.readme',
'.text' // 纯文本
]
],
[
'data',
[
'.atom', // Feed格式
'.ldif',
'.map',
'.ndjson' // 换行分隔JSON
]
],
[
'build',
[
'.bazel', // Bazel
'.build', // Meson
'.pom'
]
],
[
'database',
[
'.dml', // DDL/DML
'.psql' // PostgreSQL
]
],
[
'web',
[
'.openapi', // API文档
'.swagger'
]
],
[
'version',
[
'.bzrignore', // Bazaar ignore
'.gitattributes', // Git attributes
'.githistory', // Git history
'.hgignore', // Mercurial ignore
'.svnignore' // SVN ignore
]
],
[
'subtitle',
[
'.ass', // 字幕格式
'.sub'
]
],
[
'log',
[
'.log',
'.rpt' // 日志和报告 (移除了.out因为通常是二进制可执行文件)
]
],
[
'eda',
[
'.cir',
'.def', // LEF/DEF
'.edif', // EDIF
'.il',
'.ils', // SKILL
'.lef',
'.net',
'.scs', // Spectre
'.sdf', // SDF
'.spi'
]
]
])
/**
* A comprehensive list of all text-based file extensions, combining the
* extensive list from the linguist database with our custom additions.
* The Set ensures there are no duplicates.
*/
export const textExts = [...new Set([...Array.from(customTextExts.values()).flat(), ...codeLangExts])]
export const ZOOM_LEVELS = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]
// 从 ZOOM_LEVELS 生成 Ant Design Select 所需的 options 结构
export const ZOOM_OPTIONS = ZOOM_LEVELS.map((level) => ({
value: level,
label: `${Math.round(level * 100)}%`
}))
export const ZOOM_SHORTCUTS = [
{
key: 'zoom_in',
shortcut: ['CommandOrControl', '='],
editable: false,
enabled: true,
system: true
},
{
key: 'zoom_out',
shortcut: ['CommandOrControl', '-'],
editable: false,
enabled: true,
system: true
},
{
key: 'zoom_reset',
shortcut: ['CommandOrControl', '0'],
editable: false,
enabled: true,
system: true
}
]
export const KB = 1024
export const MB = 1024 * KB
export const GB = 1024 * MB
export const defaultLanguage = 'en-US'
export enum FeedUrl {
PRODUCTION = 'https://releases.cherry-ai.com',
GITHUB_LATEST = 'https://github.com/CherryHQ/cherry-studio/releases/latest/download'
}
export enum UpgradeChannel {
LATEST = 'latest', // 最新稳定版本
RC = 'rc', // 公测版本
BETA = 'beta' // 预览版本
}
export const defaultTimeout = 10 * 1000 * 60
export const occupiedDirs = ['logs', 'Network', 'Partitions/webview/Network']
export const defaultByPassRules = 'localhost,127.0.0.1,::1'