示例#1
0
// initiateTranscriptionJobHandlerJSON takes a POST request containing a json object,
// decodes it into a transcriptionJobData struct, and starts a transcription task.
func initiateTranscriptionJobHandlerJSON(w http.ResponseWriter, r *http.Request) {
	jsonData := new(transcriptionJobData)

	// unmarshal from the response body directly into our struct
	if err := json.NewDecoder(r.Body).Decode(jsonData); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	executer := tasks.DefaultTaskExecuter
	executer.QueueTask(transcription.MakeIBMTaskFunction(jsonData.AudioURL, jsonData.EmailAddresses, jsonData.SearchWords))
}
示例#2
0
// initiateTranscriptionJobHandler takes a POST request from a form,
// decodes it into a transcriptionJobData struct, and starts a transcription task.
func initiateTranscriptionJobHandler(w http.ResponseWriter, r *http.Request) {
	executer := tasks.DefaultTaskExecuter
	emails := strings.Split(r.FormValue("emails"), ",")
	words := strings.Split(r.FormValue("words"), ",")
	log.Println(emails, words, len(emails), len(words))
	id := executer.QueueTask(transcription.MakeIBMTaskFunction(r.FormValue("url"), emails, words))

	session, err := store.Get(r, flashSession)
	if err != nil {
		log.Fatal(err)
	}

	session.AddFlash(flash{
		Title: "Task Started!",
		Body:  fmt.Sprintf("Task %s was successfully started. The results will be emailed to you upon completion.", id),
	})
	session.Save(r, w)

	http.Redirect(w, r, "/", http.StatusFound)
}