Skip to content

Commit 71c1573

Browse files
committed
mix format + 20G
1 parent 0b9933e commit 71c1573

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

config/runtime.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if config_env() == :prod do
5252
port = String.to_integer(System.get_env("PORT") || "4000")
5353

5454
config :uploads, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
55-
55+
5656
config :uploads, :uploads_path, "/app/uploads"
5757

5858
config :uploads, UploadsWeb.Endpoint,

lib/uploads_web/live/upload_live.ex

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ defmodule UploadsWeb.UploadLive do
33
use UploadsWeb, :live_view
44

55
@accept ~w(.zip .jpg .jpeg .png)
6+
@max_file_size 20_000_000_000
67

78
def root do
89
case Application.get_env(:uploads, :uploads_path) do
910
nil -> Application.app_dir(:uploads, "priv/static/uploads")
1011
path -> path
1112
end
1213
end
13-
14+
1415
@impl true
1516
def mount(_params, _session, socket) do
1617
{:ok,
1718
socket
1819
|> assign(:done, false)
1920
|> assign(:form, to_form(%{}))
2021
|> assign(:uploaded_files, list_uploads!())
21-
|> allow_upload(:archive, accept: @accept, max_entries: 4)}
22+
|> allow_upload(:archive, accept: @accept, max_entries: 4, max_file_size: @max_file_size)}
2223
end
2324

2425
defp list_uploads! do
25-
root() |> File.ls!() |> Enum.map(fn filename ->
26+
root()
27+
|> File.ls!()
28+
|> Enum.map(fn filename ->
2629
root() |> Path.join(filename) |> to_upload()
2730
end)
2831
end
@@ -66,11 +69,13 @@ defmodule UploadsWeb.UploadLive do
6669
def render(assigns) do
6770
~H"""
6871
<div :if={@done}>
69-
<h1 class="w-full text-center text-3xl font-bold text-emerald-600 absolute top-[40%] left-0">Done!</h1>
72+
<h1 class="w-full text-center text-3xl font-bold text-emerald-600 absolute top-[40%] left-0">
73+
Done!
74+
</h1>
7075
</div>
7176
<.form :if={not @done} for={@form} phx-submit="save" phx-change="validate">
7277
<h2 class="font-bold text-2xl">Upload new</h2>
73-
78+
7479
<div class="my-3">
7580
<.live_file_input upload={@uploads.archive} />
7681
</div>
@@ -80,12 +85,21 @@ defmodule UploadsWeb.UploadLive do
8085
<div :for={entry <- @uploads.archive.entries}>
8186
<div class="flex gap-3 my-1">
8287
<progress value={entry.progress} max="100" class="flex-grow">{entry.progress}%</progress>
83-
<button type="button" phx-click="cancel" phx-value-ref={entry.ref} aria-label="cancel">&times;</button>
88+
<button type="button" phx-click="cancel" phx-value-ref={entry.ref} aria-label="cancel">
89+
&times;
90+
</button>
8491
</div>
85-
<p :for={err <- upload_errors(@uploads.archive, entry)} class="text-red-600 px-2 py-1 bg-red-100">{error_to_string(err)}</p>
92+
<p
93+
:for={err <- upload_errors(@uploads.archive, entry)}
94+
class="text-red-600 px-2 py-1 bg-red-100"
95+
>
96+
{error_to_string(err)}
97+
</p>
8698
</div>
8799
88-
<p :for={err <- upload_errors(@uploads.archive)} class="text-red-600 px-2 py-1 bg-red-100">{error_to_string(err)}</p>
100+
<p :for={err <- upload_errors(@uploads.archive)} class="text-red-600 px-2 py-1 bg-red-100">
101+
{error_to_string(err)}
102+
</p>
89103
</div>
90104
91105
<.button>Upload!</.button>
@@ -97,9 +111,15 @@ defmodule UploadsWeb.UploadLive do
97111
<img
98112
:for={u <- @uploaded_files}
99113
:if={is_nil(u.count)}
100-
src={u.src} class="aspect-square w-[200px] object-cover" />
114+
src={u.src}
115+
class="aspect-square w-[200px] object-cover"
116+
/>
101117
102-
<div :for={u <- @uploaded_files} :if={u.count} class="bg-gray-100 aspect-square w-[200px] shrink-0 flex flex-col justify-center items-center">
118+
<div
119+
:for={u <- @uploaded_files}
120+
:if={u.count}
121+
class="bg-gray-100 aspect-square w-[200px] shrink-0 flex flex-col justify-center items-center"
122+
>
103123
<p class="font-bold">{Path.basename(u.path)}</p>
104124
<p><span title={"#{u.size} bytes"}>{format_bytes(u.size)}</span>, {u.count} files</p>
105125
</div>
@@ -127,18 +147,21 @@ defmodule UploadsWeb.UploadLive do
127147
@units ["bytes", "kB", "MB", "GB", "TB", "PB"]
128148

129149
def format_bytes(atom) when is_atom(atom), do: "#{atom} bytes"
150+
130151
def format_bytes(bytes) when is_integer(bytes) and bytes >= 0 do
131152
format(bytes, 0)
132153
end
154+
133155
defp format(bytes, unit_index) when bytes < 1024 or unit_index == length(@units) - 1 do
134156
value = Float.round(bytes, 2)
135157
"#{value} #{@units |> Enum.at(unit_index)}"
136158
end
159+
137160
defp format(bytes, unit_index) do
138161
format(bytes / 1024, unit_index + 1)
139162
end
140163

141164
defp error_to_string(:too_large), do: "Too large"
142165
defp error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
143166
defp error_to_string(:too_many_files), do: "You have selected too many files"
144-
end
167+
end

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"},
1313
"floki": {:hex, :floki, "0.37.1", "d7aaee758c8a5b4a7495799a4260754fec5530d95b9c383c03b27359dea117cf", [:mix], [], "hexpm", "673d040cb594d31318d514590246b6dd587ed341d3b67e17c1c0eb8ce7ca6f04"},
1414
"gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"},
15-
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
15+
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
1616
"hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"},
1717
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
1818
"mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},

0 commit comments

Comments
 (0)