From 028d83b9cc707d8dd8e19f0348c5819192b78213 Mon Sep 17 00:00:00 2001 From: qdust41 Date: Tue, 31 Mar 2026 13:12:11 -0400 Subject: [PATCH] Had to swap to minio to let it act as a cdn. Working file uploads. --- assets/js/index.tsx | 2 +- config/config.exs | 2 +- config/dev.exs | 12 +++++------- lib/mixer/posts/media_uploader.ex | 2 +- lib/mixer_web/controllers/page_controller.ex | 8 +++++++- lib/mixer_web/controllers/page_html/index.html.heex | 3 ++- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/assets/js/index.tsx b/assets/js/index.tsx index dcee6cb..208a891 100644 --- a/assets/js/index.tsx +++ b/assets/js/index.tsx @@ -37,7 +37,7 @@ function timeAgo(): string { function getAssetHost(): string { const appEl = document.getElementById("app"); - return appEl?.dataset.assetHost ?? "http://localhost:3901"; + return appEl?.dataset.assetHost ?? "http://localhost:9000"; } // ── Components ───────────────────────────────────────────────────────────────── diff --git a/config/config.exs b/config/config.exs index bfffe79..1c706b9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -10,7 +10,7 @@ import Config config :waffle, storage: Waffle.Storage.S3, bucket: "mixer-bucket", - asset_host: "http://localhost:3900" + asset_host: "http://localhost:9000" config :ex_aws, json_codec: Jason diff --git a/config/dev.exs b/config/dev.exs index 1490490..457c221 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -92,15 +92,13 @@ config :phoenix_live_view, # Disable swoosh api client as it is only required for production adapters. config :swoosh, :api_client, false -# Local S3-compatible storage (MinIO or similar at localhost:3901) -# Adjust access_key_id / secret_access_key to match your local server's credentials +# Local S3-compatible storage (MinIO at localhost:9000) config :ex_aws, - access_key_id: "GKdea8f62997a90ffa664135d2", - secret_access_key: "dd2f1757661a9e68cae6928a2fc950a2b2fd03b229d71038c98d4713b40ebba2", - region: "garage" + access_key_id: "minioadmin", + secret_access_key: "minioadmin" config :ex_aws, :s3, scheme: "http://", host: "localhost", - port: 3900, - region: "garage" + port: 9000, + virtual_host: false diff --git a/lib/mixer/posts/media_uploader.ex b/lib/mixer/posts/media_uploader.ex index 52122ad..2318c39 100644 --- a/lib/mixer/posts/media_uploader.ex +++ b/lib/mixer/posts/media_uploader.ex @@ -13,7 +13,7 @@ defmodule Mixer.Posts.MediaUploader do def storage_dir(_version, {_file, scope}), do: "uploads/media/#{scope.id}" def filename(_version, {file, _scope}) do - Path.basename(file.file_name) + Path.basename(file.file_name, Path.extname(file.file_name)) end def s3_object_headers(_version, {file, _scope}) do diff --git a/lib/mixer_web/controllers/page_controller.ex b/lib/mixer_web/controllers/page_controller.ex index 62db9ac..2c28e49 100644 --- a/lib/mixer_web/controllers/page_controller.ex +++ b/lib/mixer_web/controllers/page_controller.ex @@ -6,8 +6,14 @@ defmodule MixerWeb.PageController do end def index(conn, _params) do + asset_host = Application.get_env(:waffle, :asset_host, "http://localhost:3900") + bucket = Application.get_env(:waffle, :bucket, "mixer-bucket") + conn |> put_root_layout(html: {MixerWeb.Layouts, :spa_root}) - |> render(:index, current_user: conn.assigns[:current_user]) + |> render(:index, + current_user: conn.assigns[:current_user], + media_host: "#{asset_host}/#{bucket}" + ) end end diff --git a/lib/mixer_web/controllers/page_html/index.html.heex b/lib/mixer_web/controllers/page_html/index.html.heex index f1c917e..dcb7fb4 100644 --- a/lib/mixer_web/controllers/page_html/index.html.heex +++ b/lib/mixer_web/controllers/page_html/index.html.heex @@ -1,4 +1,5 @@
+ data-current-user-email={if @current_user, do: @current_user.email, else: ""} + data-asset-host={@media_host}>