1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.Emoji do
8 @shortdoc "Manages Pleroma instance"
12 @default_manifest "https://git.pleroma.social/vaartis/emoji-index/raw/master/index.json"
14 defp fetch_manifest(from) do
15 Tesla.get!(from).body |> Poison.decode!()
18 defp parse_global_opts(args) do
30 def run(["ls-packs" | args]) do
31 Application.ensure_all_started(:hackney)
33 {options, [], []} = parse_global_opts(args)
36 fetch_manifest(if options[:manifest], do: options[:manifest], else: @default_manifest)
38 Enum.each(manifest, fn {name, info} ->
41 {"Homepage", info["homepage"]},
42 {"Description", info["description"]},
43 {"License", info["license"]},
44 {"Source", info["src"]}
47 for {param, value} <- to_print do
48 IO.puts(IO.ANSI.format([:bright, param, :normal, ": ", value]))
53 def run(["get-packs" | args]) do
54 Application.ensure_all_started(:hackney)
56 {options, pack_names, []} = parse_global_opts(args)
58 manifest_url = if options[:manifest], do: options[:manifest], else: @default_manifest
60 manifest = fetch_manifest(manifest_url)
62 for pack_name <- pack_names do
63 if Map.has_key?(manifest, pack_name) do
64 pack = manifest[pack_name]
79 binary_archive = Tesla.get!(src_url).body
81 # The url specified in files should be in the same directory
82 files_url = Path.join(Path.dirname(manifest_url), pack["files"])
86 "Fetching the file list for ",
96 files = Tesla.get!(files_url).body |> Poison.decode!()
98 IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name]))
100 static_path = Path.join(:code.priv_dir(:pleroma), "static")
105 Pleroma.Config.get!([:instance, :static_dir]),
113 fn {_, f} -> to_charlist(f) end
117 :zip.unzip(binary_archive,
119 file_list: files_to_unzip
122 IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name]))
127 fn {shortcode, path} ->
128 "#{shortcode}, /instance/static/emoji/#{pack_name}/#{path}"
133 File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str)
135 IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"]))