fix(post): sort media files by name

This commit is contained in:
Daniel Kempkens 2023-08-24 19:51:44 +02:00
parent e635454b2e
commit 4851b9bf7c
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM

View file

@ -208,11 +208,19 @@ defmodule BdfrBrowser.HTTP.Plug do
post_vid = "#{post}*.{mp4,MP4}"
%{
images: [post_dir, post_img] |> Path.join() |> Path.wildcard() |> Enum.map(&media_path/1),
videos: [post_dir, post_vid] |> Path.join() |> Path.wildcard() |> Enum.map(&media_path/1)
images: post_media_for_type(post_dir, post_img),
videos: post_media_for_type(post_dir, post_vid)
}
end
defp post_media_for_type(post_dir, post_type) do
[post_dir, post_type]
|> Path.join()
|> Path.wildcard()
|> Enum.map(&media_path/1)
|> Enum.sort()
end
defp media_path(full_path) do
base_directory = Application.fetch_env!(:bdfr_browser, :base_directory)