server/posts/upload: edit default flag behavior

The 'loop' flag will be auto-selected by default on video posts if
the flags parameter is undefined when creating a new post.
This commit is contained in:
Shyam Sunder 2020-03-21 18:25:54 -04:00
parent c60ec22b92
commit 65202189e1
2 changed files with 8 additions and 8 deletions

View file

@ -54,7 +54,9 @@ def create_post(
source = ctx.get_param_as_string('contentUrl', default='') source = ctx.get_param_as_string('contentUrl', default='')
relations = ctx.get_param_as_int_list('relations', default=[]) relations = ctx.get_param_as_int_list('relations', default=[])
notes = ctx.get_param_as_list('notes', default=[]) notes = ctx.get_param_as_list('notes', default=[])
flags = ctx.get_param_as_string_list('flags', default=[]) flags = ctx.get_param_as_string_list(
'flags',
default=posts.get_default_flags(content))
post, new_tags = posts.create_post( post, new_tags = posts.create_post(
content, tag_names, None if anonymous else ctx.user) content, tag_names, None if anonymous else ctx.user)
@ -65,7 +67,6 @@ def create_post(
posts.update_post_relations(post, relations) posts.update_post_relations(post, relations)
posts.update_post_notes(post, notes) posts.update_post_notes(post, notes)
posts.update_post_flags(post, flags) posts.update_post_flags(post, flags)
posts.test_sound(post, content)
if ctx.has_file('thumbnail'): if ctx.has_file('thumbnail'):
posts.update_post_thumbnail(post, ctx.get_file('thumbnail')) posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
ctx.session.add(post) ctx.session.add(post)

View file

@ -467,15 +467,14 @@ def generate_alternate_formats(post: model.Post, content: bytes) \
return new_posts return new_posts
def test_sound(post: model.Post, content: bytes) -> None: def get_default_flags(content: bytes) -> List[str]:
assert post
assert content assert content
ret = []
if mime.is_video(mime.get_mime_type(content)): if mime.is_video(mime.get_mime_type(content)):
ret.append(model.Post.FLAG_LOOP)
if images.Image(content).check_for_sound(): if images.Image(content).check_for_sound():
flags = post.flags ret.append(model.Post.FLAG_SOUND)
if model.Post.FLAG_SOUND not in flags: return ret
flags.append(model.Post.FLAG_SOUND)
update_post_flags(post, flags)
def purge_post_signature(post: model.Post) -> None: def purge_post_signature(post: model.Post) -> None: