Skip to content

Commit

Permalink
feat: 支持立即备份选中的项目
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 committed Jun 16, 2023
1 parent f3e50d5 commit 423c4a7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
10 changes: 10 additions & 0 deletions client/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ func RunOnce() {
}
}

// 运行指定的索引号
func RunByIdx(idx int) {
conf, err := entity.GetConfigCache()
if err != nil {
return
}

run(conf, conf.BackupConfig[idx])
}

// run
func run(conf entity.Config, backupConf entity.BackupConfig) {
if backupConf.NotEmptyProject() && backupConf.Enabled == 0 {
Expand Down
11 changes: 10 additions & 1 deletion web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"backup-x/client"
"backup-x/entity"
"backup-x/util"
"log"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -102,9 +103,17 @@ func Save(writer http.ResponseWriter, request *http.Request) {
// 没有错误
if err == nil {
conf.CreateBucketIfNotExist()
if request.URL.Query().Get("backupNow") == "true" {
if request.URL.Query().Get("backupAll") == "true" {
go client.RunOnce()
}
if request.URL.Query().Get("backupIdx") != "" {
idx, err := strconv.Atoi(request.URL.Query().Get("backupIdx"))
if err == nil {
go client.RunByIdx(idx)
} else {
log.Println("索引号不正确" + request.URL.Query().Get("backupIdx"))
}
}
// 重新进行循环
client.StopRunLoop()
go client.RunLoop()
Expand Down
26 changes: 21 additions & 5 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<form>

<button class="btn btn-primary submit_btn" style="margin-bottom: 15px;">Save</button>
<button class="btn btn-warning submit_btn_backupNow" style="margin-bottom: 15px;margin-left: 15px;">Save & Backup Now</button>
<button class="btn btn-primary submit_btn_backup_idx" style="margin-bottom: 15px;margin-left: 15px;">Save & 立即备份选中</button>
<button class="btn btn-warning submit_btn_backup_all" style="margin-bottom: 15px;margin-left: 15px;">Save & 立即备份全部</button>

<div class="alert" style="display: none;">
<strong id="resultMsg"></strong>
Expand All @@ -43,7 +44,7 @@ <h5 class="portlet__head">备份设置</h5>
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{range $i, $v := .BackupConfig}}
<a class="nav-item nav-link {{if eq $i 0}}active{{end}}" id="id_{{$i}}" data-toggle="tab" href="#content_{{$i}}" role="tab">
<a class="nav-item nav-link {{if eq $i 0}}active{{end}}" id="id_{{$i}}" data-toggle="tab" href="#content_{{$i}}" onclick="contentChange('{{$i}}')" role="tab">
{{if eq $v.ProjectName ""}}
{{$i}}
{{else}}
Expand Down Expand Up @@ -254,7 +255,8 @@ <h5 class="portlet__head">对象存储配置</h5>
</div>

<button class="btn btn-primary submit_btn" style="margin-bottom: 15px;">Save</button>
<button class="btn btn-warning submit_btn_backupNow" style="margin-bottom: 15px;margin-left: 15px;">Save & Backup Now</button>
<button class="btn btn-primary submit_btn_backup_idx" style="margin-bottom: 15px;margin-left: 15px;">Save & 立即备份选中</button>
<button class="btn btn-warning submit_btn_backup_all" style="margin-bottom: 15px;margin-left: 15px;">Save & 立即备份全部</button>
</form>
</div>

Expand All @@ -267,14 +269,26 @@ <h5 class="portlet__head">对象存储配置</h5>
</main>

<script>
let contentIdx = 0

function contentChange(i) {
contentIdx = i
}

$(function(){
$(".submit_btn,.submit_btn_backupNow").on('click',function(e) {
$(".submit_btn,.submit_btn_backup_all,.submit_btn_backup_idx").on('click',function(e) {
e.preventDefault();
$('body').animate({ scrollTop: 0 }, 300);
let url = "/save"
if(e.target.classList.contains("submit_btn_backup_all")) {
url += "?backupAll=true"
}
if(e.target.classList.contains("submit_btn_backup_idx")) {
url += "?backupIdx="+contentIdx
}
$.ajax({
method: "POST",
url: "/save?backupNow=" + e.target.classList.contains("submit_btn_backupNow"),
url: url,
data: $('form').serialize(),
success: function (result) {
$('.alert').css("display", "block");
Expand Down Expand Up @@ -313,6 +327,8 @@ <h5 class="portlet__head">对象存储配置</h5>
$("#id_"+id).html(enabled == 0?name:name+'<span class="badge badge-pill badge-warning">停用</span>')
}



</script>

<script>
Expand Down

0 comments on commit 423c4a7

Please sign in to comment.