Skip to content

Commit

Permalink
style(post_json,bbc_parser): mix format
Browse files Browse the repository at this point in the history
  • Loading branch information
unenglishable committed Dec 12, 2024
1 parent 4a5e52f commit a4991fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
17 changes: 14 additions & 3 deletions lib/epochtalk_server/bbc_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ defmodule EpochtalkServer.BBCParser do
do: {:reply, {:ok, ""}, {proc, pid}}

def handle_call({:parse, bbcode_data}, _from, {proc, pid}) when is_binary(bbcode_data) do
Logger.debug("#{__MODULE__}(start parse): #{String.first(bbcode_data)} #{NaiveDateTime.utc_now()}")
Logger.debug(
"#{__MODULE__}(start parse): #{String.first(bbcode_data)} #{NaiveDateTime.utc_now()}"
)

parsed = parse_with_proc(bbcode_data, {proc, pid})
Logger.debug("#{__MODULE__}(finish parse): #{String.first(bbcode_data)} #{NaiveDateTime.utc_now()}")

Logger.debug(
"#{__MODULE__}(finish parse): #{String.first(bbcode_data)} #{NaiveDateTime.utc_now()}"
)

{:reply, parsed, {proc, pid}}
end

Expand All @@ -50,11 +57,12 @@ defmodule EpochtalkServer.BBCParser do

defp parse_list_with_proc(bbcode_data_list, {proc, pid}) do
bbcode_data_list
|> Enum.map(&(parse_with_proc(&1, {proc, pid})))
|> Enum.map(&parse_with_proc(&1, {proc, pid}))
end

defp parse_with_proc(nil, {_proc, _pid}), do: {:ok, nil}
defp parse_with_proc("", {_proc, _pid}), do: {:ok, ""}

defp parse_with_proc(bbcode_data, {proc, pid}) do
Proc.send_input(proc, "echo parse_bbc('#{bbcode_data}');\n")

Expand All @@ -65,9 +73,11 @@ defmodule EpochtalkServer.BBCParser do
# time out after not receiving any data
@receive_timeout ->
Logger.error("#{__MODULE__}(parse timeout): #{inspect(pid)}, #{inspect(bbcode_data)}")

bbcode_data =
"<p style=\"color:red;font-weight:bold\">((bbcode parse timeout))</p></br>" <>
bbcode_data

{:timeout, bbcode_data}
end
end
Expand Down Expand Up @@ -103,6 +113,7 @@ defmodule EpochtalkServer.BBCParser do
@call_timeout
)
end

def parse(bbcode_data) do
:poolboy.transaction(
:bbc_parser,
Expand Down
47 changes: 28 additions & 19 deletions lib/epochtalk_server_web/json/post_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ defmodule EpochtalkServerWeb.Controllers.PostJSON do
{body_list, signature_list}
|> EpochtalkServer.BBCParser.parse_list_tuple()
|> case do
{:ok, parsed_tuple} -> parsed_tuple
{:ok, parsed_tuple} ->
parsed_tuple

{:error, unparsed_tuple} ->
Logger.error("#{__MODULE__}(tuple parse): #{inspect(posts)}")
unparsed_tuple
Expand All @@ -484,26 +486,33 @@ defmodule EpochtalkServerWeb.Controllers.PostJSON do
Enum.zip_with(
[posts, parsed_body_list, parsed_signature_list],
fn [post, parsed_body, parsed_signature] ->
parsed_body = case parsed_body do
{:ok, parsed_body} ->
Logger.debug("#{__MODULE__}(body): post_id #{inspect(post.id)}")
parsed_body
{:timeout, unparsed_body} ->
Logger.error("#{__MODULE__}(body timeout): post_id #{inspect(post.id)}")
unparsed_body
end
parsed_signature = case parsed_signature do
{:ok, parsed_signature} ->
Logger.debug("#{__MODULE__}(signature): user_id #{inspect(post.user.id)}")
parsed_signature
{:timeout, unparsed_signature} ->
Logger.error("#{__MODULE__}(signature timeout): user_id #{inspect(post.user.id)}")
unparsed_signature
end
parsed_body =
case parsed_body do
{:ok, parsed_body} ->
Logger.debug("#{__MODULE__}(body): post_id #{inspect(post.id)}")
parsed_body

{:timeout, unparsed_body} ->
Logger.error("#{__MODULE__}(body timeout): post_id #{inspect(post.id)}")
unparsed_body
end

parsed_signature =
case parsed_signature do
{:ok, parsed_signature} ->
Logger.debug("#{__MODULE__}(signature): user_id #{inspect(post.user.id)}")
parsed_signature

{:timeout, unparsed_signature} ->
Logger.error("#{__MODULE__}(signature timeout): user_id #{inspect(post.user.id)}")
unparsed_signature
end

user = post.user |> Map.put(:signature, parsed_signature)

post
|> Map.put(:body_html, parsed_body)
|> Map.put(:user, user)
|> Map.put(:body_html, parsed_body)
|> Map.put(:user, user)
end
)
end
Expand Down

0 comments on commit a4991fa

Please sign in to comment.