Correct config provider, no backblaze goroutine.

Addressing a bug where the configuration would try to interpret the
provider name from the entry in the configuration, rather than the
explicit `provider`. Also removed background uploading from Backblaze
(was worth a shot).
This commit is contained in:
Gabriel Simmer 2020-04-02 15:31:30 +01:00
parent 58128a0e98
commit 207676d4a7
No known key found for this signature in database
GPG key ID: 33BA4D83B160A0A9
4 changed files with 17 additions and 13 deletions

View file

@ -214,13 +214,16 @@ func (bp *BackblazeProvider) SaveFile(file multipart.File, handler *multipart.Fi
}
var data BackblazeUploadInfo
json.Unmarshal(bucketData, &data)
err = json.Unmarshal(bucketData, &data)
if err != nil {
fmt.Println(err.Error())
return false
}
req, err = http.NewRequest("POST",
data.UploadUrl,
file,
)
if err != nil {
fmt.Println(err.Error())
return false
@ -243,12 +246,11 @@ func (bp *BackblazeProvider) SaveFile(file multipart.File, handler *multipart.Fi
req.ContentLength = handler.Size
// Upload in background.
go func() {
res, err = client.Do(req)
if err != nil {
fmt.Println(err.Error())
return false
}
}()
return true
}

View file

@ -63,7 +63,11 @@ func (dp *DiskProvider) SaveFile(file multipart.File, handler *multipart.FileHea
}
defer f.Close()
io.Copy(f, file)
_, err = io.Copy(f, file)
if err != nil {
fmt.Println(err.Error())
return false
}
return true
}

View file

@ -7,12 +7,12 @@ var Providers map[string]*FileProviderInterface
func TranslateProvider(codename string, i *FileProviderInterface) {
provider := ProviderConfig[codename]
if codename == "disk" {
if provider.Provider == "disk" {
*i = &DiskProvider{provider,}
return
}
if codename == "backblaze" {
if provider.Provider == "backblaze" {
bbProv := &BackblazeProvider{provider, provider.Config["bucket"], ""}
*i = bbProv
return

View file

@ -12,7 +12,6 @@ import (
)
func HandleProvider() common.Handler {
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
vars := mux.Vars(r)
if r.Method == "GET" {
@ -66,7 +65,6 @@ func HandleProvider() common.Handler {
}
func ListProviders() common.Handler {
return func(rc *common.RouterContext, w http.ResponseWriter, r *http.Request) *common.HTTPError {
var providers []string
for v, _ := range files.ProviderConfig {