From 6870388d0719c3ee0c21535f5f0d5d61844c176a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 29 Jan 2026 18:33:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/views/website/EditView.vue | 187 ++++++++++++++++++++++++++++- 1 file changed, 185 insertions(+), 2 deletions(-) diff --git a/web/src/views/website/EditView.vue b/web/src/views/website/EditView.vue index b07db836..69a01e64 100644 --- a/web/src/views/website/EditView.vue +++ b/web/src/views/website/EditView.vue @@ -330,7 +330,7 @@ const addProxy = () => { pass: 'http://127.0.0.1:8080', host: '$host', sni: '', - cache: false, + cache: null, // null 表示禁用缓存 buffering: true, resolver: [], resolver_timeout: 5 * 1000000000, // 5秒,以纳秒为单位 @@ -339,6 +339,75 @@ const addProxy = () => { }) } +// ========== 缓存配置相关 ========== +// 创建默认缓存配置 +const createDefaultCacheConfig = () => ({ + valid: { '200 302': '10m', '404': '1m' }, + no_cache_conditions: [], + use_stale: [], + background_update: false, + lock: false, + min_uses: 0, + methods: [], + key: '' +}) + +// 切换缓存启用状态 +const toggleProxyCache = (proxy: any, enabled: boolean) => { + if (enabled) { + proxy.cache = createDefaultCacheConfig() + } else { + proxy.cache = null + } +} + +// 判断缓存是否启用 +const isCacheEnabled = (proxy: any) => { + return proxy.cache !== null && proxy.cache !== undefined +} + +// 添加缓存有效期规则 +const addCacheValidRule = (proxy: any) => { + if (!proxy.cache) return + if (!proxy.cache.valid) proxy.cache.valid = {} + const index = Object.keys(proxy.cache.valid).length + 1 + proxy.cache.valid[`any`] = '5m' +} + +// 删除缓存有效期规则 +const removeCacheValidRule = (proxy: any, codes: string) => { + if (proxy.cache?.valid) { + delete proxy.cache.valid[codes] + } +} + +// 不缓存条件选项 +const noCacheConditionOptions = [ + { label: '$cookie_nocache', value: '$cookie_nocache' }, + { label: '$arg_nocache', value: '$arg_nocache' }, + { label: '$http_pragma', value: '$http_pragma' }, + { label: '$http_authorization', value: '$http_authorization' }, + { label: '$http_cache_control', value: '$http_cache_control' } +] + +// 过期缓存使用策略选项 +const useStaleOptions = [ + { label: 'error', value: 'error' }, + { label: 'timeout', value: 'timeout' }, + { label: 'updating', value: 'updating' }, + { label: 'http_500', value: 'http_500' }, + { label: 'http_502', value: 'http_502' }, + { label: 'http_503', value: 'http_503' }, + { label: 'http_504', value: 'http_504' } +] + +// 缓存方法选项 +const cacheMethodOptions = [ + { label: 'GET', value: 'GET' }, + { label: 'HEAD', value: 'HEAD' }, + { label: 'POST', value: 'POST' } +] + // 删除代理 const removeProxy = (index: number) => { if (setting.value.proxies) { @@ -860,7 +929,10 @@ const removeCustomConfig = (index: number) => { /> - + @@ -893,6 +965,117 @@ const removeCustomConfig = (index: number) => { + + {{ $gettext('Custom Request Headers') }}