mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Fix Redis storage
This commit is contained in:
@ -22,4 +22,8 @@
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mxpv/podcast"
|
||||
branch = "master"
|
||||
branch = "master"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/speps/go-hashids"
|
||||
revision = "c6ced3330f133cec79e144fb11b2e4c5154059ae"
|
@ -19,42 +19,6 @@ type RedisStorage struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func (r *RedisStorage) makeURL(m map[string]string) (string, error) {
|
||||
provider := m["provider"]
|
||||
linkType := m["type"]
|
||||
id := m["id"]
|
||||
|
||||
if provider == "" || linkType == "" || id == "" {
|
||||
return "", errors.New("failed to query URL data from storage")
|
||||
}
|
||||
|
||||
url := ""
|
||||
|
||||
if strings.EqualFold(provider, "youtube") {
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
url = "https://youtube.com/channel/" + id
|
||||
} else if strings.EqualFold(linkType, "playlist") {
|
||||
url = "https://youtube.com/playlist?list=" + id
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
url = "https://youtube.com/user/" + id
|
||||
}
|
||||
} else if strings.EqualFold(provider, "vimeo") {
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
url = "https://vimeo.com/channels/" + id
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
url = "https://vimeo.com/" + id
|
||||
} else if strings.EqualFold(linkType, "group") {
|
||||
url = "https://vimeo.com/groups/" + id
|
||||
}
|
||||
}
|
||||
|
||||
if url == "" {
|
||||
return "", fmt.Errorf("failed to query URL (provider: %s, type: %s, id: %s)", provider, linkType, id)
|
||||
}
|
||||
|
||||
return url, nil
|
||||
}
|
||||
|
||||
func (r *RedisStorage) parsePageSize(m map[string]string) (int, error) {
|
||||
str, ok := m["pagesize"]
|
||||
if !ok {
|
||||
@ -123,12 +87,47 @@ func (r *RedisStorage) GetFeed(hashId string) (*api.Feed, error) {
|
||||
return feed, nil
|
||||
}
|
||||
|
||||
// Construct URL data
|
||||
url, err := r.makeURL(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Unpack provider and link type
|
||||
provider := m["provider"]
|
||||
linkType := m["type"]
|
||||
if strings.EqualFold(provider, "youtube") {
|
||||
feed.Provider = api.Youtube
|
||||
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
feed.LinkType = api.Channel
|
||||
} else if strings.EqualFold(linkType, "playlist") {
|
||||
feed.LinkType = api.Playlist
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
feed.LinkType = api.User
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported yt link type %s", linkType)
|
||||
}
|
||||
|
||||
} else if strings.EqualFold(provider, "vimeo") {
|
||||
feed.Provider = api.Vimeo
|
||||
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
feed.LinkType = api.Channel
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
feed.LinkType = api.User
|
||||
} else if strings.EqualFold(linkType, "group") {
|
||||
feed.LinkType = api.Group
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported vimeo link type %s", linkType)
|
||||
}
|
||||
|
||||
} else {
|
||||
return nil, errors.New("unsupported provider")
|
||||
}
|
||||
|
||||
// Unpack item id
|
||||
id, ok := m["id"]
|
||||
if !ok || id == "" {
|
||||
return nil, errors.New("failed to unpack item id")
|
||||
}
|
||||
|
||||
feed.ItemId = id
|
||||
|
||||
// Fetch user id
|
||||
patreonId, ok := m["patreonid"]
|
||||
if ok {
|
||||
|
@ -41,7 +41,9 @@ func TestRedisStorage_CreateFeed(t *testing.T) {
|
||||
Id: 123,
|
||||
HashId: hashId,
|
||||
UserId: "321",
|
||||
URL: "https://youtube.com/123",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
ItemId: "123",
|
||||
PageSize: 45,
|
||||
Quality: api.LowQuality,
|
||||
Format: api.AudioFormat,
|
||||
@ -55,7 +57,9 @@ func TestRedisStorage_CreateFeed(t *testing.T) {
|
||||
require.Equal(t, int64(123), feed.Id)
|
||||
require.Equal(t, hashId, feed.HashId)
|
||||
require.Equal(t, "321", feed.UserId)
|
||||
require.Equal(t, "https://youtube.com/123", feed.URL)
|
||||
require.Equal(t, api.Youtube, feed.Provider)
|
||||
require.Equal(t, api.Channel, feed.LinkType)
|
||||
require.Equal(t, "123", feed.ItemId)
|
||||
require.Equal(t, 45, feed.PageSize)
|
||||
require.Equal(t, api.LowQuality, feed.Quality)
|
||||
require.Equal(t, api.AudioFormat, feed.Format)
|
||||
|
Reference in New Issue
Block a user