func changeAuditionHandler(w http.ResponseWriter, r *http.Request) { data := setDefaultData(w, r) roleId := r.URL.Query().Get("id") role := role.FindRole(roleId) data["role"] = role display(w, "changeAudition", &Page{Title: role.Title, Data: data}) }
//Submits an audition in auditions/{auditionid} func submitAuditionHandler(w http.ResponseWriter, r *http.Request) { s := redis_session.Session(w, r) fmt.Println(r.Form) err := r.ParseMultipartForm(32 << 20) if err != nil { log.Printf("%s", err) } roleID := r.FormValue("id") fmt.Println(r.Form) file, handler, err := r.FormFile("auditionFile") defer file.Close() if err != nil { fmt.Printf("err opening audition file: %s", err) return } bytes, err := file.Seek(0, 2) if err != nil { panic(err) } var kilobytes int64 kilobytes = (bytes / 1024) var megabytes float64 megabytes = (float64)(kilobytes / 1024) if megabytes < 6 { attachmentURL := "/auditions/" + roleID + "/" + s.Get("Email") + "/" + handler.Filename uploader := s3manager.NewUploader(session.New()) result, err := uploader.Upload(&s3manager.UploadInput{ Body: file, Bucket: aws.String("coaud"), Key: aws.String(attachmentURL), }) if err != nil { log.Fatalln("Failed to upload", err) } log.Println("Successfully uploaded to", result.Location) //create a new audition and add the link auditionID := bson.NewObjectId() audition := role.NewAudition(user.FindUser(s.Get("Email")), handler.Filename, result.Location, auditionID) curRole := role.FindRole(roleID) role.InsertAudition(audition, curRole) w.Write([]byte("uploaded")) } else { w.Write([]byte("rejected")) } }
func roleHandler(w http.ResponseWriter, r *http.Request) { data := setDefaultData(w, r) roleID := r.URL.Query().Get("id") role := role.FindRole(roleID) data["role"] = role // svc := s3.New(session.New()) // //Pre-signs all audio clips so they cannot be downloaded! -- Do we want this? // for _,audition := range role.Audition { // req, _ := svc.GetObjectRequest(&s3.GetObjectInput{ // Bucket: aws.String("coaud"), // Key: aws.String(audition.AttachmentUrl), // }) // temp, err := req.Presign(15 * time.Minute) // if err != nil { // log.Println("Failed to sign request", err) // } // audition.TempUrl = temp // } data["author"] = role.GetUser() display(w, "viewRole", &Page{Title: role.Title, Data: data}) }