mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41:00 +00:00
Allow configurable upload dir per env
This commit is contained in:
parent
2f4940fab6
commit
ee571b19a7
8 changed files with 41 additions and 20 deletions
|
@ -1,15 +1,14 @@
|
|||
import Config
|
||||
|
||||
config :live_beats, :file_host, %{
|
||||
scheme: "http",
|
||||
host: "localhost",
|
||||
port: 4000
|
||||
}
|
||||
config :live_beats, :files, [
|
||||
uploads_dir: Path.expand("../priv/uploads", __DIR__),
|
||||
host: [scheme: "http", host: "localhost", port: 4000],
|
||||
]
|
||||
|
||||
config :live_beats, :github, %{
|
||||
config :live_beats, :github, [
|
||||
client_id: System.fetch_env!("LIVE_BEATS_GITHUB_CLIENT_ID"),
|
||||
client_secret: System.fetch_env!("LIVE_BEATS_GITHUB_CLIENT_SECRET"),
|
||||
}
|
||||
]
|
||||
|
||||
# Configure your database
|
||||
config :live_beats, LiveBeats.Repo,
|
||||
|
|
|
@ -45,14 +45,13 @@ if config_env() == :prod do
|
|||
secret_key_base: secret_key_base,
|
||||
server: true
|
||||
|
||||
config :live_beats, :file_host, %{
|
||||
scheme: "http",
|
||||
host: host,
|
||||
port: 80
|
||||
}
|
||||
config :live_beats, :files, [
|
||||
uploads_dir: "/app/uploads",
|
||||
host: [scheme: "https", host: host, port: 443],
|
||||
]
|
||||
|
||||
config :live_beats, :github, %{
|
||||
config :live_beats, :github, [
|
||||
client_id: System.fetch_env!("LIVE_BEATS_GITHUB_CLIENT_ID"),
|
||||
client_secret: System.fetch_env!("LIVE_BEATS_GITHUB_CLIENT_SECRET"),
|
||||
}
|
||||
]
|
||||
end
|
||||
|
|
2
fly.toml
2
fly.toml
|
@ -13,7 +13,7 @@ processes = []
|
|||
|
||||
[mounts]
|
||||
source="data"
|
||||
destination="/app/live_beats/lib/live_beats-0.1.0/priv/uploads"
|
||||
destination="/app/uploads"
|
||||
|
||||
[experimental]
|
||||
allowed_public_ports = []
|
||||
|
|
|
@ -4,6 +4,28 @@ defmodule LiveBeats do
|
|||
"""
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Looks up `Application` config or raises if keyspace is not configured.
|
||||
|
||||
## Examples
|
||||
|
||||
config :live_beats, :files, [
|
||||
uploads_dir: Path.expand("../priv/uploads", __DIR__),
|
||||
host: [scheme: "http", host: "localhost", port: 4000],
|
||||
]
|
||||
|
||||
iex> LiveBeats.config([:files, :uploads_dir])
|
||||
iex> LiveBeats.config([:files, :host, :port])
|
||||
"""
|
||||
def config([main_key | rest] = keyspace) when is_list(keyspace) do
|
||||
main = Application.fetch_env!(:live_beats, main_key)
|
||||
Enum.reduce(rest, main, fn next_key, current ->
|
||||
case Keyword.fetch(current, next_key) do
|
||||
{:ok, val} -> val
|
||||
:error -> raise ArgumentError, "no config found under #{inspect(keyspace)}"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Attaches a modules to another for listening of events.
|
||||
|
|
|
@ -28,7 +28,7 @@ defmodule LiveBeats.Accounts do
|
|||
end
|
||||
|
||||
def admin?(%User{} = user) do
|
||||
user.email in Application.fetch_env!(:live_beats, :admin_emails)
|
||||
user.email in LiveBeats.config([:admin_emails])
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -81,8 +81,8 @@ defmodule LiveBeats.Github do
|
|||
|> String.replace(["/", "+"], "-")
|
||||
end
|
||||
|
||||
defp client_id, do: Application.fetch_env!(:live_beats, :github)[:client_id]
|
||||
defp secret, do: Application.fetch_env!(:live_beats, :github)[:client_secret]
|
||||
defp client_id, do: LiveBeats.config([:github, :client_id])
|
||||
defp secret, do: LiveBeats.config([:github, :client_secret])
|
||||
|
||||
defp http(host, method, path, query, headers, body \\ "") do
|
||||
{:ok, conn} = Mint.HTTP.connect(:https, host, 443)
|
||||
|
|
|
@ -34,7 +34,8 @@ defmodule LiveBeats.MediaLibrary do
|
|||
end
|
||||
|
||||
def local_filepath(filename_uuid) when is_binary(filename_uuid) do
|
||||
Path.join("priv/uploads/songs", filename_uuid)
|
||||
dir = LiveBeats.config([:files, :uploads_dir])
|
||||
Path.join([dir, "songs", filename_uuid])
|
||||
end
|
||||
|
||||
def can_control_playback?(%Accounts.User{} = user, %Song{} = song) do
|
||||
|
|
|
@ -65,7 +65,7 @@ defmodule LiveBeats.MediaLibrary.Song do
|
|||
end
|
||||
|
||||
defp mp3_url(filename) do
|
||||
%{scheme: scheme, host: host, port: port} = Application.fetch_env!(:live_beats, :file_host)
|
||||
%{scheme: scheme, host: host, port: port} = Enum.into(LiveBeats.config([:files, :host]), %{})
|
||||
URI.to_string(%URI{scheme: scheme, host: host, port: port, path: "/files/#{filename}"})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue