Files
Aroll-Cutter/handlers/zoom.go

38 lines
899 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handlers
import (
"encoding/json"
"net/http"
"aroll/transcode"
"aroll/ws"
)
type zoomRequest struct {
Zoom float64 `json:"zoom"` // 1100, percentage of total duration to show
Center float64 `json:"center"` // scroll center in seconds
Duration float64 `json:"duration"` // total video duration in seconds
}
func ZoomHandler(hub *ws.Hub) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
var req zoomRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "bad JSON: "+err.Error(), http.StatusBadRequest)
return
}
result := transcode.TimelineZoom(req.Center, req.Zoom, req.Duration)
data, _ := json.Marshal(result)
hub.Broadcast(data)
w.WriteHeader(http.StatusAccepted)
}
}