mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-29 04:35:54 -04:00
Use authorized get to fetch public and tag timelines
Some servers require authorization for viewing "public" timelines, and since currently toot always requires auth for this it's not required to support anon access to timelines. fixes #168
This commit is contained in:
parent
ad96143ee0
commit
3b5769acc0
@ -3,6 +3,11 @@ Changelog
|
|||||||
|
|
||||||
<!-- Do not edit. This file is automatically generated from changelog.yaml.-->
|
<!-- Do not edit. This file is automatically generated from changelog.yaml.-->
|
||||||
|
|
||||||
|
**0.27.0 (TBD)**
|
||||||
|
|
||||||
|
* Fix access to public and tag timelines when on private mastodon instances
|
||||||
|
(#168)
|
||||||
|
|
||||||
**0.26.0 (2020-04-15)**
|
**0.26.0 (2020-04-15)**
|
||||||
|
|
||||||
* Fix datetime parsing on Python 3.5 (#162)
|
* Fix datetime parsing on Python 3.5 (#162)
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
0.27.0:
|
||||||
|
date: "TBD"
|
||||||
|
changes:
|
||||||
|
- "Fix access to public and tag timelines when on private mastodon instances (#168)"
|
||||||
|
|
||||||
0.26.0:
|
0.26.0:
|
||||||
date: 2020-04-15
|
date: 2020-04-15
|
||||||
changes:
|
changes:
|
||||||
|
36
toot/api.py
36
toot/api.py
@ -173,6 +173,28 @@ def _timeline_generator(app, user, path, params=None):
|
|||||||
path = _get_next_path(response.headers)
|
path = _get_next_path(response.headers)
|
||||||
|
|
||||||
|
|
||||||
|
def home_timeline_generator(app, user, limit=20):
|
||||||
|
path = '/api/v1/timelines/home?limit={}'.format(limit)
|
||||||
|
return _timeline_generator(app, user, path)
|
||||||
|
|
||||||
|
|
||||||
|
def public_timeline_generator(app, user, local=False, limit=20):
|
||||||
|
path = '/api/v1/timelines/public'
|
||||||
|
params = {'local': str_bool(local), 'limit': limit}
|
||||||
|
return _timeline_generator(app, user, path, params)
|
||||||
|
|
||||||
|
|
||||||
|
def tag_timeline_generator(app, user, hashtag, local=False, limit=20):
|
||||||
|
path = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
|
||||||
|
params = {'local': str_bool(local), 'limit': limit}
|
||||||
|
return _timeline_generator(app, user, path, params)
|
||||||
|
|
||||||
|
|
||||||
|
def timeline_list_generator(app, user, list_id, limit=20):
|
||||||
|
path = '/api/v1/timelines/list/{}'.format(list_id)
|
||||||
|
return _timeline_generator(app, user, path, {'limit': limit})
|
||||||
|
|
||||||
|
|
||||||
def _anon_timeline_generator(instance, path, params=None):
|
def _anon_timeline_generator(instance, path, params=None):
|
||||||
while path:
|
while path:
|
||||||
url = "https://{}{}".format(instance, path)
|
url = "https://{}{}".format(instance, path)
|
||||||
@ -181,28 +203,18 @@ def _anon_timeline_generator(instance, path, params=None):
|
|||||||
path = _get_next_path(response.headers)
|
path = _get_next_path(response.headers)
|
||||||
|
|
||||||
|
|
||||||
def home_timeline_generator(app, user, limit=20):
|
def anon_public_timeline_generator(instance, local=False, limit=20):
|
||||||
path = '/api/v1/timelines/home?limit={}'.format(limit)
|
|
||||||
return _timeline_generator(app, user, path)
|
|
||||||
|
|
||||||
|
|
||||||
def public_timeline_generator(instance, local=False, limit=20):
|
|
||||||
path = '/api/v1/timelines/public'
|
path = '/api/v1/timelines/public'
|
||||||
params = {'local': str_bool(local), 'limit': limit}
|
params = {'local': str_bool(local), 'limit': limit}
|
||||||
return _anon_timeline_generator(instance, path, params)
|
return _anon_timeline_generator(instance, path, params)
|
||||||
|
|
||||||
|
|
||||||
def tag_timeline_generator(instance, hashtag, local=False, limit=20):
|
def anon_tag_timeline_generator(instance, hashtag, local=False, limit=20):
|
||||||
path = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
|
path = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
|
||||||
params = {'local': str_bool(local), 'limit': limit}
|
params = {'local': str_bool(local), 'limit': limit}
|
||||||
return _anon_timeline_generator(instance, path, params)
|
return _anon_timeline_generator(instance, path, params)
|
||||||
|
|
||||||
|
|
||||||
def timeline_list_generator(app, user, list_id, limit=20):
|
|
||||||
path = '/api/v1/timelines/list/{}'.format(list_id)
|
|
||||||
return _timeline_generator(app, user, path, {'limit': limit})
|
|
||||||
|
|
||||||
|
|
||||||
def upload_media(app, user, file):
|
def upload_media(app, user, file):
|
||||||
return http.post(app, user, '/api/v1/media', files={
|
return http.post(app, user, '/api/v1/media', files={
|
||||||
'file': file
|
'file': file
|
||||||
|
@ -22,11 +22,9 @@ def get_timeline_generator(app, user, args):
|
|||||||
raise ConsoleError("The --instance option is only valid alongside --public or --tag.")
|
raise ConsoleError("The --instance option is only valid alongside --public or --tag.")
|
||||||
|
|
||||||
if args.public:
|
if args.public:
|
||||||
instance = args.instance or app.instance
|
return api.public_timeline_generator(app, user, local=args.local, limit=args.count)
|
||||||
return api.public_timeline_generator(instance, local=args.local, limit=args.count)
|
|
||||||
elif args.tag:
|
elif args.tag:
|
||||||
instance = args.instance or app.instance
|
return api.tag_timeline_generator(app, user, args.tag, local=args.local, limit=args.count)
|
||||||
return api.tag_timeline_generator(instance, args.tag, local=args.local, limit=args.count)
|
|
||||||
elif args.list:
|
elif args.list:
|
||||||
return api.timeline_list_generator(app, user, args.list, limit=args.count)
|
return api.timeline_list_generator(app, user, args.list, limit=args.count)
|
||||||
else:
|
else:
|
||||||
|
@ -358,13 +358,13 @@ class TUI(urwid.Frame):
|
|||||||
|
|
||||||
def goto_public_timeline(self, local):
|
def goto_public_timeline(self, local):
|
||||||
self.timeline_generator = api.public_timeline_generator(
|
self.timeline_generator = api.public_timeline_generator(
|
||||||
self.app.instance, local=local, limit=40)
|
self.app, self.user, local=local, limit=40)
|
||||||
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
||||||
promise.add_done_callback(lambda *args: self.close_overlay())
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
def goto_tag_timeline(self, tag, local):
|
def goto_tag_timeline(self, tag, local):
|
||||||
self.timeline_generator = api.tag_timeline_generator(
|
self.timeline_generator = api.tag_timeline_generator(
|
||||||
self.app.instance, tag, local=local, limit=40)
|
self.app, self.user, tag, local=local, limit=40)
|
||||||
promise = self.async_load_timeline(is_initial=True, timeline_name="#{}".format(tag))
|
promise = self.async_load_timeline(is_initial=True, timeline_name="#{}".format(tag))
|
||||||
promise.add_done_callback(lambda *args: self.close_overlay())
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user