From ef56488349a257def67d6c906a1f71e9bbed397e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 29 Nov 2018 06:53:17 +0000 Subject: mix: add task to compact the database --- lib/mix/tasks/compact_database.ex | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/mix/tasks/compact_database.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/compact_database.ex b/lib/mix/tasks/compact_database.ex new file mode 100644 index 000000000..b84b340ac --- /dev/null +++ b/lib/mix/tasks/compact_database.ex @@ -0,0 +1,57 @@ +defmodule Mix.Tasks.CompactDatabase do + @moduledoc """ + Compact the database by flattening the object graph. + """ + + require Logger + + use Mix.Task + import Mix.Ecto + import Ecto.Query + alias Pleroma.{Repo, Object, Activity} + + defp maybe_compact(%Activity{data: %{"object" => %{"id" => object_id}}} = activity) do + data = + activity.data + |> Map.put("object", object_id) + + {:ok, activity} = + Activity.change(activity, %{data: data}) + |> Repo.update() + + {:ok, activity} + end + + defp maybe_compact(%Activity{} = activity), do: {:ok, activity} + + defp activity_query(min_id, max_id) do + from( + a in Activity, + where: fragment("?->>'type' = 'Create'", a.data), + where: a.id >= ^min_id, + where: a.id < ^max_id + ) + end + + def run(args) do + Application.ensure_all_started(:pleroma) + + max = Repo.aggregate(Activity, :max, :id) + Logger.info("Considering #{max} activities") + + chunks = 0..(round(max / 100)) + + Enum.each(chunks, fn (i) -> + min = i * 100 + max = min + 100 + + activity_query(min, max) + |> Repo.all() + |> Enum.each(&maybe_compact/1) + + IO.write(".") + end) + + Logger.info("Finished.") + end +end -- cgit v1.2.3 From 1a360a4eaa57d57ccc4f03dfa25e82a240d0175a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 1 Dec 2018 22:17:28 +0000 Subject: compact database task: fix formatting --- lib/mix/tasks/compact_database.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/compact_database.ex b/lib/mix/tasks/compact_database.ex index b84b340ac..7de50812a 100644 --- a/lib/mix/tasks/compact_database.ex +++ b/lib/mix/tasks/compact_database.ex @@ -39,9 +39,9 @@ defmodule Mix.Tasks.CompactDatabase do max = Repo.aggregate(Activity, :max, :id) Logger.info("Considering #{max} activities") - chunks = 0..(round(max / 100)) + chunks = 0..round(max / 100) - Enum.each(chunks, fn (i) -> + Enum.each(chunks, fn i -> min = i * 100 max = min + 100 -- cgit v1.2.3 From d013b58e84f2c8213a5d26b1c3daf36e2f4807e5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:04:08 +0700 Subject: add `mix pleroma.user delete_activities NICKNAME` task --- lib/mix/tasks/pleroma/user.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 037e44716..e232df14f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -304,6 +304,18 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["delete_activities", nickname]) do + Common.start_pleroma() + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + User.delete_user_activities(user) + Mix.shell().info("User #{nickname} deleted.") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + defp set_moderator(user, value) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) -- cgit v1.2.3 From 16e598ec11cb9178b9fc53a1ec4b649d97c5f3b8 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:12:05 +0700 Subject: fix wording --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index e232df14f..ec06d908a 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -309,7 +309,7 @@ defmodule Mix.Tasks.Pleroma.User do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} deleted.") + Mix.shell().info("User #{nickname} statuses deleted..") else _ -> Mix.shell().error("No local user #{nickname}") -- cgit v1.2.3 From 3dadaa4432b442d75b0ac0425aa05527d52f0e7a Mon Sep 17 00:00:00 2001 From: William Pearson Date: Sun, 20 Jan 2019 01:44:00 +0000 Subject: robots.txt Add default robots.txt that allows bots access to all paths. Add mix task to generate robots.txt taht allows bots access to no paths. Document custom emojis, MRF and static_dir static_dir documentation includes docs for the robots.txt Mix task. --- lib/mix/tasks/pleroma/robotstxt.ex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/mix/tasks/pleroma/robotstxt.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/robotstxt.ex b/lib/mix/tasks/pleroma/robotstxt.ex new file mode 100644 index 000000000..2128e1cd6 --- /dev/null +++ b/lib/mix/tasks/pleroma/robotstxt.ex @@ -0,0 +1,32 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.RobotsTxt do + use Mix.Task + + @shortdoc "Generate robots.txt" + @moduledoc """ + Generates robots.txt + + ## Overwrite robots.txt to disallow all + + mix pleroma.robots_txt disallow_all + + This will write a robots.txt that will hide all paths on your instance + from search engines and other robots that obey robots.txt + + """ + def run(["disallow_all"]) do + static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/") + + if !File.exists?(static_dir) do + File.mkdir_p!(static_dir) + end + + robots_txt_path = Path.join(static_dir, "robots.txt") + robots_txt_content = "User-Agent: *\nDisallow: /\n" + + File.write!(robots_txt_path, robots_txt_content, [:write]) + end +end -- cgit v1.2.3 From a14742f495fac78f4dfd7ab02f4c3ae5c7c37c3b Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 16:30:11 +0700 Subject: add `user delete_activities` mix task --- lib/mix/tasks/pleroma/user.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 680422c19..62c9fceda 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -23,7 +23,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -33,6 +33,10 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user rm NICKNAME + ## Delete the user's activities. + + mix pleroma.user delete_activities NICKNAME + ## Deactivate or activate the user's account. mix pleroma.user toggle_activated NICKNAME @@ -309,7 +313,7 @@ defmodule Mix.Tasks.Pleroma.User do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete_user_activities(user) - Mix.shell().info("User #{nickname} statuses deleted..") + Mix.shell().info("User #{nickname} statuses deleted.") else _ -> Mix.shell().error("No local user #{nickname}") -- cgit v1.2.3 From 1b3d92192194baf6b431cd9f0ce58062d1b703d5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 2 Apr 2019 17:01:26 +0700 Subject: change `Repo.get(User, id)` => `User.get_by_id(id)` --- lib/mix/tasks/pleroma/user.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index f6cca0d06..2487b4ab5 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -6,7 +6,6 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset alias Mix.Tasks.Pleroma.Common - alias Pleroma.Repo alias Pleroma.User @shortdoc "Manages Pleroma users" @@ -23,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -202,7 +201,7 @@ defmodule Mix.Tasks.Pleroma.User do {:ok, friends} = User.get_friends(user) Enum.each(friends, fn friend -> - user = Repo.get(User, user.id) + user = User.get_by_id(user.id) Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}") User.unfollow(user, friend) @@ -210,7 +209,7 @@ defmodule Mix.Tasks.Pleroma.User do :timer.sleep(500) - user = Repo.get(User, user.id) + user = User.get_by_id(user.id) if Enum.empty?(user.following) do Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}") -- cgit v1.2.3 From cd41584ac4a90a666f33786d967d37a619c67762 Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Wed, 3 Apr 2019 00:54:16 +0545 Subject: Generate permissive or restrictive robots.txt in the config generator --- lib/mix/tasks/pleroma/instance.ex | 34 ++++++++++++++++++++++++++++++++++ lib/mix/tasks/pleroma/robots_txt.eex | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 lib/mix/tasks/pleroma/robots_txt.eex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 1ba452275..8f8d86a11 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -81,6 +81,14 @@ defmodule Mix.Tasks.Pleroma.Instance do email = Common.get_option(options, :admin_email, "What is your admin email address?") + indexable = + Common.get_option( + options, + :indexable, + "Do you want search engines to index your site? (y/n)", + "y" + ) === "y" + dbhost = Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost") @@ -142,6 +150,8 @@ defmodule Mix.Tasks.Pleroma.Instance do Mix.shell().info("Writing #{psql_path}.") File.write(psql_path, result_psql) + write_robots_txt(indexable) + Mix.shell().info( "\n" <> """ @@ -163,4 +173,28 @@ defmodule Mix.Tasks.Pleroma.Instance do ) end end + + defp write_robots_txt(indexable) do + robots_txt = + EEx.eval_file( + Path.expand("robots_txt.eex", __DIR__), + indexable: indexable + ) + + static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/") + + unless File.exists?(static_dir) do + File.mkdir_p!(static_dir) + end + + robots_txt_path = Path.join(static_dir, "robots.txt") + + if File.exists?(robots_txt_path) do + File.cp!(robots_txt_path, "#{robots_txt_path}.bak") + Mix.shell().info("Backing up existing robots.txt to #{robots_txt_path}.bak") + end + + File.write(robots_txt_path, robots_txt) + Mix.shell().info("Writing #{robots_txt_path}.") + end end diff --git a/lib/mix/tasks/pleroma/robots_txt.eex b/lib/mix/tasks/pleroma/robots_txt.eex new file mode 100644 index 000000000..1af3c47ee --- /dev/null +++ b/lib/mix/tasks/pleroma/robots_txt.eex @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: <%= if indexable, do: "", else: "/" %> -- cgit v1.2.3 From 0484f3a8b1ae2103d1d756e5c09f2bdb218a7207 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 6 Apr 2019 16:58:22 +0700 Subject: generating tokens with mix --- lib/mix/tasks/pleroma/user.ex | 75 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 0d0bea8c0..00a933292 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -7,6 +7,7 @@ defmodule Mix.Tasks.Pleroma.User do import Ecto.Changeset alias Mix.Tasks.Pleroma.Common alias Pleroma.User + alias Pleroma.UserInviteToken @shortdoc "Manages Pleroma users" @moduledoc """ @@ -26,7 +27,19 @@ defmodule Mix.Tasks.Pleroma.User do ## Generate an invite link. - mix pleroma.user invite + mix pleroma.user invite [OPTION...] + + Options: + - `--expire_date DATE` - last day on which token is active (e.g. "2019-04-05") + - `--max_use NUMBER` - maximum numbers of token use + + ## Generated invites list + + mix pleroma.user invites_list + + ## Revoke invite + + mix pleroma.user invite_revoke TOKEN OR TOKEN_ID ## Delete the user's account. @@ -287,11 +300,28 @@ defmodule Mix.Tasks.Pleroma.User do end end - def run(["invite"]) do + def run(["invite" | rest]) do + {options, [], []} = + OptionParser.parse(rest, + strict: [ + expire_date: :string, + max_use: :integer + ] + ) + + expire_at = + with expire_date when expire_date != nil <- Keyword.get(options, :expire_date) do + Date.from_iso8601!(expire_date) + end + + options = Keyword.put(options, :expire_at, expire_at) + Common.start_pleroma() - with {:ok, token} <- Pleroma.UserInviteToken.create_token() do - Mix.shell().info("Generated user invite token") + with {:ok, token} <- UserInviteToken.create_token(options) do + Mix.shell().info( + "Generated user invite token " <> String.replace(token.token_type, "_", " ") + ) url = Pleroma.Web.Router.Helpers.redirect_url( @@ -307,6 +337,43 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["invites_list"]) do + Common.start_pleroma() + + Mix.shell().info("Invites list:") + + UserInviteToken.list_invites() + |> Enum.each(fn invite -> + expire_date = + case invite.expire_at do + nil -> nil + date -> " | Expire date: #{Date.to_string(date)}" + end + + using_info = + case invite.max_use do + nil -> nil + max_use -> " | Max use: #{max_use} Left use: #{max_use - invite.uses}" + end + + Mix.shell().info( + "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.token_type} | Used: #{ + invite.used + }#{expire_date}#{using_info}" + ) + end) + end + + def run(["invite_revoke", token]) do + Common.start_pleroma() + + with {:ok, _} <- UserInviteToken.mark_as_used(token) do + Mix.shell().info("Invite for token #{token} was revoked.") + else + _ -> Mix.shell().error("No invite found with token #{token}") + end + end + def run(["delete_activities", nickname]) do Common.start_pleroma() -- cgit v1.2.3 From 47b07cec495528ce22f83ca56717cc74aa0096f3 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 6 Apr 2019 20:24:22 +0700 Subject: token -> invite renaming --- lib/mix/tasks/pleroma/user.ex | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 00a933292..887f45029 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -315,19 +315,19 @@ defmodule Mix.Tasks.Pleroma.User do end options = Keyword.put(options, :expire_at, expire_at) - + options = Enum.into(options, %{}) Common.start_pleroma() - with {:ok, token} <- UserInviteToken.create_token(options) do + with {:ok, invite} <- UserInviteToken.create_invite(options) do Mix.shell().info( - "Generated user invite token " <> String.replace(token.token_type, "_", " ") + "Generated user invite token " <> String.replace(invite.invite_type, "_", " ") ) url = Pleroma.Web.Router.Helpers.redirect_url( Pleroma.Web.Endpoint, :registration_page, - token.token + invite.token ) IO.puts(url) @@ -367,7 +367,9 @@ defmodule Mix.Tasks.Pleroma.User do def run(["invite_revoke", token]) do Common.start_pleroma() - with {:ok, _} <- UserInviteToken.mark_as_used(token) do + invite = UserInviteToken.find_by_token!(token) + + with {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do Mix.shell().info("Invite for token #{token} was revoked.") else _ -> Mix.shell().error("No invite found with token #{token}") -- cgit v1.2.3 From ce8d45713287d8f1c413699385950f295085ee77 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 6 Apr 2019 22:38:35 +0700 Subject: little channges --- lib/mix/tasks/pleroma/user.ex | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 887f45029..80b07d1ac 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -30,16 +30,16 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user invite [OPTION...] Options: - - `--expire_date DATE` - last day on which token is active (e.g. "2019-04-05") - - `--max_use NUMBER` - maximum numbers of token use + - `--expire_at DATE` - last day on which token is active (e.g. "2019-04-05") + - `--max_use NUMBER` - maximum numbers of token uses - ## Generated invites list + ## List generated invites - mix pleroma.user invites_list + mix pleroma.user invites ## Revoke invite - mix pleroma.user invite_revoke TOKEN OR TOKEN_ID + mix pleroma.user revoke_invite TOKEN OR TOKEN_ID ## Delete the user's account. @@ -304,21 +304,24 @@ defmodule Mix.Tasks.Pleroma.User do {options, [], []} = OptionParser.parse(rest, strict: [ - expire_date: :string, + expire_at: :string, max_use: :integer ] ) - expire_at = - with expire_date when expire_date != nil <- Keyword.get(options, :expire_date) do - Date.from_iso8601!(expire_date) - end + options = + options + |> Keyword.update(:expire_at, {:ok, nil}, fn + nil -> {:ok, nil} + val -> Date.from_iso8601(val) + end) + |> Enum.into(%{}) - options = Keyword.put(options, :expire_at, expire_at) - options = Enum.into(options, %{}) Common.start_pleroma() - with {:ok, invite} <- UserInviteToken.create_invite(options) do + with {:ok, val} <- options[:expire_at], + options = Map.put(options, :expire_at, val), + {:ok, invite} <- UserInviteToken.create_invite(options) do Mix.shell().info( "Generated user invite token " <> String.replace(invite.invite_type, "_", " ") ) @@ -332,44 +335,41 @@ defmodule Mix.Tasks.Pleroma.User do IO.puts(url) else - _ -> - Mix.shell().error("Could not create invite token.") + error -> + Mix.shell().error("Could not create invite token: #{inspect(error)}") end end - def run(["invites_list"]) do + def run(["invites"]) do Common.start_pleroma() Mix.shell().info("Invites list:") UserInviteToken.list_invites() |> Enum.each(fn invite -> - expire_date = - case invite.expire_at do - nil -> nil - date -> " | Expire date: #{Date.to_string(date)}" + expire_info = + with expire_at when not is_nil(expire_at) <- invite.expire_at do + " | Expire at: #{Date.to_string(expire_at)}" end using_info = - case invite.max_use do - nil -> nil - max_use -> " | Max use: #{max_use} Left use: #{max_use - invite.uses}" + with max_use when not is_nil(max_use) <- invite.max_use do + " | Max use: #{max_use} Left use: #{max_use - invite.uses}" end Mix.shell().info( - "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.token_type} | Used: #{ + "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{ invite.used - }#{expire_date}#{using_info}" + }#{expire_info}#{using_info}" ) end) end - def run(["invite_revoke", token]) do + def run(["revoke_invite", token]) do Common.start_pleroma() - invite = UserInviteToken.find_by_token!(token) - - with {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do + with {:ok, invite} <- UserInviteToken.find_by_token(token), + {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do Mix.shell().info("Invite for token #{token} was revoked.") else _ -> Mix.shell().error("No invite found with token #{token}") -- cgit v1.2.3 From 012bb5dcc9bfbf6f3ea210ec4e865f3adcea9dfd Mon Sep 17 00:00:00 2001 From: Alex S Date: Mon, 8 Apr 2019 16:01:28 +0700 Subject: renaming expire_at -> expires_at keyword style change --- lib/mix/tasks/pleroma/user.ex | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 80b07d1ac..441168df2 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -30,7 +30,7 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user invite [OPTION...] Options: - - `--expire_at DATE` - last day on which token is active (e.g. "2019-04-05") + - `--expires_at DATE` - last day on which token is active (e.g. "2019-04-05") - `--max_use NUMBER` - maximum numbers of token uses ## List generated invites @@ -304,14 +304,14 @@ defmodule Mix.Tasks.Pleroma.User do {options, [], []} = OptionParser.parse(rest, strict: [ - expire_at: :string, + expires_at: :string, max_use: :integer ] ) options = options - |> Keyword.update(:expire_at, {:ok, nil}, fn + |> Keyword.update(:expires_at, {:ok, nil}, fn nil -> {:ok, nil} val -> Date.from_iso8601(val) end) @@ -319,8 +319,8 @@ defmodule Mix.Tasks.Pleroma.User do Common.start_pleroma() - with {:ok, val} <- options[:expire_at], - options = Map.put(options, :expire_at, val), + with {:ok, val} <- options[:expires_at], + options = Map.put(options, :expires_at, val), {:ok, invite} <- UserInviteToken.create_invite(options) do Mix.shell().info( "Generated user invite token " <> String.replace(invite.invite_type, "_", " ") @@ -348,8 +348,8 @@ defmodule Mix.Tasks.Pleroma.User do UserInviteToken.list_invites() |> Enum.each(fn invite -> expire_info = - with expire_at when not is_nil(expire_at) <- invite.expire_at do - " | Expire at: #{Date.to_string(expire_at)}" + with expires_at when not is_nil(expires_at) <- invite.expires_at do + " | Expires at: #{Date.to_string(expires_at)}" end using_info = -- cgit v1.2.3 From fe13a1d78c13fbe7b3027d442a6f6906440e5acc Mon Sep 17 00:00:00 2001 From: Alex S Date: Wed, 10 Apr 2019 17:57:41 +0700 Subject: adding notify_email setting for trigger emails --- lib/mix/tasks/pleroma/instance.ex | 17 +++++++++++++++-- lib/mix/tasks/pleroma/sample_config.eex | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 8f8d86a11..6cee8d630 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -24,10 +24,12 @@ defmodule Mix.Tasks.Pleroma.Instance do - `--domain DOMAIN` - the domain of your instance - `--instance-name INSTANCE_NAME` - the name of your instance - `--admin-email ADMIN_EMAIL` - the email address of the instance admin + - `--notify-email NOTIFY_EMAIL` - email address for notifications - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use - `--dbname DBNAME` - the name of the database to use - `--dbuser DBUSER` - the user (aka role) to use for the database connection - `--dbpass DBPASS` - the password to use for the database connection + - `--indexable Y/N` - Allow/disallow indexing site by search engines """ def run(["gen" | rest]) do @@ -41,10 +43,12 @@ defmodule Mix.Tasks.Pleroma.Instance do domain: :string, instance_name: :string, admin_email: :string, + notify_email: :string, dbhost: :string, dbname: :string, dbuser: :string, - dbpass: :string + dbpass: :string, + indexable: :string ], aliases: [ o: :output, @@ -61,7 +65,7 @@ defmodule Mix.Tasks.Pleroma.Instance do will_overwrite = Enum.filter(paths, &File.exists?/1) proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false) - unless not proceed? do + if proceed? do [domain, port | _] = String.split( Common.get_option( @@ -81,6 +85,14 @@ defmodule Mix.Tasks.Pleroma.Instance do email = Common.get_option(options, :admin_email, "What is your admin email address?") + notify_email = + Common.get_option( + options, + :notify_email, + "What email address do you want to use for sending email notifications?", + email + ) + indexable = Common.get_option( options, @@ -122,6 +134,7 @@ defmodule Mix.Tasks.Pleroma.Instance do domain: domain, port: port, email: email, + notify_email: notify_email, name: name, dbhost: dbhost, dbname: dbname, diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 1c935c0d8..52bd57cb7 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -13,6 +13,7 @@ config :pleroma, Pleroma.Web.Endpoint, config :pleroma, :instance, name: "<%= name %>", email: "<%= email %>", + notify_email: "<%= notify_email %>", limit: 5000, registrations_open: true, dedupe_media: false @@ -75,4 +76,3 @@ config :web_push_encryption, :vapid_details, # storage_url: "https://swift-endpoint.prodider.com/v1/AUTH_/", # object_url: "https://cdn-endpoint.provider.com/" # - -- cgit v1.2.3 From a11ca87f40fd85341afa4445d3b7303ae8e92b76 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 18 Apr 2019 13:10:38 +0300 Subject: Add a migration to remove embeded objects --- lib/mix/tasks/compact_database.ex | 57 --------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 lib/mix/tasks/compact_database.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/compact_database.ex b/lib/mix/tasks/compact_database.ex deleted file mode 100644 index 17b9721f7..000000000 --- a/lib/mix/tasks/compact_database.ex +++ /dev/null @@ -1,57 +0,0 @@ -defmodule Mix.Tasks.CompactDatabase do - @moduledoc """ - Compact the database by flattening the object graph. - """ - - require Logger - - use Mix.Task - import Ecto.Query - alias Pleroma.Activity - alias Pleroma.Repo - - defp maybe_compact(%Activity{data: %{"object" => %{"id" => object_id}}} = activity) do - data = - activity.data - |> Map.put("object", object_id) - - {:ok, activity} = - Activity.change(activity, %{data: data}) - |> Repo.update() - - {:ok, activity} - end - - defp maybe_compact(%Activity{} = activity), do: {:ok, activity} - - defp activity_query(min_id, max_id) do - from( - a in Activity, - where: fragment("?->>'type' = 'Create'", a.data), - where: a.id >= ^min_id, - where: a.id < ^max_id - ) - end - - def run(_args) do - Application.ensure_all_started(:pleroma) - - max = Repo.aggregate(Activity, :max, :id) - Logger.info("Considering #{max} activities") - - chunks = 0..round(max / 100) - - Enum.each(chunks, fn i -> - min = i * 100 - max = min + 100 - - activity_query(min, max) - |> Repo.all() - |> Enum.each(&maybe_compact/1) - - IO.write(".") - end) - - Logger.info("Finished.") - end -end -- cgit v1.2.3 From 099f89367efaf4032b8e937258b2c1a90f16b047 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 18 Apr 2019 23:34:01 +0300 Subject: Replace embedded object migration with a mix task --- lib/mix/tasks/pleroma/database.ex | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/mix/tasks/pleroma/database.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex new file mode 100644 index 000000000..ce3252af5 --- /dev/null +++ b/lib/mix/tasks/pleroma/database.ex @@ -0,0 +1,45 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.Database do + alias Mix.Tasks.Pleroma.Common + use Mix.Task + + @shortdoc "A collection of database related tasks" + @moduledoc """ + A collection of database related tasks + + ## Replace embedded objects with their references + + Replaces embedded objects with references to them in the `objects` table. Only needs to be ran once. The reason why this is not a migration is because it could significantly increase the database size after being ran, however after this `VACUUM FULL` will be able to reclaim about 20% (really depends on what is in the database, your mileage may vary) of the db size before the migration. + + mix pleroma.database remove_embedded_objects + + Options: + - `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references + """ + def run(["remove_embedded_objects" | args]) do + {options, [], []} = + OptionParser.parse( + args, + strict: [ + vacuum: :boolean + ] + ) + + Common.start_pleroma() + + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;" + ) + + if Keyword.get(options, :vacuum) do + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + "vacuum full;" + ) + end + end +end -- cgit v1.2.3 From 945325013af6dde3f1da2417753bb97f55911a84 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 18 Apr 2019 23:58:59 +0300 Subject: remove query timeouts --- lib/mix/tasks/pleroma/database.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index ce3252af5..d657c1ef0 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -30,15 +30,17 @@ defmodule Mix.Tasks.Pleroma.Database do Common.start_pleroma() - Ecto.Adapters.SQL.query!( - Pleroma.Repo, - "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;" + Pleroma.Repo.query!( + "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;", + [], + timeout: :infinity ) if Keyword.get(options, :vacuum) do - Ecto.Adapters.SQL.query!( - Pleroma.Repo, - "vacuum full;" + Pleroma.Repo.query!( + "vacuum full;", + [], + timeout: :infinity ) end end -- cgit v1.2.3 From 73b8c5387b25caaf27734f7018dc4702d49af7de Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 19 Apr 2019 00:17:37 +0300 Subject: Add some logging --- lib/mix/tasks/pleroma/database.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index d657c1ef0..ab9a3a7ff 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.Database do alias Mix.Tasks.Pleroma.Common + require Logger use Mix.Task @shortdoc "A collection of database related tasks" @@ -29,6 +30,7 @@ defmodule Mix.Tasks.Pleroma.Database do ) Common.start_pleroma() + Logger.info("Removing embedded objects") Pleroma.Repo.query!( "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;", @@ -37,6 +39,8 @@ defmodule Mix.Tasks.Pleroma.Database do ) if Keyword.get(options, :vacuum) do + Logger.info("Runnning VACUUM FULL") + Pleroma.Repo.query!( "vacuum full;", [], -- cgit v1.2.3 From c26724cc5580a13d9e7e7468860eff8e49e02ba2 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Wed, 17 Apr 2019 23:54:09 +0300 Subject: Remove finmoji and add a way to download emojis in packs These packs are stored in a git repo on pleroma gitlab --- lib/mix/tasks/pleroma/emoji.ex | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 lib/mix/tasks/pleroma/emoji.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex new file mode 100644 index 000000000..ffe733617 --- /dev/null +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -0,0 +1,98 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.Emoji do + use Mix.Task + + @shortdoc "Manages Pleroma instance" + @moduledoc """ + """ + + defp fetch_manifest do + Tesla.get!("https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json").body + |> Poison.decode!() + end + + def run(["ls-packs"]) do + Application.ensure_all_started(:hackney) + + manifest = fetch_manifest() + + Enum.each(manifest, fn {name, info} -> + to_print = [ + {"Name", name}, + {"Homepage", info["homepage"]}, + {"Description", info["description"]}, + {"License", info["license"]}, + {"Source", info["src"]} + ] + + for {param, value} <- to_print do + IO.puts(IO.ANSI.format([:bright, param, :normal, ": ", value])) + end + end) + end + + def run(["get-pack", pack_name]) do + Application.ensure_all_started(:hackney) + + manifest = fetch_manifest() + + if Map.has_key?(manifest, pack_name) do + pack = manifest[pack_name] + src_url = pack["src"] + + IO.puts( + IO.ANSI.format([ + "Downloading pack ", + :bright, + pack_name, + :normal, + " from ", + :underline, + src_url + ]) + ) + + binary_archive = Tesla.get!(src_url).body + + IO.puts("Unpacking #{pack_name} pack") + + static_path = Path.join(:code.priv_dir(:pleroma), "static") + + pack_path = + Path.join([ + static_path, + Pleroma.Config.get!([:instance, :static_dir]), + "emoji", + pack_name + ]) + + files_to_unzip = + Enum.map( + pack["files"], + fn {_, f} -> to_charlist(f) end + ) + + {:ok, _} = + :zip.unzip(binary_archive, + cwd: pack_path, + file_list: files_to_unzip + ) + + IO.puts("Wriring emoji.txt for the #{pack_name} pack") + + emoji_txt_str = + Enum.map( + pack["files"], + fn {shortcode, path} -> "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" end + ) + |> Enum.join("\n") + + File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str) + else + IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"])) + end + end +end -- cgit v1.2.3 From 21b39c54a36c265fee89a9c2f2312ad925f82263 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 10:57:20 +0300 Subject: Allow using a custom manfest and getting multiple packs at once A custom manifest can be provided as a command-line options --manifest/-m --- lib/mix/tasks/pleroma/emoji.ex | 143 ++++++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 60 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index ffe733617..902bddc65 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -9,15 +9,31 @@ defmodule Mix.Tasks.Pleroma.Emoji do @moduledoc """ """ - defp fetch_manifest do - Tesla.get!("https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json").body - |> Poison.decode!() + @default_manifest "https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json" + + defp fetch_manifest(from) do + Tesla.get!(from).body |> Poison.decode!() + end + + defp parse_global_opts(args) do + OptionParser.parse( + args, + strict: [ + manifest: :string + ], + aliases: [ + m: :manifest + ] + ) end - def run(["ls-packs"]) do + def run(["ls-packs" | args]) do Application.ensure_all_started(:hackney) - manifest = fetch_manifest() + {options, [], []} = parse_global_opts(args) + + manifest = + fetch_manifest(if options[:manifest], do: options[:manifest], else: @default_manifest) Enum.each(manifest, fn {name, info} -> to_print = [ @@ -34,65 +50,72 @@ defmodule Mix.Tasks.Pleroma.Emoji do end) end - def run(["get-pack", pack_name]) do + def run(["get-packs" | args]) do Application.ensure_all_started(:hackney) - manifest = fetch_manifest() - - if Map.has_key?(manifest, pack_name) do - pack = manifest[pack_name] - src_url = pack["src"] - - IO.puts( - IO.ANSI.format([ - "Downloading pack ", - :bright, - pack_name, - :normal, - " from ", - :underline, - src_url - ]) - ) - - binary_archive = Tesla.get!(src_url).body - - IO.puts("Unpacking #{pack_name} pack") - - static_path = Path.join(:code.priv_dir(:pleroma), "static") - - pack_path = - Path.join([ - static_path, - Pleroma.Config.get!([:instance, :static_dir]), - "emoji", - pack_name - ]) - - files_to_unzip = - Enum.map( - pack["files"], - fn {_, f} -> to_charlist(f) end + {options, pack_names, []} = parse_global_opts(args) + + manifest = + fetch_manifest(if options[:manifest], do: options[:manifest], else: @default_manifest) + + for pack_name <- pack_names do + if Map.has_key?(manifest, pack_name) do + pack = manifest[pack_name] + src_url = pack["src"] + + IO.puts( + IO.ANSI.format([ + "Downloading ", + :bright, + pack_name, + :normal, + " from ", + :underline, + src_url + ]) ) - {:ok, _} = - :zip.unzip(binary_archive, - cwd: pack_path, - file_list: files_to_unzip - ) - - IO.puts("Wriring emoji.txt for the #{pack_name} pack") - - emoji_txt_str = - Enum.map( - pack["files"], - fn {shortcode, path} -> "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" end - ) - |> Enum.join("\n") - - File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str) - else - IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"])) + binary_archive = Tesla.get!(src_url).body + + IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name])) + + static_path = Path.join(:code.priv_dir(:pleroma), "static") + + pack_path = + Path.join([ + static_path, + Pleroma.Config.get!([:instance, :static_dir]), + "emoji", + pack_name + ]) + + files_to_unzip = + Enum.map( + pack["files"], + fn {_, f} -> to_charlist(f) end + ) + + {:ok, _} = + :zip.unzip(binary_archive, + cwd: pack_path, + file_list: files_to_unzip + ) + + IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name])) + + emoji_txt_str = + Enum.map( + pack["files"], + fn {shortcode, path} -> + "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" + end + ) + |> Enum.join("\n") + + File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str) + else + IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"])) + end end end end -- cgit v1.2.3 From af5494f942636bc6d2baa2638502974ed8cb7846 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 15:32:18 +0300 Subject: Separate emoji pack file lists in a different file The file should be in the same directory as the manifest file --- lib/mix/tasks/pleroma/emoji.ex | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 902bddc65..526b09b11 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -55,8 +55,9 @@ defmodule Mix.Tasks.Pleroma.Emoji do {options, pack_names, []} = parse_global_opts(args) - manifest = - fetch_manifest(if options[:manifest], do: options[:manifest], else: @default_manifest) + manifest_url = if options[:manifest], do: options[:manifest], else: @default_manifest + + manifest = fetch_manifest(manifest_url) for pack_name <- pack_names do if Map.has_key?(manifest, pack_name) do @@ -77,6 +78,23 @@ defmodule Mix.Tasks.Pleroma.Emoji do binary_archive = Tesla.get!(src_url).body + # The url specified in files should be in the same directory + files_url = Path.join(Path.dirname(manifest_url), pack["files"]) + + IO.puts( + IO.ANSI.format([ + "Fetching the file list for ", + :bright, + pack_name, + :normal, + " from ", + :underline, + files_url + ]) + ) + + files = Tesla.get!(files_url).body |> Poison.decode!() + IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name])) static_path = Path.join(:code.priv_dir(:pleroma), "static") @@ -91,7 +109,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do files_to_unzip = Enum.map( - pack["files"], + files, fn {_, f} -> to_charlist(f) end ) @@ -105,7 +123,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do emoji_txt_str = Enum.map( - pack["files"], + files, fn {shortcode, path} -> "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" end -- cgit v1.2.3 From 06db3ee1a8a443316196e6d8f55f4d5fc0cac694 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 15:46:07 +0300 Subject: Add MD5 verification for emoji pack source --- lib/mix/tasks/pleroma/emoji.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 526b09b11..29c5d0c93 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -77,6 +77,16 @@ defmodule Mix.Tasks.Pleroma.Emoji do ) binary_archive = Tesla.get!(src_url).body + archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() + + md5_status_text = ["MD5 of ", :bright, pack_name, :normal, " source file is ", :bright] + if archive_md5 == String.upcase(pack["src_md5"]) do + IO.puts(IO.ANSI.format(md5_status_text ++ [:green, "OK"])) + else + IO.puts(IO.ANSI.format(md5_status_text ++ [:red, "BAD"])) + + raise "Bad MD5 for #{pack_name}" + end # The url specified in files should be in the same directory files_url = Path.join(Path.dirname(manifest_url), pack["files"]) -- cgit v1.2.3 From c5b7286b5f3fd2a3eb91eea74bebb684575682bd Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 15:47:49 +0300 Subject: Move helper functions of emoji manager task down in the file --- lib/mix/tasks/pleroma/emoji.ex | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 29c5d0c93..71d08411f 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -11,22 +11,6 @@ defmodule Mix.Tasks.Pleroma.Emoji do @default_manifest "https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json" - defp fetch_manifest(from) do - Tesla.get!(from).body |> Poison.decode!() - end - - defp parse_global_opts(args) do - OptionParser.parse( - args, - strict: [ - manifest: :string - ], - aliases: [ - m: :manifest - ] - ) - end - def run(["ls-packs" | args]) do Application.ensure_all_started(:hackney) @@ -146,4 +130,20 @@ defmodule Mix.Tasks.Pleroma.Emoji do end end end + + defp fetch_manifest(from) do + Tesla.get!(from).body |> Poison.decode!() + end + + defp parse_global_opts(args) do + OptionParser.parse( + args, + strict: [ + manifest: :string + ], + aliases: [ + m: :manifest + ] + ) + end end -- cgit v1.2.3 From eff725c3af4537b2d993f85a236636cd5d5e17d0 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 17:02:22 +0300 Subject: Add a task to generate emoji packs --- lib/mix/tasks/pleroma/emoji.ex | 103 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 71d08411f..2126588b1 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -131,6 +131,109 @@ defmodule Mix.Tasks.Pleroma.Emoji do end end + def run(["gen-pack", src]) do + Application.ensure_all_started(:hackney) + + proposed_name = Path.basename(src) |> Path.rootname() + name = String.trim(IO.gets("Pack name [#{proposed_name}]: ")) + # If there's no name, use the default one + name = if String.length(name) > 0, do: name, else: proposed_name + + license = String.trim(IO.gets("License: ")) + homepage = String.trim(IO.gets("Homepage: ")) + description = String.trim(IO.gets("Description: ")) + + proposed_files_name = "#{name}.json" + files_name = String.trim(IO.gets("Save file list to [#{proposed_files_name}]: ")) + files_name = if String.length(files_name) > 0, do: files_name, else: proposed_files_name + + default_exts = [".png", ".gif"] + default_exts_str = Enum.join(default_exts, " ") + exts = + String.trim(IO.gets("Emoji file extensions (separated with spaces) [#{default_exts_str}]: ")) + exts = if String.length(exts) > 0 do + String.split(exts, " ") |> Enum.filter(fn e -> (e |> String.trim() |> String.length()) > 0 end) + else + default_exts + end + + IO.puts "Downloading the pack and generating MD5" + + binary_archive = Tesla.get!(src).body + archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() + + IO.puts "MD5 is #{archive_md5}" + + pack_json = %{ + name => %{ + license: license, + homepage: homepage, + description: description, + src: src, + src_md5: archive_md5, + files: files_name + } + } + + tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}") + {:ok, _} = + :zip.unzip( + binary_archive, + cwd: tmp_pack_dir + ) + + emoji_map = + find_all_emoji(tmp_pack_dir, exts) |> + Enum.map(&Path.relative_to(&1, tmp_pack_dir)) |> + Enum.map(fn f -> {f |> Path.basename() |> Path.rootname(), f} end) |> + Enum.into(%{}) + + File.write!(files_name, Poison.encode!(emoji_map, pretty: true)) + + IO.puts """ + + #{files_name} has been created and contains the list of all found emojis in the pack. + Please review the files in the remove those not needed. + """ + + if File.exists?("index.json") do + existing_data = File.read!("index.json") |> Poison.decode!() + + File.write!( + "index.json", + Poison.encode!( + Map.merge( + existing_data, + pack_json + ), + pretty: true + ) + ) + + IO.puts "index.json file has been update with the #{name} pack" + else + File.write!("index.json", Poison.encode!(pack_json, pretty: true)) + + IO.puts "index.json has been created with the #{name} pack" + end + + end + + defp find_all_emoji(dir, exts) do + Enum.reduce( + File.ls!(dir), + [], + fn f, acc -> + filepath = Path.join(dir, f) + if File.dir?(filepath) do + acc ++ find_all_emoji(filepath, exts) + else + acc ++ [filepath] + end + end + ) |> Enum.filter(fn f -> Path.extname(f) in exts end) + end + defp fetch_manifest(from) do Tesla.get!(from).body |> Poison.decode!() end -- cgit v1.2.3 From a141f0807bc84868fb84e3d628ab8f99f429d5c0 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 18:04:02 +0300 Subject: Assume packs without emoji.txt only have emoji pictures, unhardcode unhardcode: remove hardcoded /instance/static and actually use the config option as it is used in other places. packs without emoji.txt: these are now assumed to have .png files that are all emojis, their names are used as shortcodes --- lib/mix/tasks/pleroma/emoji.ex | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 2126588b1..4fb383b61 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -115,11 +115,14 @@ defmodule Mix.Tasks.Pleroma.Emoji do IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name])) + common_pack_path = Path.join([ + "/", Pleroma.Config.get!([:instance, :static_dir]), "emoji", pack_name + ]) emoji_txt_str = Enum.map( files, fn {shortcode, path} -> - "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}" + "#{shortcode}, #{Path.join(common_pack_path, path)}" end ) |> Enum.join("\n") @@ -182,11 +185,8 @@ defmodule Mix.Tasks.Pleroma.Emoji do cwd: tmp_pack_dir ) - emoji_map = - find_all_emoji(tmp_pack_dir, exts) |> - Enum.map(&Path.relative_to(&1, tmp_pack_dir)) |> - Enum.map(fn f -> {f |> Path.basename() |> Path.rootname(), f} end) |> - Enum.into(%{}) + emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts) + File.write!(files_name, Poison.encode!(emoji_map, pretty: true)) @@ -219,21 +219,6 @@ defmodule Mix.Tasks.Pleroma.Emoji do end - defp find_all_emoji(dir, exts) do - Enum.reduce( - File.ls!(dir), - [], - fn f, acc -> - filepath = Path.join(dir, f) - if File.dir?(filepath) do - acc ++ find_all_emoji(filepath, exts) - else - acc ++ [filepath] - end - end - ) |> Enum.filter(fn f -> Path.extname(f) in exts end) - end - defp fetch_manifest(from) do Tesla.get!(from).body |> Poison.decode!() end -- cgit v1.2.3 From aaaa428512db8ace56ca5ab7ebf1488d64ac5e35 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 18:09:43 +0300 Subject: mix format --- lib/mix/tasks/pleroma/emoji.ex | 45 ++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 4fb383b61..fed3dcb40 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -64,6 +64,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() md5_status_text = ["MD5 of ", :bright, pack_name, :normal, " source file is ", :bright] + if archive_md5 == String.upcase(pack["src_md5"]) do IO.puts(IO.ANSI.format(md5_status_text ++ [:green, "OK"])) else @@ -115,9 +116,14 @@ defmodule Mix.Tasks.Pleroma.Emoji do IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name])) - common_pack_path = Path.join([ - "/", Pleroma.Config.get!([:instance, :static_dir]), "emoji", pack_name - ]) + common_pack_path = + Path.join([ + "/", + Pleroma.Config.get!([:instance, :static_dir]), + "emoji", + pack_name + ]) + emoji_txt_str = Enum.map( files, @@ -152,20 +158,26 @@ defmodule Mix.Tasks.Pleroma.Emoji do default_exts = [".png", ".gif"] default_exts_str = Enum.join(default_exts, " ") + exts = - String.trim(IO.gets("Emoji file extensions (separated with spaces) [#{default_exts_str}]: ")) - exts = if String.length(exts) > 0 do - String.split(exts, " ") |> Enum.filter(fn e -> (e |> String.trim() |> String.length()) > 0 end) - else - default_exts - end + String.trim( + IO.gets("Emoji file extensions (separated with spaces) [#{default_exts_str}]: ") + ) - IO.puts "Downloading the pack and generating MD5" + exts = + if String.length(exts) > 0 do + String.split(exts, " ") + |> Enum.filter(fn e -> e |> String.trim() |> String.length() > 0 end) + else + default_exts + end + + IO.puts("Downloading the pack and generating MD5") binary_archive = Tesla.get!(src).body archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() - IO.puts "MD5 is #{archive_md5}" + IO.puts("MD5 is #{archive_md5}") pack_json = %{ name => %{ @@ -179,6 +191,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do } tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}") + {:ok, _} = :zip.unzip( binary_archive, @@ -187,14 +200,13 @@ defmodule Mix.Tasks.Pleroma.Emoji do emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts) - File.write!(files_name, Poison.encode!(emoji_map, pretty: true)) - IO.puts """ + IO.puts(""" #{files_name} has been created and contains the list of all found emojis in the pack. Please review the files in the remove those not needed. - """ + """) if File.exists?("index.json") do existing_data = File.read!("index.json") |> Poison.decode!() @@ -210,13 +222,12 @@ defmodule Mix.Tasks.Pleroma.Emoji do ) ) - IO.puts "index.json file has been update with the #{name} pack" + IO.puts("index.json file has been update with the #{name} pack") else File.write!("index.json", Poison.encode!(pack_json, pretty: true)) - IO.puts "index.json has been created with the #{name} pack" + IO.puts("index.json has been created with the #{name} pack") end - end defp fetch_manifest(from) do -- cgit v1.2.3 From 98d4b3de53a5eaf412e3b200d4f0ed04c9c4622d Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 20:06:59 +0300 Subject: Treat the manifest path as a file if it doesn't start with http --- lib/mix/tasks/pleroma/emoji.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index fed3dcb40..9cb6fb88d 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -231,7 +231,13 @@ defmodule Mix.Tasks.Pleroma.Emoji do end defp fetch_manifest(from) do - Tesla.get!(from).body |> Poison.decode!() + Poison.decode!( + if String.starts_with?(from, "http") do + Tesla.get!(from).body + else + File.read!(from) + end + ) end defp parse_global_opts(args) do -- cgit v1.2.3 From 9bd5e2dec9ce0b23f287b3ea6ad375280d92bb7b Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 18 Apr 2019 20:48:57 +0300 Subject: Make emoji default_manifest a config option --- lib/mix/tasks/pleroma/emoji.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 9cb6fb88d..8261c2122 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do @moduledoc """ """ - @default_manifest "https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json" + @default_manifest Pleroma.Config.get!([:emoji, :default_manifest]) def run(["ls-packs" | args]) do Application.ensure_all_started(:hackney) -- cgit v1.2.3 From 1e311d6662812377f2ed8c4483754d5876d82631 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 20 Apr 2019 00:22:11 +0300 Subject: Add a newline at the end of pack in ls-packs --- lib/mix/tasks/pleroma/emoji.ex | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 8261c2122..f4da183ad 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -31,6 +31,9 @@ defmodule Mix.Tasks.Pleroma.Emoji do for {param, value} <- to_print do IO.puts(IO.ANSI.format([:bright, param, :normal, ": ", value])) end + + # A newline + IO.puts("") end) end -- cgit v1.2.3 From 31cff7dbcaf7d8087fb2c8eef2b949820fd5767c Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 20 Apr 2019 10:57:31 +0300 Subject: Document the pleroma.emoji task --- lib/mix/tasks/pleroma/emoji.ex | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index f4da183ad..0a1bf24e2 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -5,8 +5,50 @@ defmodule Mix.Tasks.Pleroma.Emoji do use Mix.Task - @shortdoc "Manages Pleroma instance" + @shortdoc "Manages emoji packs" @moduledoc """ + Manages emoji packs + + ## ls-packs + + mix pleroma.emoji ls-packs [OPTION...] + + Lists the emoji packs and metadata specified in the manifest. + + ### Options + + - `-m, --manifest PATH/URL` - path to a custom manifest, it can either be an URL + starting with `http`, in that case the manifest will be fetched from that address, + or a local path + + ## get-packs + + mix pleroma.emoji get-packs [OPTION...] PACKS + + Fetches, verifies and installs the specified PACKS from the manifest into + the `STATIC-DIR/emoji/PACK-NAME + + ### Options + + - `-m, --manifest PATH/URL` - same as ls-packs + + ## gen-pack + + mix pleroma.emoji gen-pack PACK-URL + + Creates a new manifest entry and a file list from the specified remote pack file. + Currently, only .zip archives are recognized as remote pack files and packs are therefore + assumed to be zip archives. This command is intended to run interactively and + will first ask you some basic questions about the pack, then download the remote + file and generate an MD5 signature for it, then generate an emoji file list for you. + + The manifest entry will either be written to a newly created `index.json` file or appended to the existing one, + *replacing* the old pack with the same name if it was in the file previously. + + The file list will be written to the file specified previously, *replacing* that file. + You _should_ check that the file list doesn't contain anything you don't need in the pack, that is, + anything that is not an emoji (the whole pack is downloaded, but only emoji files are extracted). + """ @default_manifest Pleroma.Config.get!([:emoji, :default_manifest]) -- cgit v1.2.3 From 53a3e61016592b25cca4876c4f8f7be8aa6efa9b Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 20 Apr 2019 15:06:56 +0300 Subject: Fix priv/static/instance/static to be just instance/static It was a misunderstanding --- lib/mix/tasks/pleroma/emoji.ex | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 0a1bf24e2..02cfaa774 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -137,11 +137,8 @@ defmodule Mix.Tasks.Pleroma.Emoji do IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name])) - static_path = Path.join(:code.priv_dir(:pleroma), "static") - pack_path = Path.join([ - static_path, Pleroma.Config.get!([:instance, :static_dir]), "emoji", pack_name @@ -161,19 +158,12 @@ defmodule Mix.Tasks.Pleroma.Emoji do IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name])) - common_pack_path = - Path.join([ - "/", - Pleroma.Config.get!([:instance, :static_dir]), - "emoji", - pack_name - ]) - emoji_txt_str = Enum.map( files, fn {shortcode, path} -> - "#{shortcode}, #{Path.join(common_pack_path, path)}" + emojo_path = Path.join("/emoji/#{pack_name}", path) + "#{shortcode}, #{emojo_path}" end ) |> Enum.join("\n") -- cgit v1.2.3 From d5c0fd35e1486040d4c57ba18942b2a228d6a4a8 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 21 Apr 2019 22:16:46 +0300 Subject: Wrap the docstrings to 70 characters --- lib/mix/tasks/pleroma/emoji.ex | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 02cfaa774..92d62b6de 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -17,16 +17,16 @@ defmodule Mix.Tasks.Pleroma.Emoji do ### Options - - `-m, --manifest PATH/URL` - path to a custom manifest, it can either be an URL - starting with `http`, in that case the manifest will be fetched from that address, - or a local path + - `-m, --manifest PATH/URL` - path to a custom manifest, it can + either be an URL starting with `http`, in that case the + manifest will be fetched from that address, or a local path ## get-packs mix pleroma.emoji get-packs [OPTION...] PACKS - Fetches, verifies and installs the specified PACKS from the manifest into - the `STATIC-DIR/emoji/PACK-NAME + Fetches, verifies and installs the specified PACKS from the + manifest into the `STATIC-DIR/emoji/PACK-NAME ### Options @@ -36,19 +36,23 @@ defmodule Mix.Tasks.Pleroma.Emoji do mix pleroma.emoji gen-pack PACK-URL - Creates a new manifest entry and a file list from the specified remote pack file. - Currently, only .zip archives are recognized as remote pack files and packs are therefore - assumed to be zip archives. This command is intended to run interactively and - will first ask you some basic questions about the pack, then download the remote - file and generate an MD5 signature for it, then generate an emoji file list for you. - - The manifest entry will either be written to a newly created `index.json` file or appended to the existing one, - *replacing* the old pack with the same name if it was in the file previously. - - The file list will be written to the file specified previously, *replacing* that file. - You _should_ check that the file list doesn't contain anything you don't need in the pack, that is, - anything that is not an emoji (the whole pack is downloaded, but only emoji files are extracted). - + Creates a new manifest entry and a file list from the specified + remote pack file. Currently, only .zip archives are recognized + as remote pack files and packs are therefore assumed to be zip + archives. This command is intended to run interactively and will + first ask you some basic questions about the pack, then download + the remote file and generate an MD5 signature for it, then + generate an emoji file list for you. + + The manifest entry will either be written to a newly created + `index.json` file or appended to the existing one, *replacing* + the old pack with the same name if it was in the file previously. + + The file list will be written to the file specified previously, + *replacing* that file. You _should_ check that the file list doesn't + contain anything you don't need in the pack, that is, anything that is + not an emoji (the whole pack is downloaded, but only emoji files + are extracted). """ @default_manifest Pleroma.Config.get!([:emoji, :default_manifest]) -- cgit v1.2.3 From 153f5375a6fa7ed3ae78a921acc87b1fb025aba9 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 21 Apr 2019 22:19:19 +0300 Subject: Replace MD5 with SHA256 for emoji pack verification --- lib/mix/tasks/pleroma/emoji.ex | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 92d62b6de..2754dd876 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -41,7 +41,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do as remote pack files and packs are therefore assumed to be zip archives. This command is intended to run interactively and will first ask you some basic questions about the pack, then download - the remote file and generate an MD5 signature for it, then + the remote file and generate an SHA256 checksum for it, then generate an emoji file list for you. The manifest entry will either be written to a newly created @@ -110,16 +110,16 @@ defmodule Mix.Tasks.Pleroma.Emoji do ) binary_archive = Tesla.get!(src_url).body - archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() + archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16() - md5_status_text = ["MD5 of ", :bright, pack_name, :normal, " source file is ", :bright] + sha_status_text = ["SHA256 of ", :bright, pack_name, :normal, " source file is ", :bright] - if archive_md5 == String.upcase(pack["src_md5"]) do - IO.puts(IO.ANSI.format(md5_status_text ++ [:green, "OK"])) + if archive_sha == String.upcase(pack["src_sha256"]) do + IO.puts(IO.ANSI.format(sha_status_text ++ [:green, "OK"])) else - IO.puts(IO.ANSI.format(md5_status_text ++ [:red, "BAD"])) + IO.puts(IO.ANSI.format(sha_status_text ++ [:red, "BAD"])) - raise "Bad MD5 for #{pack_name}" + raise "Bad SHA256 for #{pack_name}" end # The url specified in files should be in the same directory @@ -211,12 +211,12 @@ defmodule Mix.Tasks.Pleroma.Emoji do default_exts end - IO.puts("Downloading the pack and generating MD5") + IO.puts("Downloading the pack and generating SHA256") binary_archive = Tesla.get!(src).body - archive_md5 = :crypto.hash(:md5, binary_archive) |> Base.encode16() + archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16() - IO.puts("MD5 is #{archive_md5}") + IO.puts("SHA256 is #{archive_sha}") pack_json = %{ name => %{ @@ -224,7 +224,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do homepage: homepage, description: description, src: src, - src_md5: archive_md5, + src_sha256: archive_sha, files: files_name } } -- cgit v1.2.3 From b9cdf6d3b9940fded7d6be9f8771fd9c211afdd4 Mon Sep 17 00:00:00 2001 From: Egor Date: Mon, 22 Apr 2019 07:20:43 +0000 Subject: Use `User.get_cached*` everywhere --- lib/mix/tasks/pleroma/user.ex | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 441168df2..b396ff0de 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -162,7 +162,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["rm", nickname]) do Common.start_pleroma() - with %User{local: true} = user <- User.get_by_nickname(nickname) do + with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do User.delete(user) Mix.shell().info("User #{nickname} deleted.") else @@ -174,7 +174,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["toggle_activated", nickname]) do Common.start_pleroma() - with %User{} = user <- User.get_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname(nickname) do {:ok, user} = User.deactivate(user, !user.info.deactivated) Mix.shell().info( @@ -189,7 +189,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["reset_password", nickname]) do Common.start_pleroma() - with %User{local: true} = user <- User.get_by_nickname(nickname), + with %User{local: true} = user <- User.get_cached_by_nickname(nickname), {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do Mix.shell().info("Generated password reset token for #{user.nickname}") @@ -211,14 +211,14 @@ defmodule Mix.Tasks.Pleroma.User do def run(["unsubscribe", nickname]) do Common.start_pleroma() - with %User{} = user <- User.get_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname(nickname) do Mix.shell().info("Deactivating #{user.nickname}") User.deactivate(user) {:ok, friends} = User.get_friends(user) Enum.each(friends, fn friend -> - user = User.get_by_id(user.id) + user = User.get_cached_by_id(user.id) Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}") User.unfollow(user, friend) @@ -226,7 +226,7 @@ defmodule Mix.Tasks.Pleroma.User do :timer.sleep(500) - user = User.get_by_id(user.id) + user = User.get_cached_by_id(user.id) if Enum.empty?(user.following) do Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}") @@ -250,7 +250,7 @@ defmodule Mix.Tasks.Pleroma.User do ] ) - with %User{local: true} = user <- User.get_by_nickname(nickname) do + with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do user = case Keyword.get(options, :moderator) do nil -> user @@ -277,7 +277,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["tag", nickname | tags]) do Common.start_pleroma() - with %User{} = user <- User.get_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname(nickname) do user = user |> User.tag(tags) Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}") @@ -290,7 +290,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["untag", nickname | tags]) do Common.start_pleroma() - with %User{} = user <- User.get_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname(nickname) do user = user |> User.untag(tags) Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}") @@ -379,7 +379,7 @@ defmodule Mix.Tasks.Pleroma.User do def run(["delete_activities", nickname]) do Common.start_pleroma() - with %User{local: true} = user <- User.get_by_nickname(nickname) do + with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do User.delete_user_activities(user) Mix.shell().info("User #{nickname} statuses deleted.") else -- cgit v1.2.3 From 952a4ae68e10129c49616aa45de47366ad8a81be Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 22 Apr 2019 11:02:31 +0300 Subject: Fix unclosed ` and put synopsis into a code block in pleroma.emoji mix task docs --- lib/mix/tasks/pleroma/emoji.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index 2754dd876..cced73226 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -11,7 +11,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do ## ls-packs - mix pleroma.emoji ls-packs [OPTION...] + mix pleroma.emoji ls-packs [OPTION...] Lists the emoji packs and metadata specified in the manifest. @@ -23,10 +23,10 @@ defmodule Mix.Tasks.Pleroma.Emoji do ## get-packs - mix pleroma.emoji get-packs [OPTION...] PACKS + mix pleroma.emoji get-packs [OPTION...] PACKS Fetches, verifies and installs the specified PACKS from the - manifest into the `STATIC-DIR/emoji/PACK-NAME + manifest into the `STATIC-DIR/emoji/PACK-NAME` ### Options @@ -34,7 +34,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do ## gen-pack - mix pleroma.emoji gen-pack PACK-URL + mix pleroma.emoji gen-pack PACK-URL Creates a new manifest entry and a file list from the specified remote pack file. Currently, only .zip archives are recognized -- cgit v1.2.3