From e8e6d974f583e21d05d674942cef96bd7f6bd013 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Wed, 4 Sep 2024 17:03:53 -0400 Subject: [PATCH] Guard against invalid values for `:sort` option in `MediaLibrary.list_assets/2` --- CHANGELOG.md | 3 +++ lib/beacon/media_library.ex | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28be7d21..13816d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Breaking Changes * Require minimum Gettext v0.26 to use the new backend module +### Fixes + * [Media Library] Guard against invalid values for `:sort` option in `MediaLibrary.list_assets/2` + ## 0.1.0-rc.1 (2024-08-27) ### Enhancements diff --git a/lib/beacon/media_library.ex b/lib/beacon/media_library.ex index 9cd451f8..0aa87118 100644 --- a/lib/beacon/media_library.ex +++ b/lib/beacon/media_library.ex @@ -238,6 +238,7 @@ defmodule Beacon.MediaLibrary do * `:query` - search assets by file name. Defaults to `nil`, doesn't filter query. * `:preloads` - a list of preloads to load. Defaults to `[:thumbnail]`. * `:sort` - column in which the result will be ordered by. Defaults to `:file_name`. + Allowed values: `:file_name`, `:media_type`. """ @doc type: :assets @@ -247,7 +248,8 @@ defmodule Beacon.MediaLibrary do page = Keyword.get(opts, :page, 1) search = Keyword.get(opts, :query) preloads = Keyword.get(opts, :preloads, [:thumbnail]) - sort = Keyword.get(opts, :sort, :file_name) + sort = Keyword.get(opts, :sort) + sort = if sort in [:file_name, :media_type], do: sort, else: :file_name site |> query_list_assets_base()