fix issues with unicode claim names

fix issue with streams to abandon
This commit is contained in:
Niko Storni 2021-03-23 01:18:26 +01:00
parent 55577201a4
commit d53d0a1d52
6 changed files with 47 additions and 26 deletions

View file

@ -135,10 +135,11 @@ func (s *Sync) walletSetup() error {
} else if claimAddress == nil { } else if claimAddress == nil {
return errors.Err("could not get an address") return errors.Err("could not get an address")
} }
if s.DbChannelData.PublishAddress == "" || !s.shouldTransfer() { if s.DbChannelData.PublishAddress.Address == "" || !s.shouldTransfer() {
s.DbChannelData.PublishAddress = string(claimAddress.Items[0].Address) s.DbChannelData.PublishAddress.Address = string(claimAddress.Items[0].Address)
s.DbChannelData.PublishAddress.IsMine = true
} }
if s.DbChannelData.PublishAddress == "" { if s.DbChannelData.PublishAddress.Address == "" {
return errors.Err("found blank claim address") return errors.Err("found blank claim address")
} }

View file

@ -235,7 +235,7 @@ func transferVideos(s *Sync) error {
streamUpdateOptions := jsonrpc.StreamUpdateOptions{ streamUpdateOptions := jsonrpc.StreamUpdateOptions{
StreamCreateOptions: &jsonrpc.StreamCreateOptions{ StreamCreateOptions: &jsonrpc.StreamCreateOptions{
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
ClaimAddress: &s.DbChannelData.PublishAddress, ClaimAddress: &s.DbChannelData.PublishAddress.Address,
FundingAccountIDs: []string{ FundingAccountIDs: []string{
account, account,
}, },
@ -335,7 +335,7 @@ func transferChannel(s *Sync) error {
Bid: util.PtrToString(fmt.Sprintf("%.6f", channelClaimAmount-0.005)), Bid: util.PtrToString(fmt.Sprintf("%.6f", channelClaimAmount-0.005)),
ChannelCreateOptions: jsonrpc.ChannelCreateOptions{ ChannelCreateOptions: jsonrpc.ChannelCreateOptions{
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
ClaimAddress: &s.DbChannelData.PublishAddress, ClaimAddress: &s.DbChannelData.PublishAddress.Address,
}, },
}, },
} }

View file

@ -260,7 +260,7 @@ func deleteSyncFolder(videoDirectory string) {
} }
func (s *Sync) shouldTransfer() bool { func (s *Sync) shouldTransfer() bool {
return s.DbChannelData.TransferState >= 1 && s.DbChannelData.PublishAddress != "" && !s.Manager.CliFlags.DisableTransfers && s.DbChannelData.TransferState != 3 return s.DbChannelData.TransferState >= 1 && s.DbChannelData.PublishAddress.Address != "" && !s.Manager.CliFlags.DisableTransfers && s.DbChannelData.TransferState != 3
} }
func (s *Sync) setChannelTerminationStatus(e *error) { func (s *Sync) setChannelTerminationStatus(e *error) {
@ -417,7 +417,8 @@ func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
claimToAbandon = cl claimToAbandon = cl
videoIDs[videoID] = c videoIDs[videoID] = c
} }
if claimToAbandon.Address != s.DbChannelData.PublishAddress && !s.syncedVideos[videoID].Transferred { //it's likely that all we need is s.DbChannelData.PublishAddress.IsMine but better be safe than sorry I guess
if (claimToAbandon.Address != s.DbChannelData.PublishAddress.Address || s.DbChannelData.PublishAddress.IsMine) && !s.syncedVideos[videoID].Transferred {
log.Debugf("abandoning %+v", claimToAbandon) log.Debugf("abandoning %+v", claimToAbandon)
_, err := s.daemon.StreamAbandon(claimToAbandon.Txid, claimToAbandon.Nout, nil, true) _, err := s.daemon.StreamAbandon(claimToAbandon.Txid, claimToAbandon.Nout, nil, true)
if err != nil { if err != nil {
@ -425,7 +426,7 @@ func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
} }
abandonedClaims = true abandonedClaims = true
} else { } else {
log.Debugf("lbrynet stream abandon --txid=%s --nout=%d", claimToAbandon.Txid, claimToAbandon.Nout) log.Debugf("claim is not ours. Have the user run this: lbrynet stream abandon --txid=%s --nout=%d", claimToAbandon.Txid, claimToAbandon.Nout)
} }
} }
return abandonedClaims, nil return abandonedClaims, nil
@ -975,7 +976,7 @@ func (s *Sync) processVideo(v ytapi.Video) (err error) {
return err return err
} }
sp := sources.SyncParams{ sp := sources.SyncParams{
ClaimAddress: s.DbChannelData.PublishAddress, ClaimAddress: s.DbChannelData.PublishAddress.Address,
Amount: publishAmount, Amount: publishAmount,
ChannelID: s.DbChannelData.ChannelClaimID, ChannelID: s.DbChannelData.ChannelClaimID,
MaxVideoSize: s.DbChannelData.SizeLimit, MaxVideoSize: s.DbChannelData.SizeLimit,

View file

@ -10,7 +10,7 @@ import (
"sync" "sync"
) )
var claimNameRegexp = regexp.MustCompile(`[=&#:$@%?;\\"/<>%{}|^~\x60[\]\s]`) var claimNameRegexp = regexp.MustCompile(`[=&#:$@%?;\\"/<>%{}|^~\x60[\]\s]`)
type Namer struct { type Namer struct {
mu *sync.Mutex mu *sync.Mutex
@ -82,7 +82,7 @@ func getClaimNameFromTitle(title string, attempt int) string {
tmpName := name + "-" + chunk tmpName := name + "-" + chunk
if len(tmpName) > maxLen { if len(tmpName) > maxLen {
if len(name) < 20 { if len(name) < 20 {
name = tmpName[:maxLen] name = truncateUnicode(tmpName, maxLen-len(name))
} }
break break
} }

View file

@ -12,15 +12,17 @@ func Test_getClaimNameFromTitle(t *testing.T) {
name = getClaimNameFromTitle("SADB - \"A Weak Woman With a Strong Hood\"", 0) name = getClaimNameFromTitle("SADB - \"A Weak Woman With a Strong Hood\"", 0)
assert.Equal(t, "sadb-a-weak-woman-with-a-strong-hood", name) assert.Equal(t, "sadb-a-weak-woman-with-a-strong-hood", name)
name = getClaimNameFromTitle("錢包整理術 5 Tips、哪種錢包最NG有錢人默默在做的「錢包整理術」 ft.@SHIN LI", 0) name = getClaimNameFromTitle("錢包整理術 5 Tips、哪種錢包最NG有錢人默默在做的「錢包整理術」 ft.@SHIN LI", 0)
assert.Equal(t, "錢包整理術-5-tips、哪種錢包最", name) assert.Equal(t, "錢包整理術-5-tips-哪種錢包最ng", name)
name = getClaimNameFromTitle("اسرع-طريقة-لتختيم", 0) name = getClaimNameFromTitle("اسرع-طريقة-لتختيم", 0)
assert.Equal(t, "اسرع-طريقة-لتختيم", name) assert.Equal(t, "اسرع-طريقة-لتختيم", name)
name = getClaimNameFromTitle("شكرا على 380 مشترك😍😍😍😍 لي يريد دعم ادا وصلنا المقطع 40 لايك وراح ادعم قناتين", 0) name = getClaimNameFromTitle("شكرا على 380 مشترك😍😍😍😍 لي يريد دعم ادا وصلنا المقطع 40 لايك وراح ادعم قناتين", 0)
assert.Equal(t, "شكرا-على-380-مشترك😍😍\xf0\x9f", name) assert.Equal(t, "شكرا-على-380-مشترك😍😍😍", name)
name = getClaimNameFromTitle("test-@", 0) name = getClaimNameFromTitle("test-@", 0)
assert.Equal(t, "test", name) assert.Equal(t, "test", name)
name = getClaimNameFromTitle("『あなたはただの空の殻でした』", 0) name = getClaimNameFromTitle("『あなたはただの空の殻でした』", 0)
assert.Equal(t, "『あなたはただの空の殻でした』", name) assert.Equal(t, "『あなたはただの空の殻でした』", name)
name = getClaimNameFromTitle("精靈樂章-這樣的夥伴沒問題嗎 幽暗隕石坑(夢魘) 王有無敵狀態...要會閃不然會被秒(無課)", 2)
assert.Equal(t, "精靈樂章-這樣的夥伴沒問題嗎-2", name)
name = getClaimNameFromTitle("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 50) name = getClaimNameFromTitle("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 50)
assert.Equal(t, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-50", name) assert.Equal(t, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-50", name)
} }

View file

@ -1,10 +1,12 @@
package shared package shared
import ( import (
"encoding/json"
"time" "time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/lbryio/lbry.go/v2/extras/errors"
) )
type Fee struct { type Fee struct {
@ -20,7 +22,7 @@ type YoutubeChannel struct {
Fee *Fee `json:"fee"` Fee *Fee `json:"fee"`
ChannelClaimID string `json:"channel_claim_id"` ChannelClaimID string `json:"channel_claim_id"`
TransferState int `json:"transfer_state"` TransferState int `json:"transfer_state"`
PublishAddress string `json:"publish_address"` PublishAddress PublishAddress `json:"publish_address"`
PublicKey string `json:"public_key"` PublicKey string `json:"public_key"`
LengthLimit int `json:"length_limit"` LengthLimit int `json:"length_limit"`
SizeLimit int `json:"size_limit"` SizeLimit int `json:"size_limit"`
@ -28,6 +30,21 @@ type YoutubeChannel struct {
WipeDB bool `json:"wipe_db"` WipeDB bool `json:"wipe_db"`
} }
type PublishAddress struct {
Address string `json:"address"`
IsMine bool `json:"is_mine"`
}
func (p *PublishAddress) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return errors.Err(err)
}
p.Address = s
p.IsMine = false
return nil
}
var NeverRetryFailures = []string{ var NeverRetryFailures = []string{
"Error extracting sts from embedded url response", "Error extracting sts from embedded url response",
"Unable to extract signature tokens", "Unable to extract signature tokens",