Skip to content

Commit b47a452

Browse files
authored
feat: Enhance browser cache management and localization support (#11277)
* feat: Enhance browser cache management and localization support - Updated browser cache handling in WebsiteService to include a 'noModify' option. - Introduced new method AddBroswerNoCache in Location to manage no-cache directives. - Added localization for 'noModify' in multiple languages. - Updated frontend to support the new browser cache options in the proxy configuration. * fix: Update cache display logic in proxy configuration - Adjusted the rendering of cache tags in the proxy configuration to conditionally display based on cache time values. - Improved user interface by adding margin classes for better spacing between cache tags.
1 parent 38ab0d9 commit b47a452

File tree

14 files changed

+74
-22
lines changed

14 files changed

+74
-22
lines changed

agent/app/service/website.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,10 +1759,12 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
17591759
location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
17601760
}
17611761
// Browser Cache Settings
1762-
if req.CacheTime != 0 {
1762+
if req.CacheTime > 0 {
17631763
location.AddBrowserCache(req.CacheTime, req.CacheUnit)
1764-
} else {
1764+
} else if req.CacheTime == 0 {
17651765
location.RemoveBrowserCache()
1766+
} else {
1767+
location.AddBroswerNoCache()
17661768
}
17671769
// Content Replace Settings
17681770
if len(req.Replaces) > 0 {
@@ -1945,10 +1947,8 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e
19451947
}
19461948
proxyConfig.ProxyPass = location.ProxyPass
19471949
proxyConfig.Cache = location.Cache
1948-
if location.CacheTime > 0 {
1949-
proxyConfig.CacheTime = location.CacheTime
1950-
proxyConfig.CacheUnit = location.CacheUint
1951-
}
1950+
proxyConfig.CacheTime = location.CacheTime
1951+
proxyConfig.CacheUnit = location.CacheUint
19521952
if location.ServerCacheTime > 0 {
19531953
proxyConfig.ServerCacheTime = location.ServerCacheTime
19541954
proxyConfig.ServerCacheUnit = location.ServerCacheUint

agent/utils/nginx/components/location.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ func NewLocation(directive IDirective) *Location {
7373
location.CacheUint = unit
7474
location.CacheTime = cacheTime
7575
}
76+
if di.GetName() == "add_header" && len(di.GetParameters()) >= 2 {
77+
if di.GetParameters()[0] == "Cache-Control" && di.GetParameters()[1] == "no-cache" {
78+
location.CacheTime = -1
79+
location.CacheUint = ""
80+
}
81+
}
7682
}
7783
}
7884
if params[0] == "(" && params[1] == "$request_method" && params[2] == `=` && params[3] == `'OPTIONS'` && params[4] == ")" {
@@ -274,6 +280,28 @@ func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) {
274280
l.CacheUint = cacheUint
275281
}
276282

283+
func (l *Location) AddBroswerNoCache() {
284+
l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"})
285+
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
286+
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
287+
directives := l.GetDirectives()
288+
newDir := &Directive{
289+
Name: "if",
290+
Parameters: []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"},
291+
Block: &Block{},
292+
}
293+
block := &Block{}
294+
block.Directives = append(block.Directives, &Directive{
295+
Name: "add_header",
296+
Parameters: []string{"Cache-Control", "no-cache"},
297+
})
298+
newDir.Block = block
299+
directives = append(directives, newDir)
300+
l.Directives = directives
301+
l.CacheTime = -1
302+
l.CacheUint = "s"
303+
}
304+
277305
func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCacheUint string) {
278306
l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"})
279307
l.UpdateDirective("proxy_cache", []string{cacheKey})
@@ -287,7 +315,7 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa
287315
func (l *Location) RemoveBrowserCache() {
288316
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
289317
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
290-
l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"})
318+
l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"})
291319
l.CacheTime = 0
292320
l.CacheUint = ""
293321
}

frontend/src/lang/modules/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,7 @@ const message = {
25312531
antiLeech: 'Anti-leech',
25322532
extends: 'Extension',
25332533
browserCache: 'Browser Cache',
2534+
noModify: 'No Modify',
25342535
serverCache: 'Server Cache',
25352536
leechLog: 'Record anti-leech log',
25362537
accessDomain: 'Allowed domains',

frontend/src/lang/modules/es-es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,7 @@ const message = {
25232523
antiLeech: 'Anti-hotlink',
25242524
extends: 'Extensiones',
25252525
browserCache: 'Caché de navegador',
2526+
noModify: 'No Modificar',
25262527
serverCache: 'Caché del servidor',
25272528
leechLog: 'Registrar logs anti-hotlink',
25282529
accessDomain: 'Dominios permitidos',

frontend/src/lang/modules/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,7 @@ const message = {
24502450
antiLeech: '反リーチ',
24512451
extends: '拡大',
24522452
browserCache: 'キャッシュ',
2453+
noModify: '変更しない',
24532454
serverCache: 'サーバーキャッシュ',
24542455
leechLog: '反リーチログを記録します',
24552456
accessDomain: '許可されたドメイン',

frontend/src/lang/modules/ko.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,7 @@ const message = {
24072407
antiLeech: '링크 차단',
24082408
extends: '확장',
24092409
browserCache: '캐시',
2410+
noModify: '수정 안 함',
24102411
serverCache: '서버 캐시',
24112412
leechLog: '링크 차단 로그 기록',
24122413
accessDomain: '허용된 도메인',

frontend/src/lang/modules/ms.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,7 @@ const message = {
25042504
antiLeech: 'Anti-leech',
25052505
extends: 'Pelanjutan',
25062506
browserCache: 'Cache',
2507+
noModify: 'Tidak Ubah',
25072508
serverCache: 'Cache Pelayan',
25082509
leechLog: 'Rekod log anti-leech',
25092510
accessDomain: 'Domain yang dibenarkan',

frontend/src/lang/modules/pt-br.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,7 @@ const message = {
25072507
antiLeech: 'Anti-leech',
25082508
extends: 'Extensão',
25092509
browserCache: 'Cache',
2510+
noModify: 'Não Modificar',
25102511
serverCache: 'Cache do servidor',
25112512
leechLog: 'Registrar log anti-leech',
25122513
accessDomain: 'Domínios permitidos',

frontend/src/lang/modules/ru.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,7 @@ const message = {
25042504
antiLeech: 'Анти-лич',
25052505
extends: 'Расширение',
25062506
browserCache: 'Кэш',
2507+
noModify: 'Не изменять',
25072508
serverCache: 'Кэш сервера',
25082509
leechLog: 'Записывать лог анти-лича',
25092510
accessDomain: 'Разрешенные домены',

frontend/src/lang/modules/tr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,7 @@ const message = {
25632563
antiLeech: 'Sömürü karşıtı',
25642564
extends: 'Uzantı',
25652565
browserCache: 'Önbellek',
2566+
noModify: 'Değiştirme',
25662567
serverCache: 'Sunucu önbelleği',
25672568
leechLog: 'Sömürü karşıtı günlüğü kaydet',
25682569
accessDomain: 'İzin verilen alan adları',

0 commit comments

Comments
 (0)