瀏覽代碼

feat: Add a 'save & backup now' button (#3)

jeessy2 3 年之前
父節點
當前提交
ff8c1387fb
共有 3 個文件被更改,包括 10 次插入7 次删除
  1. 3 3
      client/backup.go
  2. 3 1
      web/save.go
  3. 4 3
      web/writing.html

+ 3 - 3
client/backup.go

@@ -44,7 +44,7 @@ func RunLoop() {
 		}
 
 		delay := util.GetDelaySeconds(backupConf.StartTime)
-		ticker := time.NewTicker(time.Second)
+		ticker := time.NewTicker(delay)
 		log.Printf("%s项目将在%.1f小时后运行\n", backupConf.ProjectName, delay.Hours())
 
 		bl.Wg.Add(1)
@@ -144,9 +144,9 @@ func backup(backupConf entity.BackupConfig) (outFileName os.FileInfo, err error)
 	shell.Dir = backupConf.GetProjectPath()
 	outputBytes, err := shell.CombinedOutput()
 	if len(outputBytes) > 0 {
-		log.Printf("<span title=\"%s\">执行shell的输出:鼠标移动此处查看</span>", util.EscapeShell(string(outputBytes)))
+		log.Printf("<span title=\"%s\">%s 执行shell的输出:鼠标移动此处查看</span>\n", util.EscapeShell(string(outputBytes)), backupConf.ProjectName)
 	} else {
-		log.Printf("执行shell的输出为空")
+		log.Printf("执行shell的输出为空\n")
 	}
 
 	// execute shell success

+ 3 - 1
web/save.go

@@ -49,7 +49,9 @@ func Save(writer http.ResponseWriter, request *http.Request) {
 	// 没有错误
 	if err == nil {
 		conf.CreateBucketIfNotExist()
-		go client.RunOnce()
+		if request.URL.Query().Get("backupNow") == "true" {
+			go client.RunOnce()
+		}
 		// 重新进行循环
 		client.StopRunLoop()
 		go client.RunLoop()

+ 4 - 3
web/writing.html

@@ -30,6 +30,7 @@
         <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>
 
           <div class="alert alert-success" style="display: none;">
             <strong id="resultMsg">保存成功</strong>
@@ -224,7 +225,7 @@
           </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>
         </form>
       </div>
 
@@ -238,12 +239,12 @@
   <script>
 
     $(function(){
-      $(".submit_btn").on('click',function(e) {
+      $(".submit_btn,.submit_btn_run").on('click',function(e) {
         e.preventDefault();
         $('body').animate({ scrollTop: 0 }, 300);
         $.ajax({
           method: "POST",
-          url: "/save",
+          url: "/save?backupNow=" + e.target.classList.contains("submit_btn_backupNow"),
           data: $('form').serialize(),
           success: function (result) {
             $('.alert').css("display", "block");