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') }}