summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd/ctrlWebSimple.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-07 15:55:35 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-08 00:28:37 (GMT)
commit6e5d14f4a2189dbc0f0404c398d11878e356ecd7 (patch)
tree23ed10d556a8145537ac40af64873a3790913c3b /src/helsinki.at/rhimportd/ctrlWebSimple.go
parent25928481ff6d29db10380209feb24775eb83f6c4 (diff)
major refactoring of base structure
Diffstat (limited to 'src/helsinki.at/rhimportd/ctrlWebSimple.go')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index eb781dd..8080514 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -26,11 +26,11 @@ package main
import (
"encoding/json"
+ "fmt"
"helsinki.at/rhimport"
"html"
"net/http"
_ "net/http/pprof"
- "fmt"
)
type webSimpleRequestData struct {
@@ -38,6 +38,7 @@ type webSimpleRequestData struct {
Password string `json:"PASSWORD"`
GroupName string `json:"GROUP_NAME"`
Cart int `json:"CART_NUMBER"`
+ Cut int `json:"CUT_NUMBER"`
Channels int `json:"CHANNELS"`
NormalizationLevel int `json:"NORMALIZATION_LEVEL"`
AutotrimLevel int `json:"AUTOTRIM_LEVEL"`
@@ -46,16 +47,15 @@ type webSimpleRequestData struct {
}
type webSimpleResponseData struct {
- ResponseCode int `json:"REPONSE_CODE"`
- ErrorString string `json:"ERROR_STRING"`
- AudioConvertError int `json:"AudioConvertError"`
+ ResponseCode int `json:"REPONSE_CODE"`
+ ErrorString string `json:"ERROR_STRING"`
}
-func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string, audio_err int) {
+func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{code, error_str, audio_err}
+ respdata := webSimpleResponseData{code, error_str}
encoder.Encode(respdata)
}
@@ -63,17 +63,16 @@ func webSimpleResponse(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{200, "SUCCESS", 0}
+ respdata := webSimpleResponseData{200, "SUCCESS"}
encoder.Encode(respdata)
}
-func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter, r *http.Request) {
- rhdl.Printf("SimpleHandler: request for '%s'", html.EscapeString(r.URL.Path))
+func webSimpleParseRequest(conf *rhimport.Config, trusted bool, r *http.Request) (ctx *rhimport.ImportContext, err error) {
decoder := json.NewDecoder(r.Body)
var reqdata webSimpleRequestData
- if err := decoder.Decode(&reqdata); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("Error parsing JSON response: %s", err), 0)
+ if jsonerr := decoder.Decode(&reqdata); jsonerr != nil {
+ err = fmt.Errorf("Error parsing JSON response: %s", jsonerr)
return
}
@@ -81,22 +80,36 @@ func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter
if trusted {
username = r.Header.Get("X-Forwarded-User")
}
- ctx := rhimport.NewImportContext(conf, username, reqdata.GroupName, reqdata.Cart)
+ ctx = rhimport.NewImportContext(conf, username, reqdata.GroupName)
ctx.Password = reqdata.Password
ctx.Trusted = trusted
+ ctx.Cart = reqdata.Cart
+ ctx.Cut = reqdata.Cut
ctx.Channels = reqdata.Channels
ctx.NormalizationLevel = reqdata.NormalizationLevel
ctx.AutotrimLevel = reqdata.AutotrimLevel
ctx.UseMetaData = reqdata.UseMetaData
+ ctx.SourceUri = reqdata.SourceUri
+ return
+}
- // TODO: call the fetcher
+func webSimpleHandler(conf *rhimport.Config, trusted bool, w http.ResponseWriter, r *http.Request) {
+ rhdl.Printf("SimpleHandler: request for '%s'", html.EscapeString(r.URL.Path))
+
+ var ctx *rhimport.ImportContext
+ var err error
+ if ctx, err = webSimpleParseRequest(conf, trusted, r); err != nil {
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
+ return
+ }
- // TODO: the following should be returned by the fetcher
- ctx.SourceFile = "<undefined>"
- ctx.DeleteSourceFile = true
+ if err := rhimport.FetchFile(ctx); err != nil {
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
+ return
+ }
if err := rhimport.ImportFile(ctx); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error(), 0)
+ webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}