From 7445627f7e582ffbc82a93a85aeab5d7fcedcd6d Mon Sep 17 00:00:00 2001 From: Joren Date: Tue, 24 Sep 2024 15:17:58 +0200 Subject: [PATCH] Add option to disable the console broadcasts --- config.toml | 3 ++- src/config.go | 1 + src/downloaders.go | 5 +++-- src/handlers.go | 13 ++++++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/config.toml b/config.toml index 7fe8fdb..58e198c 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,7 @@ BaseDir = "/mnt/media" Format = "mkv" TempBaseDir = "/tmp/nre" +EnableConsole = true [N_m3u8DLRE] -Path = "nre" +Path = "nre" \ No newline at end of file diff --git a/src/config.go b/src/config.go index b7253bb..fc36b81 100644 --- a/src/config.go +++ b/src/config.go @@ -15,6 +15,7 @@ type Config struct { N_m3u8DLRE struct { Path string } + EnableConsole bool } var config Config diff --git a/src/downloaders.go b/src/downloaders.go index 6532315..c027fb7 100644 --- a/src/downloaders.go +++ b/src/downloaders.go @@ -132,8 +132,9 @@ func downloadFile(drmdFilename string, item Item, jobInfo *JobInfo) error { for { if outputBuffer.Len() > 0 { message := outputBuffer.Bytes() - logger.LogInfo("Download File", fmt.Sprintf("Broadcasting message: %s", message)) - broadcast(drmdFilename, message) + if config.EnableConsole { + broadcast(drmdFilename, message) + } outputBuffer.Reset() } time.Sleep(1 * time.Second) diff --git a/src/handlers.go b/src/handlers.go index 7a6899e..309c4ae 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -386,8 +386,13 @@ var clients = make(map[string]map[*websocket.Conn]bool) var mu sync.Mutex func handleWebSocket(w http.ResponseWriter, r *http.Request) { + fmt.Println(config.EnableConsole) + if !config.EnableConsole { + http.Error(w, "Console output is disabled", http.StatusForbidden) + return + } + filename := r.URL.Query().Get("filename") - fmt.Println("Filename:", filename) if filename == "" { http.Error(w, "Filename is required", http.StatusBadRequest) return @@ -423,11 +428,13 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) { } func broadcast(filename string, message []byte) { + if !config.EnableConsole { + return + } + mu.Lock() defer mu.Unlock() - logger.LogInfo("Broadcast", fmt.Sprintf("Broadcasting message for filename: %s", filename)) - for client := range clients[filename] { if err := client.WriteMessage(websocket.TextMessage, message); err != nil { client.Close()