summaryrefslogtreecommitdiff
path: root/src/helsinki.at
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-12 01:41:25 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-12 01:41:25 (GMT)
commitd5450bb18ea879ca9a63aa1d16a5c647e8ecf692 (patch)
treea6e934caee5f96b686a9a4b8d677a9eacbae067c /src/helsinki.at
parent6ceb3358b6ffbe803e4fe1d811b5a2f266fc49d9 (diff)
ImportFile now passes through result from RDXport
Diffstat (limited to 'src/helsinki.at')
-rw-r--r--src/helsinki.at/rhimport/importer.go44
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSimple.go11
2 files changed, 39 insertions, 16 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index 55fbe62..e29e4df 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -117,16 +117,33 @@ func (ctx *ImportContext) getShowInfo() (err error) {
return
}
+type ImportResult struct {
+ ResponseCode int
+ ErrorString string
+ Cart int
+ Cut int
+}
+
+func NewImportResult(rdres *RDWebResult) *ImportResult {
+ res := new(ImportResult)
+ res.ResponseCode = rdres.ResponseCode
+ res.ErrorString = rdres.ErrorString
+ if rdres.AudioConvertError != 0 {
+ res.ErrorString += fmt.Sprint(", Audio Convert Error: %d", rdres.AudioConvertError)
+ }
+ return res
+}
+
type RDWebResult struct {
ResponseCode int `xml:"ResponseCode"`
ErrorString string `xml:"ErrorString"`
- AudioConvertError string `xml:"AudioConvertError"`
+ AudioConvertError int `xml:"AudioConvertError"`
}
-func decodeRDWebResult(data io.Reader) (result *RDWebResult, err error) {
+func NewRDWebResultFromXML(data io.Reader) (res *RDWebResult, err error) {
decoder := xml.NewDecoder(data)
- result = &RDWebResult{}
- if xmlerr := decoder.Decode(result); xmlerr != nil {
+ res = &RDWebResult{}
+ if xmlerr := decoder.Decode(res); xmlerr != nil {
err = fmt.Errorf("Error parsing XML response: %s", xmlerr)
return
}
@@ -220,7 +237,7 @@ func send_post_request(url string, b *bytes.Buffer, contenttype string) (result
defer res.Body.Close()
// TODO: some commands might return something else...
- return decodeRDWebResult(res.Body)
+ return NewRDWebResultFromXML(res.Body)
}
func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) {
@@ -302,7 +319,7 @@ func import_audio(ctx *ImportContext) (result *RDWebResult, err error) {
// if status_code, err = easy.Getinfo(curl.INFO_RESPONSE_CODE); err != nil {
// return
// }
- return decodeRDWebResult(bufio.NewReader(&resbody))
+ return NewRDWebResultFromXML(bufio.NewReader(&resbody))
} else {
err = fmt.Errorf("Error initializing libcurl")
}
@@ -328,7 +345,7 @@ func cleanup_files(ctx *ImportContext) {
return
}
-func ImportFile(ctx *ImportContext) (err error) {
+func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
rhl.Println("ImportFile called for", ctx.SourceFile)
defer cleanup_files(ctx)
@@ -342,16 +359,21 @@ func ImportFile(ctx *ImportContext) (err error) {
}
}
- var result *RDWebResult
- if result, err = import_audio(ctx); err != nil {
+ var rdres *RDWebResult
+ if rdres, err = import_audio(ctx); err != nil {
return
}
if ctx.ProgressCallBack != nil {
ctx.ProgressCallBack(2, "importing", 1.0, ctx.ProgressCallBackData)
}
- rhdl.Printf("StatusCode: %d, ErrorString: '%s', AudioConverterError: %s\n", result.ResponseCode, result.ErrorString, result.AudioConvertError)
+ res = NewImportResult(rdres)
+ rhdl.Printf("StatusCode: %d, ErrorString: '%s'\n", res.ResponseCode, res.ErrorString)
- rhl.Println("ImportFile succesfully imported", ctx.SourceFile)
+ if res.ResponseCode == http.StatusOK {
+ rhl.Println("ImportFile succesfully imported", ctx.SourceFile)
+ } else {
+ rhl.Println("ImportFile import of", ctx.SourceFile, "was unsuccesful")
+ }
return
}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go
index 4cac593..9b25dad 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSimple.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go
@@ -59,11 +59,11 @@ func webSimpleErrorResponse(w http.ResponseWriter, code int, error_str string) {
encoder.Encode(respdata)
}
-func webSimpleResponse(w http.ResponseWriter) {
+func webSimpleResponse(w http.ResponseWriter, result *rhimport.ImportResult) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
encoder := json.NewEncoder(w)
- respdata := webSimpleResponseData{200, "SUCCESS"}
+ respdata := webSimpleResponseData{result.ResponseCode, result.ErrorString}
encoder.Encode(respdata)
}
@@ -108,16 +108,17 @@ func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDb, trusted bool,
return
}
- if err := rhimport.FetchFile(ctx); err != nil {
+ if err = rhimport.FetchFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- if err := rhimport.ImportFile(ctx); err != nil {
+ var result *rhimport.ImportResult
+ if result, err = rhimport.ImportFile(ctx); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- webSimpleResponse(w)
+ webSimpleResponse(w, result)
return
}