Track timestamps server-side

This commit is contained in:
Carl Pearson
2025-05-01 05:50:53 -06:00
parent 010c6bd191
commit b4aaa4410c
3 changed files with 49 additions and 35 deletions

View File

@@ -20,24 +20,20 @@ func SetTimestamp(c echo.Context) error {
// Define a struct to receive the timestamp from JSON
type TimestampRequest struct {
Timestamp string `json:"timestamp"`
Timestamp float64 `json:"timestamp"`
}
// Parse the request body
var req TimestampRequest
if err := c.Bind(&req); err != nil {
log.Errorln(err)
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request body"})
}
// Validate that timestamp was provided
if req.Timestamp == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Timestamp is required"})
}
// Get database connection
db := database.Get()
log.Debugln("set video", id, "timestamp:", req.Timestamp)
// Update the timestamp field with the value from the request
db := database.Get()
result := db.Model(&originals.Original{}).
Where("id = ?", id).
Update("timestamp", req.Timestamp)