Fixed pagination parsing for non-numeric IDs
Mastodon API's pagination IDs are not guaranteed to be in a numeric format. This happens to be the case for the tootsuite implementation, but others use UUIDs or flake IDs for pagination. This also simplifies the code a bit and luckily shouldn't break backwards compatibility since they're already of type ID in the Pagination struct.pull/103/head
parent
f51571807d
commit
c09198f7c9
13
mastodon.go
13
mastodon.go
|
@ -14,7 +14,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -352,17 +351,7 @@ func getPaginationID(rawurl, key string) (ID, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
val := u.Query().Get(key)
|
return ID(u.Query().Get(key)), nil
|
||||||
if val == "" {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
id, err := strconv.ParseInt(val, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ID(fmt.Sprint(id)), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pagination) toValues() url.Values {
|
func (p *Pagination) toValues() url.Values {
|
||||||
|
|
|
@ -294,8 +294,8 @@ func TestNewPagination(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = newPagination(`<http://example.com?min_id=abc>; rel="prev"`)
|
_, err = newPagination(`<http://example.com?min_id=abc>; rel="prev"`)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Fatalf("should be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pg, err := newPagination(`<http://example.com?max_id=123>; rel="next", <http://example.com?since_id=789>; rel="prev"`)
|
pg, err := newPagination(`<http://example.com?max_id=123>; rel="next", <http://example.com?since_id=789>; rel="prev"`)
|
||||||
|
@ -317,8 +317,8 @@ func TestGetPaginationID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = getPaginationID("http://example.com?max_id=abc", "max_id")
|
_, err = getPaginationID("http://example.com?max_id=abc", "max_id")
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Fatalf("should be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := getPaginationID("http://example.com?max_id=123", "max_id")
|
id, err := getPaginationID("http://example.com?max_id=123", "max_id")
|
||||||
|
|
Loading…
Reference in New Issue