Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

api: fix or not fix the aspect ratio #37

@egabancho

Description

@egabancho

This commit 1fac6ee attempted to fix the problem with the aspect ratios which are not in the configuration.

I would either:

  • Create a decorator which we can use in every single function which gets display_aspect_ratio as parameter and it will change it to the correct one if needed.
    Take it with a grain of salt, probably we need to order correctly the function arguments to make it work or use the display_aspect_ratio always as a keyword argument.
def fix_aspect_ratio(f):
    def wrapper(*args, **kwargs):
        kwargs['display_aspect_ratio'] = get_closest_aspect_ratio()
        return f(*args, **kwargs)
    return wrapper
  • let if fail if we pass the wrong aspect ratio and make the "client", in our case webhooks/tasks.py, handle the error (or maybe send already the correct aspect ratio).

  • or use the function we have already and call it every time we have an aspect ratio related calculation.

--

There is also a problem with the commit itself, this is how it should be otherwise it will return the wrong type of object

-        raise InvalidAspectRatioError(display_aspect_ratio)
+        if max_height and max_width:
+            display_aspect_ratio = get_closest_aspect_ratio(max_height, max_width)
+            aspect_ratio = current_app.config['CDS_SORENSON_PRESETS'][
+                display_aspect_ratio]
+        else:
+            raise InvalidAspectRatioError(display_aspect_ratio)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions