Skip to content

Commit

Permalink
Guard against invalid values for :sort option in `MediaLibrary.list…
Browse files Browse the repository at this point in the history
…_assets/2`
  • Loading branch information
leandrocp committed Sep 4, 2024
1 parent 626a844 commit e8e6d97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/beacon/media_library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit e8e6d97

Please sign in to comment.