Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,10 +1759,12 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
}
// Browser Cache Settings
if req.CacheTime != 0 {
if req.CacheTime > 0 {
location.AddBrowserCache(req.CacheTime, req.CacheUnit)
} else {
} else if req.CacheTime == 0 {
location.RemoveBrowserCache()
} else {
location.AddBroswerNoCache()
}
// Content Replace Settings
if len(req.Replaces) > 0 {
Expand Down Expand Up @@ -1945,10 +1947,8 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e
}
proxyConfig.ProxyPass = location.ProxyPass
proxyConfig.Cache = location.Cache
if location.CacheTime > 0 {
proxyConfig.CacheTime = location.CacheTime
proxyConfig.CacheUnit = location.CacheUint
}
proxyConfig.CacheTime = location.CacheTime
proxyConfig.CacheUnit = location.CacheUint
if location.ServerCacheTime > 0 {
proxyConfig.ServerCacheTime = location.ServerCacheTime
proxyConfig.ServerCacheUnit = location.ServerCacheUint
Expand Down
30 changes: 29 additions & 1 deletion agent/utils/nginx/components/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func NewLocation(directive IDirective) *Location {
location.CacheUint = unit
location.CacheTime = cacheTime
}
if di.GetName() == "add_header" && len(di.GetParameters()) >= 2 {
if di.GetParameters()[0] == "Cache-Control" && di.GetParameters()[1] == "no-cache" {
location.CacheTime = -1
location.CacheUint = ""
}
}
}
}
if params[0] == "(" && params[1] == "$request_method" && params[2] == `=` && params[3] == `'OPTIONS'` && params[4] == ")" {
Expand Down Expand Up @@ -274,6 +280,28 @@ func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) {
l.CacheUint = cacheUint
}

func (l *Location) AddBroswerNoCache() {
l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
directives := l.GetDirectives()
newDir := &Directive{
Name: "if",
Parameters: []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"},
Block: &Block{},
}
block := &Block{}
block.Directives = append(block.Directives, &Directive{
Name: "add_header",
Parameters: []string{"Cache-Control", "no-cache"},
})
newDir.Block = block
directives = append(directives, newDir)
l.Directives = directives
l.CacheTime = -1
l.CacheUint = "s"
}

func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCacheUint string) {
l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"})
l.UpdateDirective("proxy_cache", []string{cacheKey})
Expand All @@ -287,7 +315,7 @@ func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCa
func (l *Location) RemoveBrowserCache() {
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"})
l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"})
l.CacheTime = 0
l.CacheUint = ""
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,7 @@ const message = {
antiLeech: 'Anti-leech',
extends: 'Extension',
browserCache: 'Browser Cache',
noModify: 'No Modify',
serverCache: 'Server Cache',
leechLog: 'Record anti-leech log',
accessDomain: 'Allowed domains',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,7 @@ const message = {
antiLeech: 'Anti-hotlink',
extends: 'Extensiones',
browserCache: 'Caché de navegador',
noModify: 'No Modificar',
serverCache: 'Caché del servidor',
leechLog: 'Registrar logs anti-hotlink',
accessDomain: 'Dominios permitidos',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,7 @@ const message = {
antiLeech: '反リーチ',
extends: '拡大',
browserCache: 'キャッシュ',
noModify: '変更しない',
serverCache: 'サーバーキャッシュ',
leechLog: '反リーチログを記録します',
accessDomain: '許可されたドメイン',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,7 @@ const message = {
antiLeech: '링크 차단',
extends: '확장',
browserCache: '캐시',
noModify: '수정 안 함',
serverCache: '서버 캐시',
leechLog: '링크 차단 로그 기록',
accessDomain: '허용된 도메인',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,7 @@ const message = {
antiLeech: 'Anti-leech',
extends: 'Pelanjutan',
browserCache: 'Cache',
noModify: 'Tidak Ubah',
serverCache: 'Cache Pelayan',
leechLog: 'Rekod log anti-leech',
accessDomain: 'Domain yang dibenarkan',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,7 @@ const message = {
antiLeech: 'Anti-leech',
extends: 'Extensão',
browserCache: 'Cache',
noModify: 'Não Modificar',
serverCache: 'Cache do servidor',
leechLog: 'Registrar log anti-leech',
accessDomain: 'Domínios permitidos',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,7 @@ const message = {
antiLeech: 'Анти-лич',
extends: 'Расширение',
browserCache: 'Кэш',
noModify: 'Не изменять',
serverCache: 'Кэш сервера',
leechLog: 'Записывать лог анти-лича',
accessDomain: 'Разрешенные домены',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,7 @@ const message = {
antiLeech: 'Sömürü karşıtı',
extends: 'Uzantı',
browserCache: 'Önbellek',
noModify: 'Değiştirme',
serverCache: 'Sunucu önbelleği',
leechLog: 'Sömürü karşıtı günlüğü kaydet',
accessDomain: 'İzin verilen alan adları',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,7 @@ const message = {
antiLeech: '防盜鏈',
extends: '副檔名',
browserCache: '瀏覽器快取',
noModify: '不修改',
serverCache: '伺服器快取',
leechLog: '記錄防盜鏈日誌',
accessDomain: '允許的域名',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,7 @@ const message = {
antiLeech: '防盗链',
extends: '扩展名',
browserCache: '浏览器缓存',
noModify: '不修改',
serverCache: '服务器缓存',
leechLog: '记录防盗链日志',
accessDomain: '允许的域名',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,31 @@
</div>
<el-button-group>
<el-button
:type="proxy.browserCache ? 'primary' : 'default'"
@click="changeBrowserCache(true)"
:type="proxy.browserCache === 'enable' ? 'primary' : 'default'"
@click="changeBrowserCache('enable')"
size="small"
>
{{ $t('commons.button.enable') }}
</el-button>
<el-button
:type="!proxy.browserCache ? 'primary' : 'default'"
@click="changeBrowserCache(false)"
:type="proxy.browserCache === 'disable' ? 'primary' : 'default'"
@click="changeBrowserCache('disable')"
size="small"
>
{{ $t('commons.button.disable') }}
</el-button>
<el-button
:type="proxy.browserCache === 'noModify' ? 'primary' : 'default'"
@click="changeBrowserCache('noModify')"
size="small"
>
{{ $t('website.noModify') }}
</el-button>
</el-button-group>
</div>

<el-collapse-transition>
<div v-if="proxy.browserCache" class="mt-4 mb-6">
<div v-if="proxy.browserCache === 'enable'" class="mt-4 mb-6">
<el-form-item :label="$t('website.browserCacheTime')" prop="cacheTime">
<el-input v-model.number="proxy.cacheTime" maxlength="15" class="!w-64">
<template #append>
Expand Down Expand Up @@ -257,8 +264,8 @@ const initData = (): Website.ProxyConfig => ({
operate: 'create',
enable: true,
cache: false,
cacheTime: 4,
cacheUnit: 'h',
cacheTime: 0,
cacheUnit: '',
name: '',
modifier: '',
match: '/',
Expand All @@ -272,7 +279,7 @@ const initData = (): Website.ProxyConfig => ({
proxySSLName: '',
serverCacheTime: 10,
serverCacheUnit: 'm',
browserCache: false,
browserCache: 'noModify',
cors: false,
allowOrigins: '*',
allowMethods: 'GET,POST,OPTIONS,PUT,DELETE',
Expand All @@ -295,8 +302,12 @@ const acceptParams = (proxyParam: Website.ProxyConfig) => {
activeTab.value = 'basic';

// Initialize browserCache based on cacheTime value
if (proxy.value.browserCache === undefined) {
proxy.value.browserCache = proxy.value.cacheTime > 0;
if (proxy.value.cacheTime > 0) {
proxy.value.browserCache = 'enable';
} else if (proxy.value.cacheTime === 0) {
proxy.value.browserCache = 'noModify';
} else {
proxy.value.browserCache = 'disable';
}

const res = getProtocolAndHost(proxyParam.proxyPass);
Expand Down Expand Up @@ -326,11 +337,14 @@ const changeServerCache = (cache: boolean) => {
}
};

const changeBrowserCache = (cache: boolean) => {
proxy.value.browserCache = cache;
if (cache) {
const changeBrowserCache = (mode: 'enable' | 'disable' | 'noModify') => {
proxy.value.browserCache = mode;
if (mode === 'enable') {
proxy.value.cacheTime = 4;
proxy.value.cacheUnit = 'h';
} else if (mode === 'disable') {
proxy.value.cacheTime = -1;
proxy.value.cacheUnit = '';
} else {
proxy.value.cacheTime = 0;
proxy.value.cacheUnit = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<el-table-column :label="$t('website.proxyPass')" prop="proxyPass"></el-table-column>
<el-table-column :label="$t('website.cache')" prop="cache">
<template #default="{ row }">
<el-tag :type="row.cacheTime > 0 ? 'success' : 'info'">
<el-tag class="mr-2" :type="row.cacheTime > 0 ? 'success' : 'info'" v-if="row.cacheTime != 0">
{{ $t('website.browserCache') + ':' }}
{{ row.cacheTime > 0 ? row.cacheTime + row.cacheUnit : $t('setting.sslDisable') }}
</el-tag>
<el-tag class="ml-2" :type="row.serverCacheTime > 0 ? 'success' : 'info'">
<el-tag :type="row.serverCacheTime > 0 ? 'success' : 'info'">
{{ $t('website.serverCache') + ':' }}
{{ row.serverCacheTime > 0 ? row.serverCacheTime + row.serverCacheUnit : $t('setting.sslDisable') }}
</el-tag>
Expand Down
Loading