+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Captcha do
use GenServer
ets_name = Module.concat(method(), Ets)
^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options)
+ # Clean up old captchas every few minutes
+ seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained])
+ Process.send_after(self(), :cleanup, 1000 * seconds_retained)
+
{:ok, nil}
end
if !enabled do
{:reply, %{type: :none}, state}
else
- new_captcha = method().new()
-
- minutes_retained = Pleroma.Config.get!([__MODULE__, :minutes_retained])
- # Wait several minutes and if the captcha is still there, delete it
- Process.send_after(self(), {:cleanup, new_captcha.token}, 1000 * 60 * minutes_retained)
-
- {:reply, new_captcha, state}
+ {:reply, method().new(), state}
end
end
end
@doc false
- def handle_info({:cleanup, token}, state) do
- method().cleanup(token)
+ def handle_info(:cleanup, state) do
+ :ok = method().cleanup()
+
+ seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained])
+ # Schedule the next clenup
+ Process.send_after(self(), :cleanup, 1000 * seconds_retained)
{:noreply, state}
end