modifications in ui for audio recording display and some backend fixes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user