-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateVideo.go
More file actions
54 lines (45 loc) · 1.13 KB
/
updateVideo.go
File metadata and controls
54 lines (45 loc) · 1.13 KB
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
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"log"
"net/http"
"net/url"
"github.com/SUASecLab/workadventure_admin_extensions/extensions"
)
func updateVideo(videoUrl, userToken string, w http.ResponseWriter) {
// Check if user is allowed to update the video
decision, err := extensions.GetAuthDecision("http://" + sidecarUrl +
"/auth?token=" + userToken + "&service=updateVideo")
if !decision.Allowed {
w.WriteHeader(http.StatusForbidden)
return
}
if err != nil {
log.Println("Could not update video: ", err)
fmt.Fprintf(w, "Could not update video")
return
}
// Change video
realUrl, err := url.Parse(videoUrl)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
msg := "Could not parse URL:"
log.Println(msg, err)
fmt.Fprintln(w, msg, err)
return
}
if realUrl.Host != "www.youtube.com" ||
realUrl.Path != "/watch" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "Not a YouTube video")
return
}
videoId := realUrl.Query().Get("v")
if len(videoId) != 11 {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "Invalid video ID")
return
}
video = videoId
fmt.Fprintf(w, "Stored video successfully")
}