From ccebab35da23e640628f463b38ea7e4f1b7c535f Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Thu, 6 Jun 2019 16:31:35 +0200 Subject: [PATCH] fix bugs --- manager/ytsync.go | 4 ++-- sdk/api.go | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manager/ytsync.go b/manager/ytsync.go index 307f6f0..026a09b 100644 --- a/manager/ytsync.go +++ b/manager/ytsync.go @@ -484,7 +484,7 @@ func (s *Sync) updateRemoteDB(claims []jsonrpc.Claim) (total, fixed, removed int } } removeCount := 0 - if s.Manager.removeDBUnpublished { + if s.Manager.removeDBUnpublished && len(idsToRemove) > 0 { err := s.Manager.apiConfig.DeleteVideos(idsToRemove) if err != nil { return count, fixed, 0, err @@ -539,7 +539,7 @@ func (s *Sync) doSync() error { pubsOnWallet, nFixed, nRemoved, err := s.updateRemoteDB(allClaims) if err != nil { - return errors.Prefix("error counting claims", err) + return errors.Prefix("error updating remote database", err) } if nFixed > 0 || nRemoved > 0 { err := s.setStatusSyncing() diff --git a/sdk/api.go b/sdk/api.go index b243d2f..ec861c5 100644 --- a/sdk/api.go +++ b/sdk/api.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "github.com/lbryio/lbry.go/extras/api" "github.com/lbryio/lbry.go/extras/errors" "github.com/lbryio/lbry.go/extras/null" @@ -170,31 +169,32 @@ const ( ) func (a *APIConfig) DeleteVideos(videos []string) error { - endpoint := a.ApiURL + "/yt/video_status" + endpoint := a.ApiURL + "/yt/video_delete" videoIDs := strings.Join(videos, ",") vals := url.Values{ - "video_id": {videoIDs}, + "video_ids": {videoIDs}, "auth_token": {a.ApiToken}, } res, _ := http.PostForm(endpoint, vals) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) - response := api.Response{} - err := json.Unmarshal(body, response) + var response struct { + Success bool `json:"success"` + Error null.String `json:"error"` + Data null.String `json:"data"` + } + err := json.Unmarshal(body, &response) if err != nil { return errors.Err(err) } - if response.Error != nil { - return errors.Err(response.Error) + if !response.Error.IsNull() { + return errors.Err(response.Error.String) } - str, ok := response.Data.(string) - if !ok { - return errors.Err("%x", response.Data) + + if !response.Data.IsNull() && response.Data.String == "ok" { + return nil } - if str != "ok" { - return errors.Err(str) - } - return nil + return errors.Err("invalid API response. Status code: %d", res.StatusCode) } func (a *APIConfig) MarkVideoStatus(channelID string, videoID string, status string, claimID string, claimName string, failureReason string, size *int64, metadataVersion uint) error {