diff --git a/backend/internal/api/handlers/logs_handler.go b/backend/internal/api/handlers/logs_handler.go index d9ca204c..23296b08 100644 --- a/backend/internal/api/handlers/logs_handler.go +++ b/backend/internal/api/handlers/logs_handler.go @@ -1,6 +1,7 @@ package handlers import ( + "io" "net/http" "os" "strconv" @@ -75,6 +76,30 @@ func (h *LogsHandler) Download(c *gin.Context) { return } + // Create a temporary file to serve a consistent snapshot + // This prevents Content-Length mismatches if the live log file grows during download + tmpFile, err := os.CreateTemp("", "cpmp-log-*.log") + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create temp file"}) + return + } + defer os.Remove(tmpFile.Name()) + + srcFile, err := os.Open(path) + if err != nil { + tmpFile.Close() + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to open log file"}) + return + } + defer srcFile.Close() + + if _, err := io.Copy(tmpFile, srcFile); err != nil { + tmpFile.Close() + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to copy log file"}) + return + } + tmpFile.Close() + c.Header("Content-Disposition", "attachment; filename="+filename) - c.File(path) + c.File(tmpFile.Name()) } diff --git a/cookies.txt b/cookies.txt new file mode 100644 index 00000000..1f4251a9 --- /dev/null +++ b/cookies.txt @@ -0,0 +1,3 @@ +# Netscape HTTP Cookie File +# https://curl.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk.