diff --git a/agent/app/api/v2/nginx.go b/agent/app/api/v2/nginx.go index a2a7e514c..5a05cc2fb 100644 --- a/agent/app/api/v2/nginx.go +++ b/agent/app/api/v2/nginx.go @@ -101,21 +101,6 @@ func (b *BaseApi) UpdateNginxFile(c *gin.Context) { helper.SuccessWithData(c, nil) } -// @Tags OpenResty -// @Summary Clear OpenResty proxy cache -// @Description 清理 OpenResty 代理缓存 -// @Success 200 -// @Security ApiKeyAuth -// @Router /openresty/clear [post] -// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清理 Openresty 代理缓存","formatEN":"Clear nginx proxy cache"} -func (b *BaseApi) ClearNginxProxyCache(c *gin.Context) { - if err := nginxService.ClearProxyCache(); err != nil { - helper.InternalServer(c, err) - return - } - helper.SuccessWithOutData(c) -} - // @Tags OpenResty // @Summary Build OpenResty // @Description 构建 OpenResty diff --git a/agent/app/api/v2/website.go b/agent/app/api/v2/website.go index f16ec0b73..e617fe67d 100644 --- a/agent/app/api/v2/website.go +++ b/agent/app/api/v2/website.go @@ -1082,3 +1082,21 @@ func (b *BaseApi) ListCustomRewrite(c *gin.Context) { } helper.SuccessWithData(c, res) } + +// @Tags Website +// @Summary Clear Website proxy cache +// @Success 200 +// @Security ApiKeyAuth +// @Router /websites/proxy/clear [post] +// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"清理 Openresty 代理缓存","formatEN":"Clear nginx proxy cache"} +func (b *BaseApi) ClearProxyCache(c *gin.Context) { + var req request.NginxCommonReq + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + if err := websiteService.ClearProxyCache(req); err != nil { + helper.InternalServer(c, err) + return + } + helper.SuccessWithOutData(c) +} diff --git a/agent/app/service/nginx.go b/agent/app/service/nginx.go index 579882149..53b5cd3dc 100644 --- a/agent/app/service/nginx.go +++ b/agent/app/service/nginx.go @@ -35,7 +35,6 @@ type INginxService interface { UpdateConfigByScope(req request.NginxConfigUpdate) error GetStatus() (response.NginxStatus, error) UpdateConfigFile(req request.NginxConfigFileUpdate) error - ClearProxyCache() error Build(req request.NginxBuildReq) error GetModules() (*response.NginxBuildConfig, error) @@ -166,25 +165,6 @@ func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error return nginxCheckAndReload(string(oldContent), filePath, nginxInstall.ContainerName) } -func (n NginxService) ClearProxyCache() error { - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return err - } - cacheDir := path.Join(nginxInstall.GetPath(), "www/common/proxy/proxy_cache_dir") - fileOp := files.NewFileOp() - if fileOp.Stat(cacheDir) { - if err = fileOp.CleanDir(cacheDir); err != nil { - return err - } - _, err = compose.Restart(nginxInstall.GetComposePath()) - if err != nil { - return err - } - } - return nil -} - func (n NginxService) Build(req request.NginxBuildReq) error { nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) if err != nil { diff --git a/agent/app/service/website.go b/agent/app/service/website.go index c2209587b..f02448ff9 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -91,6 +91,7 @@ type IWebsiteService interface { UpdateProxyFile(req request.NginxProxyUpdate) (err error) UpdateProxyCache(req request.NginxProxyCacheUpdate) (err error) GetProxyCache(id uint) (res response.NginxProxyCache, err error) + ClearProxyCache(req request.NginxCommonReq) error GetAntiLeech(id uint) (*response.NginxAntiLeechRes, error) UpdateAntiLeech(req request.NginxAntiLeechUpdate) (err error) @@ -1822,6 +1823,28 @@ func (w WebsiteService) UpdateProxyFile(req request.NginxProxyUpdate) (err error return updateNginxConfig(constant.NginxScopeServer, nil, &website) } +func (w WebsiteService) ClearProxyCache(req request.NginxCommonReq) error { + website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + if err != nil { + return err + } + cacheDir := GetSitePath(website, SiteProxyDir) + fileOp := files.NewFileOp() + if fileOp.Stat(cacheDir) { + if err = fileOp.CleanDir(cacheDir); err != nil { + return err + } + } + nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) + if err != nil { + return err + } + if err = opNginx(nginxInstall.ContainerName, constant.NginxReload); err != nil { + return err + } + return nil +} + func (w WebsiteService) GetAuthBasics(req request.NginxAuthReq) (res response.NginxAuthRes, err error) { var ( website model.Website diff --git a/agent/router/ro_nginx.go b/agent/router/ro_nginx.go index 08b3ed212..9ea4cf154 100644 --- a/agent/router/ro_nginx.go +++ b/agent/router/ro_nginx.go @@ -18,7 +18,6 @@ func (a *NginxRouter) InitRouter(Router *gin.RouterGroup) { groupRouter.POST("/update", baseApi.UpdateNginxConfigByScope) groupRouter.GET("/status", baseApi.GetNginxStatus) groupRouter.POST("/file", baseApi.UpdateNginxFile) - groupRouter.POST("/clear", baseApi.ClearNginxProxyCache) groupRouter.POST("/build", baseApi.BuildNginx) groupRouter.POST("/modules/update", baseApi.UpdateNginxModule) groupRouter.GET("/modules", baseApi.GetNginxModules) diff --git a/agent/router/ro_website.go b/agent/router/ro_website.go index fd93d8529..d3f2a28a1 100644 --- a/agent/router/ro_website.go +++ b/agent/router/ro_website.go @@ -53,6 +53,7 @@ func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) { websiteRouter.POST("/proxies/file", baseApi.UpdateProxyConfigFile) websiteRouter.POST("/proxy/config", baseApi.UpdateProxyCache) websiteRouter.GET("/proxy/config/:id", baseApi.GetProxyCache) + websiteRouter.POST("/proxy/clear", baseApi.ClearProxyCache) websiteRouter.POST("/auths", baseApi.GetAuthConfig) websiteRouter.POST("/auths/update", baseApi.UpdateAuthConfig) diff --git a/frontend/src/api/modules/nginx.ts b/frontend/src/api/modules/nginx.ts index bba625fe7..4f763ff46 100644 --- a/frontend/src/api/modules/nginx.ts +++ b/frontend/src/api/modules/nginx.ts @@ -22,10 +22,6 @@ export const UpdateNginxConfigFile = (req: Nginx.NginxFileUpdate) => { return http.post(`/openresty/file`, req); }; -export const ClearNginxCache = () => { - return http.post(`/openresty/clear`); -}; - export const BuildNginx = (req: Nginx.NginxBuildReq) => { return http.post(`/openresty/build`, req); }; diff --git a/frontend/src/api/modules/website.ts b/frontend/src/api/modules/website.ts index de0299329..f5a9fc70f 100644 --- a/frontend/src/api/modules/website.ts +++ b/frontend/src/api/modules/website.ts @@ -190,6 +190,10 @@ export const UpdateProxyConfigFile = (req: Website.ProxyFileUpdate) => { return http.post(`/websites/proxies/file`, req); }; +export const ClearProxtCache = (req: Website.WebsiteReq) => { + return http.post(`/websites/proxy/clear`, req); +}; + export const GetAuthConfig = (req: Website.AuthReq) => { return http.post(`/websites/auths`, req); }; diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue index 4d84b12f7..17fe2cfee 100644 --- a/frontend/src/components/app-status/index.vue +++ b/frontend/src/components/app-status/index.vue @@ -51,18 +51,6 @@ > {{ $t('commons.button.set') }} - - - {{ $t('nginx.clearProxyCache') }} -
{ }); }; -const clear = () => { - ElMessageBox.confirm(i18n.global.t('nginx.clearProxyCacheWarn'), i18n.global.t('nginx.clearProxyCache'), { - confirmButtonText: i18n.global.t('commons.button.confirm'), - cancelButtonText: i18n.global.t('commons.button.cancel'), - }).then(async () => { - await ClearNginxCache(); - MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); - }); -}; - const onOperate = async (operation: string) => { em('update:maskShow', false); operateReq.operate = operation; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 431735d51..79ab011b3 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2364,8 +2364,7 @@ const message = { configResource: 'Configuration', saveAndReload: 'Save and Reload', clearProxyCache: 'Clear reverse proxy cache', - clearProxyCacheWarn: - 'Clearing the reverse proxy cache will affect all websites configured with cache and requires restarting OpenResty. Do you want to continue? ', + clearProxyCacheWarn: 'This action will delete all files in the cache directory. Do you want to continue?', create: 'Add a new module', update: 'Edit a module', params: 'Parameters', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index cd4ce02d3..db6e39a8d 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -2203,7 +2203,7 @@ const message = { configResource: '配置修改', saveAndReload: '保存並重載', clearProxyCache: '清除反代快取', - clearProxyCacheWarn: '清除反代快取會影響所有配置快取的網站,並且需要重新啟動 OpenResty, 是否繼續? ', + clearProxyCacheWarn: '此操作將刪除緩存目錄下的所有文件,是否繼續?', create: '新增模組', update: '編輯模組', params: '參數', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 978b8f47b..fc3670abf 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2202,7 +2202,7 @@ const message = { configResource: '配置修改', saveAndReload: '保存并重载', clearProxyCache: '清除反代缓存', - clearProxyCacheWarn: '清除反代缓存会影响所有配置缓存的网站,并且需要重启 OpenResty, 是否继续?', + clearProxyCacheWarn: '此操作将删除缓存目录下的所有文件, 是否继续?', create: '新增模块', update: '编辑模块', params: '参数', diff --git a/frontend/src/views/website/website/config/basic/proxy/index.vue b/frontend/src/views/website/website/config/basic/proxy/index.vue index e38aebb78..8edbecee9 100644 --- a/frontend/src/views/website/website/config/basic/proxy/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/index.vue @@ -3,6 +3,9 @@ @@ -35,7 +38,7 @@