From 0abd886ecd27df2404df4783fe8ccfb33516a31d Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 9 May 2024 17:47:23 +0200 Subject: [PATCH 1/4] Reworked webui reader --- .gitignore | 1 + internal/conf/config.yaml | 6 +-- internal/httpcontroller/fileserver.go | 29 ++++++++++++++ internal/httpcontroller/handlers.go | 16 ++++++++ internal/httpcontroller/routes.go | 2 +- views/logs.html | 56 ++++++++++++++++++++++++++- 6 files changed, 104 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 705bc2c..59bf69f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ output/soundscape.wav.csv birdnet.db birdnet.txt custom_confidence_list.txt +conf/config.yaml diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index 2bf2f9a..76e7eb9 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -1,6 +1,6 @@ # BirdNET-Go configuration -debug: false # print debug messages, can help with problem solving +debug: true # print debug messages, can help with problem solving # Node specific settings main: @@ -45,8 +45,8 @@ realtime: id: 00000 # birdweather ID rtsp: - url: # RTSP stream URL - transport: tcp # RTSP Transport Protocol + url: rtsp://192.168.1.33:8554/ # RTSP stream URL + transport: udp # RTSP Transport Protocol mqtt: enabled: false # true to enable MQTT diff --git a/internal/httpcontroller/fileserver.go b/internal/httpcontroller/fileserver.go index 32221b0..7518c21 100644 --- a/internal/httpcontroller/fileserver.go +++ b/internal/httpcontroller/fileserver.go @@ -1,9 +1,11 @@ package httpcontroller import ( + "bufio" "io/fs" "mime" "net/http" + "os" "path/filepath" "strings" @@ -34,3 +36,30 @@ func customFileServer(e *echo.Echo, fileSystem fs.FS, root string) { fileServer.ServeHTTP(w, r) }))) } + +// readWebLog reads the content of the web.log file from the root directory and returns it as a string. +// It returns an error if there is an issue opening or reading the file. +func readWebLog() (string, error) { + // Open the web.log file + file, err := os.Open("webui.log") + if err != nil { + return "", err + } + defer file.Close() + + var content string + scanner := bufio.NewScanner(file) + + // Read the file line by line and append each line to the content string + for scanner.Scan() { + content += scanner.Text() + "\n" + } + + // Check if there was an error during scanning + if err := scanner.Err(); err != nil { + return "", err + } + + // Return the content of the file + return content, nil +} diff --git a/internal/httpcontroller/handlers.go b/internal/httpcontroller/handlers.go index 29bb1f2..d423bdd 100644 --- a/internal/httpcontroller/handlers.go +++ b/internal/httpcontroller/handlers.go @@ -387,3 +387,19 @@ func (s *Server) serveSpectrogramHandler(c echo.Context) error { // Serve the spectrogram image file return c.File(spectrogramPath) } + +// getLogsHandler handles GET requests to the /logs endpoint. +// It reads the content of the webui.log file and renders the logs view with the content. +func (s *Server) getLogsHandler(c echo.Context) error { + // Read the content of web.log + logContent, err := readWebLog() + if err != nil { + // Return an HTTP error if there is an issue reading the file + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read web.log: "+err.Error()) + } + + // Render the logs view and pass the logContent as data + return c.Render(http.StatusOK, "logs", map[string]interface{}{ + "LogContent": logContent, + }) +} diff --git a/internal/httpcontroller/routes.go b/internal/httpcontroller/routes.go index 32e3061..12aa76c 100644 --- a/internal/httpcontroller/routes.go +++ b/internal/httpcontroller/routes.go @@ -66,6 +66,7 @@ func (s *Server) initRoutes() { // Other static routes. s.Echo.Static("/clips", "clips") + s.Echo.GET("/logs", s.getLogsHandler) // Additional handlers. s.Echo.GET("/top-birds", s.topBirdsHandler) @@ -75,7 +76,6 @@ func (s *Server) initRoutes() { s.Echo.GET("/search", s.searchHandler) s.Echo.GET("/spectrogram", s.serveSpectrogramHandler) - // Handle both GET and DELETE requests for the /note route s.Echo.Add("GET", "/note", s.getNoteHandler) s.Echo.Add("DELETE", "/note", s.deleteNoteHandler) diff --git a/views/logs.html b/views/logs.html index a6d725d..a1dd3cb 100644 --- a/views/logs.html +++ b/views/logs.html @@ -1,5 +1,57 @@ {{define "logs"}} -Nothing here yet .. + + -{{end}} \ No newline at end of file + + + BirdNET-Go Logs + + + + + + + + + + + + +
+
+ {{ template "header" . }} +
+ + +
+
+ + {{if .LogContent}} +
{{.LogContent}}
+ {{else}} + It didn't work + {{end}} +
+
+ +
+
+
+ + {{ template "sidebar" . }} + + + + + + +{{end}} From 26619f186f7466ed9f4131a3bb4025b5abde0e12 Mon Sep 17 00:00:00 2001 From: Matthew Burton Date: Tue, 14 May 2024 20:13:57 +0200 Subject: [PATCH 2/4] Update .gitignore Removed forgotten parts --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 59bf69f..705bc2c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ output/soundscape.wav.csv birdnet.db birdnet.txt custom_confidence_list.txt -conf/config.yaml From e0bbb8f43953cc59826781a8aeffaf763c555681 Mon Sep 17 00:00:00 2001 From: Matthew Burton Date: Tue, 14 May 2024 20:16:10 +0200 Subject: [PATCH 3/4] Update config.yaml removed forgotten modifications --- internal/conf/config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index 76e7eb9..99255f1 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -1,6 +1,6 @@ # BirdNET-Go configuration -debug: true # print debug messages, can help with problem solving +debug: false # print debug messages, can help with problem solving # Node specific settings main: @@ -45,8 +45,8 @@ realtime: id: 00000 # birdweather ID rtsp: - url: rtsp://192.168.1.33:8554/ # RTSP stream URL - transport: udp # RTSP Transport Protocol + url: # RTSP stream URL + transport: tcp # RTSP Transport Protocol mqtt: enabled: false # true to enable MQTT @@ -98,4 +98,4 @@ output: password: secret # mysql database user password database: birdnet # mysql database name host: localhost # mysql database host - port: 3306 # mysql database port \ No newline at end of file + port: 3306 # mysql database port From 71b0de5ebd447f0ba034de4fdd323a5f9da1fa11 Mon Sep 17 00:00:00 2001 From: Matthew Burton Date: Tue, 14 May 2024 20:20:31 +0200 Subject: [PATCH 4/4] Update config.yaml reverted to base --- internal/conf/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index 99255f1..1116fcc 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -1,6 +1,6 @@ # BirdNET-Go configuration -debug: false # print debug messages, can help with problem solving +debug: false # print debug messages, can help with problem solving # Node specific settings main: