-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_progress.go
46 lines (38 loc) 路 911 Bytes
/
post_progress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package rest
import (
"encoding/json"
"github.com/boggydigital/yet/data"
"net/http"
"strings"
)
type ProgressRequest struct {
VideoId string `json:"v"`
CurrentTime string `json:"t"`
}
func PostProgress(w http.ResponseWriter, r *http.Request) {
// POST /progress
// {v, t}
var err error
progressRdx, err = progressRdx.RefreshWriter()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
decoder := json.NewDecoder(r.Body)
var pr ProgressRequest
err = decoder.Decode(&pr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := progressRdx.ReplaceValues(data.VideoProgressProperty, pr.VideoId, trimTime(pr.CurrentTime)); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func trimTime(ts string) string {
if tt, _, ok := strings.Cut(ts, "."); ok {
return tt
}
return ts
}