mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	实现自动清理服务访问日志
This commit is contained in:
		
							
								
								
									
										15
									
								
								internal/web/actions/default/settings/database/clean.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								internal/web/actions/default/settings/database/clean.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
package profile
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
 | 
			
		||||
type CleanAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanAction) Init() {
 | 
			
		||||
	this.Nav("", "", "clean")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanAction) RunGet(params struct{}) {
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,82 @@
 | 
			
		||||
package profile
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type CleanSettingAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanSettingAction) Init() {
 | 
			
		||||
	this.Nav("", "", "cleanSetting")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanSettingAction) RunGet(params struct{}) {
 | 
			
		||||
	// 读取设置
 | 
			
		||||
	configResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeDatabaseConfigSetting})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var config = &systemconfigs.DatabaseConfig{}
 | 
			
		||||
	if len(configResp.ValueJSON) > 0 {
 | 
			
		||||
		err = json.Unmarshal(configResp.ValueJSON, config)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			this.ErrorPage(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["config"] = config.ServerAccessLog.Clean
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanSettingAction) RunPost(params struct {
 | 
			
		||||
	Days int
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
	CSRF *actionutils.CSRF
 | 
			
		||||
}) {
 | 
			
		||||
	defer this.CreateLogInfo("修改数据库自动清理设置")
 | 
			
		||||
 | 
			
		||||
	days := params.Days
 | 
			
		||||
	if days < 0 {
 | 
			
		||||
		days = 0
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 读取设置
 | 
			
		||||
	configResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeDatabaseConfigSetting})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var config = &systemconfigs.DatabaseConfig{}
 | 
			
		||||
	if len(configResp.ValueJSON) > 0 {
 | 
			
		||||
		err = json.Unmarshal(configResp.ValueJSON, config)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			this.ErrorPage(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	config.ServerAccessLog.Clean.Days = days
 | 
			
		||||
	configJSON, err := json.Marshal(config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
 | 
			
		||||
		Code:      systemconfigs.SettingCodeDatabaseConfigSetting,
 | 
			
		||||
		ValueJSON: configJSON,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -15,6 +15,8 @@ func init() {
 | 
			
		||||
			Prefix("/settings/database").
 | 
			
		||||
			Get("", new(IndexAction)).
 | 
			
		||||
			GetPost("/update", new(UpdateAction)).
 | 
			
		||||
			GetPost("/clean", new(CleanAction)).
 | 
			
		||||
			GetPost("/cleanSetting", new(CleanSettingAction)).
 | 
			
		||||
			EndAll()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
<first-menu>
 | 
			
		||||
	<menu-item href="/settings/database" code="index">详情</menu-item>
 | 
			
		||||
	<menu-item href="/settings/database/update" code="update">修改</menu-item>
 | 
			
		||||
    <menu-item href="/settings/database/clean" code="clean">手动清理</menu-item>
 | 
			
		||||
    <menu-item href="/settings/database/cleanSetting" code="cleanSetting">自动清理设置</menu-item>
 | 
			
		||||
    <span class="item">|</span>
 | 
			
		||||
    <span class="item"><tip-icon content="在这里可以设置API节点可以使用的数据库,修改后请重新配置并启动API节点才能生效。"></tip-icon></span>
 | 
			
		||||
</first-menu>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								web/views/@default/settings/database/clean.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								web/views/@default/settings/database/clean.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
							
								
								
									
										21
									
								
								web/views/@default/settings/database/cleanSetting.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								web/views/@default/settings/database/cleanSetting.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "menu"}
 | 
			
		||||
 | 
			
		||||
<form class="ui form" data-tea-success="success" data-tea-action="$">
 | 
			
		||||
    <csrf-token></csrf-token>
 | 
			
		||||
 | 
			
		||||
    <h4 style="margin-top: 0">服务访问日志</h4>
 | 
			
		||||
    <table class="ui table definition selectable">
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td class="title">保存天数 *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <div class="ui input right labeled">
 | 
			
		||||
                    <input type="text" name="days" v-model="config.days" style="width:6em" maxlength="6"/>
 | 
			
		||||
                    <span class="ui label">天</span>
 | 
			
		||||
                </div>
 | 
			
		||||
                <p class="comment">天数包括当天。如果填0表示不自动清理。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
    </table>
 | 
			
		||||
    <submit-btn></submit-btn>
 | 
			
		||||
</form>
 | 
			
		||||
							
								
								
									
										3
									
								
								web/views/@default/settings/database/cleanSetting.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								web/views/@default/settings/database/cleanSetting.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
    this.success = NotifyReloadSuccess("保存成功")
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user