modifications in ui for audio recording display and some backend fixes

This commit is contained in:
tdv
2025-09-03 11:55:34 +03:00
parent 35c5a4dc46
commit 247a2ed6b2
36 changed files with 944 additions and 64 deletions

View File

@@ -1,8 +1,8 @@
package handlers
import (
"context"
"fmt"
"io"
"mime/multipart"
"net/http"
"path"
@@ -111,13 +111,35 @@ func (h *RecordsHandler) File(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
var rec models.Record
if err := h.db.First(&rec, id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
c.Status(http.StatusNotFound)
return
}
u, err := h.minio.PresignedGetObject(context.Background(), h.recordsBucket, rec.ObjectKey, h.presignTTL, nil)
// Stream from MinIO to the client to avoid redirecting to an internal host like "minio".
obj, err := h.minio.GetObject(c.Request.Context(), h.recordsBucket, rec.ObjectKey, minio.GetObjectOptions{})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "presign failed"})
c.Status(http.StatusInternalServerError)
return
}
c.Redirect(http.StatusFound, u.String())
defer obj.Close()
info, err := h.minio.StatObject(c.Request.Context(), h.recordsBucket, rec.ObjectKey, minio.StatObjectOptions{})
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
if ct := info.ContentType; ct != "" {
c.Header("Content-Type", ct)
} else {
c.Header("Content-Type", "application/octet-stream")
}
if info.Size >= 0 {
c.Header("Content-Length", strconv.FormatInt(info.Size, 10))
}
if filename := path.Base(rec.ObjectKey); filename != "" {
c.Header("Content-Disposition", fmt.Sprintf("inline; filename=%q", filename))
}
c.Status(http.StatusOK)
_, _ = io.Copy(c.Writer, obj)
}

View File

@@ -48,7 +48,7 @@ func Build(db *gorm.DB, minio *minio.Client, cfg *config.Config) *gin.Engine {
r.POST("/devices/:guid/set_users", authMW, adminOnly, devH.SetUsers)
r.POST("/devices/:guid/remove_from_user", authMW, devH.RemoveFromUser)
r.POST("/records/upload", authMW, recH.Upload)
r.POST("/records/upload", recH.Upload)
r.GET("/records", authMW, recH.List)
r.GET("/records/:id/file", authMW, recH.File)