Browse Source

feat: support clear log (#12)

Co-authored-by: jeessy2 <[email protected]>
jeessy2 3 years ago
parent
commit
f9b81ac286
3 changed files with 22 additions and 0 deletions
  1. 1 0
      main.go
  2. 5 0
      web/logs.go
  3. 16 0
      web/writing.html

+ 1 - 0
main.go

@@ -27,6 +27,7 @@ func main() {
 	http.HandleFunc("/", web.BasicAuth(web.WritingConfig))
 	http.HandleFunc("/save", web.BasicAuth(web.Save))
 	http.HandleFunc("/logs", web.BasicAuth(web.Logs))
+	http.HandleFunc("/clearLog", web.BasicAuth(web.ClearLog))
 	http.HandleFunc("/webhookTest", web.BasicAuth(web.WebhookTest))
 
 	// 运行

+ 5 - 0
web/logs.go

@@ -37,3 +37,8 @@ func Logs(writer http.ResponseWriter, request *http.Request) {
 		writer.Write([]byte("<br/>"))
 	}
 }
+
+// ClearLog
+func ClearLog(writer http.ResponseWriter, request *http.Request) {
+	mlogs.Logs = mlogs.Logs[:0]
+}

+ 16 - 0
web/writing.html

@@ -231,6 +231,7 @@
 
       <div class="col-md-3">
         <p class="font-weight-light text-break" style="margin-top: 115px;font-size: 13px;" id="logs"></p>
+        <button type="button" class="btn btn-outline-primary btn-sm" id="clearLogBtn">清空日志</button>
       </div>
     </div>
 
@@ -285,6 +286,21 @@
     }
     getLogs()
     setInterval(getLogs, 5 * 1000)
+    $(function(){
+      $("#clearLogBtn").on("click", function(e) {
+        e.preventDefault();
+        $.ajax({
+            method: "GET",
+            url: "/clearLog",
+            success: function() {
+              getLogs()
+            },
+            error: function(jqXHR) {
+              alert(jqXHR.statusText);
+            }
+        })
+      })
+    })
   </script>
 
   <script>