-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
76 lines (60 loc) · 1.86 KB
/
create.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bluebeam Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
package main
import (
"html/template"
"net/http"
)
func createPage(w http.ResponseWriter, r *http.Request) {
client := getOAuthClient(r.Context())
projectID := r.FormValue("project")
sessionName := r.FormValue("session")
r.ParseMultipartForm(32 << 20)
file, handler, err := r.FormFile("sessionFile")
if err != nil {
redirectToError(w, r, err)
return
}
defer file.Close()
projectFilesResponse, err := startFileUpload(client, projectID, handler.Filename)
if err != nil {
redirectToError(w, r, err)
return
}
err = uploadToAWS(projectFilesResponse, file, handler.Size)
if err != nil {
redirectToError(w, r, err)
return
}
err = confirmUpload(client, projectID, projectFilesResponse.ID)
if err != nil {
redirectToError(w, r, err)
return
}
sessionResponse, err := createSession(client, sessionName)
if err != nil {
redirectToError(w, r, err)
return
}
checkoutResponse, err := checkoutFileToSession(client, sessionResponse.ID, projectID, projectFilesResponse.ID)
if err != nil {
redirectToError(w, r, err)
return
}
html, err := Asset("assets/create.html")
if err != nil {
redirectToError(w, r, err)
return
}
t, _ := template.New("createSession").Parse(string(html))
createSessionData := struct {
SessionName string
SessionID string
ProjectID string
FileSessionID int
FileProjectID int
}{SessionName: sessionName, SessionID: sessionResponse.ID, ProjectID: projectID, FileSessionID: checkoutResponse.ID, FileProjectID: projectFilesResponse.ID}
t.Execute(w, createSessionData)
}