Support adding description to media
This commit is contained in:
parent
83ca619c14
commit
ec097886d8
4 changed files with 33 additions and 16 deletions
|
@ -2,6 +2,7 @@
|
|||
date: TBA
|
||||
changes:
|
||||
- "Add `--scheduled-at` option to `toot post`, allows scheduling toots"
|
||||
- "Add `--description` option to `toot post`, for adding descriptions to media attachments (thanks @ansuz)"
|
||||
|
||||
0.27.0:
|
||||
date: 2020-06-15
|
||||
|
|
|
@ -217,10 +217,11 @@ def anon_tag_timeline_generator(instance, hashtag, local=False, limit=20):
|
|||
return _anon_timeline_generator(instance, path, params)
|
||||
|
||||
|
||||
def upload_media(app, user, file):
|
||||
return http.post(app, user, '/api/v1/media', files={
|
||||
'file': file
|
||||
}).json()
|
||||
def upload_media(app, user, file, description=None):
|
||||
return http.post(app, user, '/api/v1/media',
|
||||
data={'description': description},
|
||||
files={'file': file}
|
||||
).json()
|
||||
|
||||
|
||||
def search(app, user, query, resolve):
|
||||
|
|
|
@ -87,15 +87,20 @@ def post(app, user, args):
|
|||
if not args.text and not sys.stdin.isatty():
|
||||
args.text = sys.stdin.read().rstrip()
|
||||
|
||||
if args.media:
|
||||
media = [_do_upload(app, user, file) for file in args.media]
|
||||
media_ids = [m["id"] for m in media]
|
||||
else:
|
||||
media = None
|
||||
media_ids = None
|
||||
# Match media to corresponding description and upload
|
||||
media = args.media or []
|
||||
descriptions = args.description or []
|
||||
uploaded_media = []
|
||||
|
||||
if media and not args.text:
|
||||
args.text = "\n".join(m['text_url'] for m in media)
|
||||
for idx, file in enumerate(media):
|
||||
description = descriptions[idx].strip() if idx < len(descriptions) else None
|
||||
result = _do_upload(app, user, file, description)
|
||||
uploaded_media.append(result)
|
||||
|
||||
media_ids = [m["id"] for m in uploaded_media]
|
||||
|
||||
if uploaded_media and not args.text:
|
||||
args.text = "\n".join(m['text_url'] for m in uploaded_media)
|
||||
|
||||
if args.editor:
|
||||
args.text = editor_input(args.editor, args.text)
|
||||
|
@ -210,7 +215,7 @@ def activate(app, user, args):
|
|||
|
||||
|
||||
def upload(app, user, args):
|
||||
response = _do_upload(app, user, args.file)
|
||||
response = _do_upload(app, user, args.file, args.description)
|
||||
|
||||
msg = "Successfully uploaded media ID <yellow>{}</yellow>, type '<yellow>{}</yellow>'"
|
||||
|
||||
|
@ -226,9 +231,9 @@ def search(app, user, args):
|
|||
print_search_results(response)
|
||||
|
||||
|
||||
def _do_upload(app, user, file):
|
||||
def _do_upload(app, user, file, description):
|
||||
print_out("Uploading media: <green>{}</green>".format(file.name))
|
||||
return api.upload_media(app, user, file)
|
||||
return api.upload_media(app, user, file, description=description)
|
||||
|
||||
|
||||
def _find_account(app, user, account_name):
|
||||
|
|
|
@ -297,6 +297,12 @@ POST_COMMANDS = [
|
|||
"help": "path to the media file to attach (specify multiple "
|
||||
"times to attach up to 4 files)"
|
||||
}),
|
||||
(["-d", "--description"], {
|
||||
"action": "append",
|
||||
"type": str,
|
||||
"help": "plain-text description of the media for accessibility "
|
||||
"purposes, one per attached media"
|
||||
}),
|
||||
(["-v", "--visibility"], {
|
||||
"type": visibility,
|
||||
"default": "public",
|
||||
|
@ -341,7 +347,11 @@ POST_COMMANDS = [
|
|||
(["file"], {
|
||||
"help": "Path to the file to upload",
|
||||
"type": FileType('rb')
|
||||
})
|
||||
}),
|
||||
(["-d", "--description"], {
|
||||
"type": str,
|
||||
"help": "plain-text description of the media for accessibility purposes"
|
||||
}),
|
||||
],
|
||||
require_auth=True,
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue