forked from epochtalk/epochtalk_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into board-moderators
* origin/main: (36 commits) style(application): mix format refactor(bbc_parser): reduce bbc parser php call timeout to 1 second refactor(config): poolboy_config -> bbc_parser_poolboy_config feat(helpers/proxy_conversion): load board last post user avatar feat(docker): upgrade elixir version in docker file fix(credo): resolve credo error with user_json refactor(user-find): move manipulation of user object into user_json file fix(last-login): use users last login instead of test value, resolve credo error feat(last-active): implement last active, respecting flag showOnline if user doesnt want to be shown as active within the past 72 hours test(warnings): resolve test warnings feat(user-find): convert gender and dob into human readable format test(static): resolve dialyzer errors after upgrade of elixir/erlang feat(dob): calculate dob for user find proxy feat(gender): calculate gender for user find proxy refactor(cleanup): use BBCParser Gen Server for parsing user signature, run format feat(last-active): bring back last post date for last active in user find fix(credo): resolve credo issues in bbc parser feat(credo): upgrade credo to latest fix(parser): add missing settings that were causing portuguese characters to break feat(parser): user async parser for signature, code cleanup ...
- Loading branch information
Showing
26 changed files
with
529 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
elixir 1.14.4-otp-25 | ||
erlang 25.3.1 | ||
elixir 1.17.3-otp-27 | ||
erlang 27.1.2 | ||
php 8.3.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
defmodule EpochtalkServer.BBCParser do | ||
use GenServer | ||
require Logger | ||
alias Porcelain.Process, as: Proc | ||
@timeout 1_000 | ||
|
||
@moduledoc """ | ||
`BBCParser` genserver, runs interactive php shell to call bbcode parser | ||
""" | ||
|
||
## === genserver functions ==== | ||
|
||
@impl true | ||
def init(:ok), do: {:ok, load()} | ||
|
||
@impl true | ||
def handle_call({:parse, ""}, _from, {proc, pid}), | ||
do: {:reply, "", {proc, pid}} | ||
|
||
def handle_call({:parse, bbcode_data}, _from, {proc, pid}) when is_binary(bbcode_data) do | ||
Proc.send_input(proc, "echo parse_bbc('#{bbcode_data}');\n") | ||
|
||
parsed = | ||
receive do | ||
{^pid, :data, :out, data} -> | ||
Logger.debug(data) | ||
data | ||
end | ||
|
||
{:reply, parsed, {proc, pid}} | ||
end | ||
|
||
## === parser api functions ==== | ||
|
||
@doc """ | ||
Start genserver and create a reference for supervision tree | ||
""" | ||
def start_link(_opts), do: GenServer.start_link(__MODULE__, :ok) | ||
|
||
@doc """ | ||
Uses poolboy to call parser | ||
""" | ||
def async_parse(bbcode_data) do | ||
:poolboy.transaction( | ||
:bbc_parser, | ||
fn pid -> | ||
try do | ||
Logger.debug("#{__MODULE__}(ASYNC PARSE): #{inspect(pid)}") | ||
GenServer.call(pid, {:parse, bbcode_data}, @timeout) | ||
catch | ||
e, r -> | ||
Logger.debug("poolboy transaction caught error: #{inspect(e)}, #{inspect(r)}") | ||
:ok | ||
end | ||
end, | ||
@timeout | ||
) | ||
end | ||
|
||
## === private functions ==== | ||
|
||
# returns loaded interactive php shell | ||
defp load() do | ||
proc = %Proc{pid: pid} = Porcelain.spawn_shell("php -a", in: :receive, out: {:send, self()}) | ||
Proc.send_input(proc, "require 'parsing.php';\n") | ||
Logger.debug("#{__MODULE__}(LOAD): #{inspect(pid)}") | ||
# clear initial php interactive shell message | ||
receive do | ||
{^pid, :data, :out, data} -> Logger.debug("#{__MODULE__}: #{inspect(data)}") | ||
end | ||
|
||
{proc, pid} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.