mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 04:39:21 +02:00
true remote timeline
This commit is contained in:
parent
fa5eaa4442
commit
3762ccfb83
|
@ -8,6 +8,9 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type StatusPleroma struct {
|
||||
|
@ -224,6 +227,51 @@ func (c *Client) GetTimelineHome(ctx context.Context, pg *Pagination) ([]*Status
|
|||
return statuses, nil
|
||||
}
|
||||
|
||||
type RemoteTimelineInstance struct {
|
||||
http.Client
|
||||
}
|
||||
|
||||
// TrueRemoteTimeline get public timeline from remote Mastodon API compatible instance directly
|
||||
func (c *Client) TrueRemoteTimeline(ctx context.Context, instance string, pg *Pagination) ([]*Status, error) {
|
||||
var httpclient RemoteTimelineInstance
|
||||
var publicstatuses []*Status
|
||||
params := url.Values{}
|
||||
params.Set("local", "true")
|
||||
if pg != nil {
|
||||
params = pg.setValues(params)
|
||||
}
|
||||
u, err := url.Parse("https://" + instance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.Path = path.Join(u.Path, "/api/v1/timelines/public")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), strings.NewReader(params.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp, err := httpclient.Do(req)
|
||||
fmt.Println(req)
|
||||
fmt.Println(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, parseAPIError("bad request", resp)
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&publicstatuses)
|
||||
fmt.Println(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicstatuses, nil
|
||||
}
|
||||
|
||||
// GetTimelinePublic return statuses from public timeline.
|
||||
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool, instance string, pg *Pagination) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
|
|
|
@ -149,12 +149,20 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
|
|||
title = "Local Timeline"
|
||||
case "remote":
|
||||
if len(instance) > 0 {
|
||||
statuses, err = c.GetTimelinePublic(c.ctx, false, instance, &pg)
|
||||
statuses, err = c.GetTimelinePublic(c.ctx, true, instance, &pg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
title = "Remote Timeline"
|
||||
case "tremote":
|
||||
if len(instance) > 0 {
|
||||
statuses, err = c.TrueRemoteTimeline(c.ctx, instance, &pg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
title = "True Remote Timeline"
|
||||
case "twkn":
|
||||
statuses, err = c.GetTimelinePublic(c.ctx, false, "", &pg)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue