Add support for new SDK (0.37.*) and support for upgrading channels and claims to new metadata #28

Merged
nikooo777 merged 37 commits from metadata_upgrade into master 2019-06-13 20:14:14 +02:00
2 changed files with 16 additions and 16 deletions
Showing only changes of commit ccebab35da - Show all commits

View file

@ -484,7 +484,7 @@ func (s *Sync) updateRemoteDB(claims []jsonrpc.Claim) (total, fixed, removed int
} }
} }
removeCount := 0 removeCount := 0
if s.Manager.removeDBUnpublished { if s.Manager.removeDBUnpublished && len(idsToRemove) > 0 {
err := s.Manager.apiConfig.DeleteVideos(idsToRemove) err := s.Manager.apiConfig.DeleteVideos(idsToRemove)
if err != nil { if err != nil {
return count, fixed, 0, err return count, fixed, 0, err
@ -539,7 +539,7 @@ func (s *Sync) doSync() error {
pubsOnWallet, nFixed, nRemoved, err := s.updateRemoteDB(allClaims) pubsOnWallet, nFixed, nRemoved, err := s.updateRemoteDB(allClaims)
if err != nil { if err != nil {
return errors.Prefix("error counting claims", err) return errors.Prefix("error updating remote database", err)
} }
if nFixed > 0 || nRemoved > 0 { if nFixed > 0 || nRemoved > 0 {
err := s.setStatusSyncing() err := s.setStatusSyncing()

View file

@ -11,7 +11,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/lbryio/lbry.go/extras/api"
"github.com/lbryio/lbry.go/extras/errors" "github.com/lbryio/lbry.go/extras/errors"
"github.com/lbryio/lbry.go/extras/null" "github.com/lbryio/lbry.go/extras/null"
@ -170,32 +169,33 @@ const (
) )
func (a *APIConfig) DeleteVideos(videos []string) error { func (a *APIConfig) DeleteVideos(videos []string) error {
endpoint := a.ApiURL + "/yt/video_status" endpoint := a.ApiURL + "/yt/video_delete"
videoIDs := strings.Join(videos, ",") videoIDs := strings.Join(videos, ",")
vals := url.Values{ vals := url.Values{
"video_id": {videoIDs}, "video_ids": {videoIDs},
"auth_token": {a.ApiToken}, "auth_token": {a.ApiToken},
} }
res, _ := http.PostForm(endpoint, vals) res, _ := http.PostForm(endpoint, vals)
defer res.Body.Close() defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body) body, _ := ioutil.ReadAll(res.Body)
response := api.Response{} var response struct {
err := json.Unmarshal(body, response) Success bool `json:"success"`
Error null.String `json:"error"`
Data null.String `json:"data"`
}
err := json.Unmarshal(body, &response)
if err != nil { if err != nil {
return errors.Err(err) return errors.Err(err)
} }
if response.Error != nil { if !response.Error.IsNull() {
return errors.Err(response.Error) return errors.Err(response.Error.String)
}
str, ok := response.Data.(string)
if !ok {
return errors.Err("%x", response.Data)
}
if str != "ok" {
return errors.Err(str)
} }
if !response.Data.IsNull() && response.Data.String == "ok" {
return nil 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 { func (a *APIConfig) MarkVideoStatus(channelID string, videoID string, status string, claimID string, claimName string, failureReason string, size *int64, metadataVersion uint) error {
endpoint := a.ApiURL + "/yt/video_status" endpoint := a.ApiURL + "/yt/video_status"