mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-04 07:56:33 +08:00
Refactor log handling and add UI auto-update toggle
This commit refactors the log handling in the API to use a switch statement for improved readability and maintainability. It also introduces error messages with more context when reading or truncating the log file fails. On the frontend, a new auto-update toggle button has been added to the log viewer, allowing users to enable or disable automatic log updates. The button's appearance changes based on its state, providing a clear visual indication of whether auto-update is active. Additionally, the button styling has been updated to ensure consistency across the interface.
This commit is contained in:
@@ -268,25 +268,27 @@ func restartHandler(w http.ResponseWriter, r *http.Request) {
|
||||
//
|
||||
// No return values are provided since the function writes directly to the response writer.
|
||||
func logHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
logFilePath := app.GetLogFilepath()
|
||||
|
||||
if r.Method == "GET" {
|
||||
data, err := os.ReadFile(app.GetLogFilepath())
|
||||
// Send current state of the log file immediately
|
||||
data, err := os.ReadFile(logFilePath)
|
||||
if err != nil {
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "Error reading log file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
Response(w, data, "text/plain")
|
||||
} else if r.Method == "DELETE" {
|
||||
case "DELETE":
|
||||
err := os.Truncate(app.GetLogFilepath(), 0)
|
||||
if err != nil {
|
||||
http.Error(w, "", http.StatusServiceUnavailable)
|
||||
http.Error(w, "Error truncating log file", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
http.Error(w, "", http.StatusBadRequest)
|
||||
return
|
||||
Response(w, "Log file deleted", "text/plain")
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
|
Reference in New Issue
Block a user