feat: implement temporary file creation for log downloads to prevent Content-Length mismatches
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
3
cookies.txt
Normal file
3
cookies.txt
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user