mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 12:08:00 +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"),
|
proxy_host: System.get_env("PROXY_HOST"),
|
||||||
camo_host: System.get_env("CAMO_HOST"),
|
camo_host: System.get_env("CAMO_HOST"),
|
||||||
camo_key: System.get_env("CAMO_KEY"),
|
camo_key: System.get_env("CAMO_KEY"),
|
||||||
cdn_host: System.fetch_env!("CDN_HOST"),
|
cdn_host: System.fetch_env!("CDN_HOST")
|
||||||
app_dir: System.get_env("APP_DIR", File.cwd!())
|
|
||||||
|
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,
|
config :exq,
|
||||||
host: System.get_env("REDIS_HOST", "localhost"),
|
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)
|
# Starts a worker by calling: Philomena.Worker.start_link(arg)
|
||||||
# {Philomena.Worker, arg},
|
# {Philomena.Worker, arg},
|
||||||
Philomena.Servers.Config,
|
|
||||||
{Redix, name: :redix, host: Application.get_env(:philomena, :redis_host)},
|
{Redix, name: :redix, host: Application.get_env(:philomena, :redis_host)},
|
||||||
{Phoenix.PubSub,
|
{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
|
defmodule Philomena.Images.TagValidator do
|
||||||
alias Philomena.Servers.Config
|
alias Philomena.Config
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
def validate_tags(changeset) do
|
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
|
defmodule PhilomenaWeb.StatsUpdater do
|
||||||
|
alias Philomena.Config
|
||||||
alias Philomena.Elasticsearch
|
alias Philomena.Elasticsearch
|
||||||
alias Philomena.Servers.Config
|
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
alias Philomena.Comments.Comment
|
alias Philomena.Comments.Comment
|
||||||
alias Philomena.Topics.Topic
|
alias Philomena.Topics.Topic
|
||||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.AvatarGeneratorView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
use Bitwise
|
use Bitwise
|
||||||
|
|
||||||
alias Philomena.Servers.Config
|
alias Philomena.Config
|
||||||
|
|
||||||
def generated_avatar(displayed_name) do
|
def generated_avatar(displayed_name) do
|
||||||
config = config()
|
config = config()
|
||||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.LayoutView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
alias PhilomenaWeb.ImageView
|
alias PhilomenaWeb.ImageView
|
||||||
alias Philomena.Servers.Config
|
alias Philomena.Config
|
||||||
alias Plug.Conn
|
alias Plug.Conn
|
||||||
|
|
||||||
def layout_class(conn) do
|
def layout_class(conn) do
|
||||||
|
|
|
@ -2,7 +2,7 @@ defmodule PhilomenaWeb.TagView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
# this is bad practice, don't copy this.
|
# this is bad practice, don't copy this.
|
||||||
alias Philomena.Servers.Config
|
alias Philomena.Config
|
||||||
alias Philomena.Elasticsearch
|
alias Philomena.Elasticsearch
|
||||||
alias Philomena.Tags.Tag
|
alias Philomena.Tags.Tag
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
|
|
Loading…
Reference in a new issue