summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimport')
-rw-r--r--src/helsinki.at/rhimport/core.go7
-rw-r--r--src/helsinki.at/rhimport/fetcher.go19
-rw-r--r--src/helsinki.at/rhimport/importer.go7
-rw-r--r--src/helsinki.at/rhimport/session.go2
4 files changed, 15 insertions, 20 deletions
diff --git a/src/helsinki.at/rhimport/core.go b/src/helsinki.at/rhimport/core.go
index f74f422..bb92d30 100644
--- a/src/helsinki.at/rhimport/core.go
+++ b/src/helsinki.at/rhimport/core.go
@@ -54,6 +54,13 @@ func init() {
type ImportProgressCB func(step int, stepName string, progress float64, userdata interface{}) bool
type ImportDoneCB func(ImportResult, interface{}) bool
+type ImportResult struct {
+ ResponseCode int
+ ErrorString string
+ Cart uint
+ Cut uint
+}
+
type ImportContext struct {
conf *Config
rddb *RdDbChan
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go
index 55b814c..f5d5420 100644
--- a/src/helsinki.at/rhimport/fetcher.go
+++ b/src/helsinki.at/rhimport/fetcher.go
@@ -39,11 +39,6 @@ import (
"time"
)
-type FetchResult struct {
- ResponseCode int
- ErrorString string
-}
-
type FetcherCurlCBData struct {
basepath string
filename string
@@ -91,7 +86,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
return true
}
-func fetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) {
+func fetchFileCurl(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) {
rhl.Printf("curl-based fetcher called for '%s'", ctx.SourceUri)
easy := curl.EasyInit()
@@ -155,7 +150,7 @@ func fetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro
return
}
-func fetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err error) {
+func fetchFileLocal(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) {
rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri)
if ctx.ProgressCallBack != nil {
if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep {
@@ -192,7 +187,7 @@ func fetchFileLocal(ctx *ImportContext, res *FetchResult, uri *url.URL) (err err
return
}
-func fetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error {
+func fetchFileFake(ctx *ImportContext, res *ImportResult, uri *url.URL) error {
rhdl.Printf("Fake fetcher for '%s'", ctx.SourceUri)
if duration, err := strconv.ParseUint(uri.Host, 10, 32); err != nil {
@@ -226,7 +221,7 @@ func fetchFileFake(ctx *ImportContext, res *FetchResult, uri *url.URL) error {
return nil
}
-type FetchFunc func(*ImportContext, *FetchResult, *url.URL) (err error)
+type FetchFunc func(*ImportContext, *ImportResult, *url.URL) (err error)
// TODO: implement fetchers for:
// archiv://
@@ -262,7 +257,7 @@ func fetcherInit() {
}
}
-func checkPassword(ctx *ImportContext, result *FetchResult) (err error) {
+func checkPassword(ctx *ImportContext, result *ImportResult) (err error) {
ok := false
if ok, err = ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil {
return
@@ -274,8 +269,8 @@ func checkPassword(ctx *ImportContext, result *FetchResult) (err error) {
return
}
-func FetchFile(ctx *ImportContext) (res *FetchResult, err error) {
- res = &FetchResult{ResponseCode: http.StatusOK}
+func FetchFile(ctx *ImportContext) (res *ImportResult, err error) {
+ res = &ImportResult{ResponseCode: http.StatusOK}
var uri *url.URL
if uri, err = url.Parse(ctx.SourceUri); err != nil {
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index e4f979f..4a0bece 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -35,13 +35,6 @@ import (
"path"
)
-type ImportResult struct {
- ResponseCode int
- ErrorString string
- Cart uint
- Cut uint
-}
-
func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) {
self.ResponseCode = rdres.ResponseCode
self.ErrorString = rdres.ErrorString
diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go
index 80acee1..e0f1a4b 100644
--- a/src/helsinki.at/rhimport/session.go
+++ b/src/helsinki.at/rhimport/session.go
@@ -108,7 +108,7 @@ func sessionImportRun(ctx ImportContext, done chan<- ImportResult) {
done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0}
return
} else if res.ResponseCode != http.StatusOK {
- done <- ImportResult{res.ResponseCode, res.ErrorString, 0, 0}
+ done <- *res
return
}