implamented Aroll cuter
This commit is contained in:
38
handlers/zoom.go
Normal file
38
handlers/zoom.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"aroll/transcode"
|
||||
"aroll/ws"
|
||||
)
|
||||
|
||||
type zoomRequest struct {
|
||||
Zoom float64 `json:"zoom"` // 1–100, 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
|
||||
}
|
||||
|
||||
h := transcode.HandlerZoom{Center: req.Center}
|
||||
result := h.TimelineZoom(req.Zoom, req.Duration)
|
||||
|
||||
data, _ := json.Marshal(result)
|
||||
hub.Broadcast(data)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user