From 4851b9bf7c76db8bc0bd8fb5a608c012cc511b96 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Thu, 24 Aug 2023 19:51:44 +0200 Subject: [PATCH] fix(post): sort media files by name --- lib/bdfr_browser/http/plug.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/bdfr_browser/http/plug.ex b/lib/bdfr_browser/http/plug.ex index 33dc87b..c830321 100644 --- a/lib/bdfr_browser/http/plug.ex +++ b/lib/bdfr_browser/http/plug.ex @@ -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)