mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
remove config server (philomena-dev/philomena#56)
This commit is contained in:
parent
fb39379051
commit
495396206e
9 changed files with 28 additions and 67 deletions
|
@ -34,8 +34,24 @@ config :philomena,
|
|||
proxy_host: System.get_env("PROXY_HOST"),
|
||||
camo_host: System.get_env("CAMO_HOST"),
|
||||
camo_key: System.get_env("CAMO_KEY"),
|
||||
cdn_host: System.fetch_env!("CDN_HOST"),
|
||||
app_dir: System.get_env("APP_DIR", File.cwd!())
|
||||
cdn_host: System.fetch_env!("CDN_HOST")
|
||||
|
||||
app_dir = System.get_env("APP_DIR", File.cwd!())
|
||||
|
||||
json_config =
|
||||
%{
|
||||
aggregation: "aggregation.json",
|
||||
avatar: "avatar.json",
|
||||
footer: "footer.json",
|
||||
quick_tag_table: "quick_tag_table.json",
|
||||
tag: "tag.json"
|
||||
}
|
||||
|> Map.new(fn {name, file} ->
|
||||
{name, Jason.decode!(File.read!("#{app_dir}/config/#{file}"))}
|
||||
end)
|
||||
|
||||
config :philomena,
|
||||
config: json_config
|
||||
|
||||
config :exq,
|
||||
host: System.get_env("REDIS_HOST", "localhost"),
|
||||
|
|
|
@ -16,7 +16,6 @@ defmodule Philomena.Application do
|
|||
|
||||
# Starts a worker by calling: Philomena.Worker.start_link(arg)
|
||||
# {Philomena.Worker, arg},
|
||||
Philomena.Servers.Config,
|
||||
{Redix, name: :redix, host: Application.get_env(:philomena, :redis_host)},
|
||||
{Phoenix.PubSub,
|
||||
[
|
||||
|
|
5
lib/philomena/config.ex
Normal file
5
lib/philomena/config.ex
Normal file
|
@ -0,0 +1,5 @@
|
|||
defmodule Philomena.Config do
|
||||
def get(key) do
|
||||
Application.get_env(:philomena, :config)[key]
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Philomena.Images.TagValidator do
|
||||
alias Philomena.Servers.Config
|
||||
alias Philomena.Config
|
||||
import Ecto.Changeset
|
||||
|
||||
def validate_tags(changeset) do
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
defmodule Philomena.Servers.Config do
|
||||
use GenServer
|
||||
|
||||
@process_name :philomena_config
|
||||
|
||||
def start_link([]) do
|
||||
GenServer.start_link(__MODULE__, [])
|
||||
end
|
||||
|
||||
def get(key) do
|
||||
pid = Process.whereis(@process_name)
|
||||
GenServer.call(pid, {:get, key})
|
||||
end
|
||||
|
||||
def reload do
|
||||
pid = Process.whereis(@process_name)
|
||||
GenServer.cast(pid, :reload)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init([]) do
|
||||
Process.register(self(), @process_name)
|
||||
{:ok, %{}}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call({:get, key}, _from, state) do
|
||||
state = maybe_update_state(state, key, Map.has_key?(state, key))
|
||||
|
||||
{:reply, state[key], state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast(:reload, _state) do
|
||||
{:noreply, %{}}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def code_change(_old_vsn, _state, _extra) do
|
||||
{:ok, %{}}
|
||||
end
|
||||
|
||||
defp maybe_update_state(state, key, false) do
|
||||
Map.put(state, key, load_config(key))
|
||||
end
|
||||
|
||||
defp maybe_update_state(state, _key, _true), do: state
|
||||
|
||||
defp load_config(name) do
|
||||
with {:ok, text} <- File.read("#{app_dir()}/config/#{name}.json"),
|
||||
{:ok, json} <- Jason.decode(text) do
|
||||
json
|
||||
end
|
||||
end
|
||||
|
||||
defp app_dir do
|
||||
Application.get_env(:philomena, :app_dir)
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
defmodule PhilomenaWeb.StatsUpdater do
|
||||
alias Philomena.Config
|
||||
alias Philomena.Elasticsearch
|
||||
alias Philomena.Servers.Config
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.Topics.Topic
|
||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.AvatarGeneratorView do
|
|||
use PhilomenaWeb, :view
|
||||
use Bitwise
|
||||
|
||||
alias Philomena.Servers.Config
|
||||
alias Philomena.Config
|
||||
|
||||
def generated_avatar(displayed_name) do
|
||||
config = config()
|
||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.LayoutView do
|
|||
use PhilomenaWeb, :view
|
||||
|
||||
alias PhilomenaWeb.ImageView
|
||||
alias Philomena.Servers.Config
|
||||
alias Philomena.Config
|
||||
alias Plug.Conn
|
||||
|
||||
def layout_class(conn) do
|
||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.TagView do
|
|||
use PhilomenaWeb, :view
|
||||
|
||||
# this is bad practice, don't copy this.
|
||||
alias Philomena.Servers.Config
|
||||
alias Philomena.Config
|
||||
alias Philomena.Elasticsearch
|
||||
alias Philomena.Tags.Tag
|
||||
alias Philomena.Repo
|
||||
|
|
Loading…
Reference in a new issue