diff options
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSimple.go | 47 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/rhimportd.go | 3 |
2 files changed, 32 insertions, 18 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 } diff --git a/src/helsinki.at/rhimportd/rhimportd.go b/src/helsinki.at/rhimportd/rhimportd.go index c1af87e..03d0340 100644 --- a/src/helsinki.at/rhimportd/rhimportd.go +++ b/src/helsinki.at/rhimportd/rhimportd.go @@ -36,6 +36,7 @@ func main() { web_addr_s := flag.String("web-addr", ":4000", "addr:port to listen on, default: ':4000'") rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file, default: '/etc/rd.conf'") rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api, default: 'http://localhost/rd-bin/rdxport.cgi'") + temp_dir_s := flag.String("tmp-dir", "/tmp", "path to temporary files, default: '/tmp'") help := flag.Bool("help", false, "show usage") flag.Parse() @@ -44,7 +45,7 @@ func main() { return } - conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s) + conf, err := rhimport.NewConfig(rdconf_s, rdxport_url_s, temp_dir_s) if err != nil { rhl.Println("Error reading configuration:", err) return |