1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-19 11:29:17 +00:00
akkoma/lib/pleroma/upload.ex

30 lines
719 B
Elixir
Raw Normal View History

2017-03-29 00:39:01 +01:00
defmodule Pleroma.Upload do
def store(%Plug.Upload{} = file) do
uuid = Ecto.UUID.generate
upload_folder = Path.join(upload_path(), uuid)
File.mkdir_p!(upload_folder)
result_file = Path.join(upload_folder, file.filename)
File.cp!(file.path, result_file)
%{
"type" => "Image",
2017-03-30 15:08:23 +01:00
"url" => [%{
"type" => "Link",
"mediaType" => file.content_type,
"href" => url_for(Path.join(uuid, file.filename))
}],
2017-03-29 00:39:01 +01:00
"name" => file.filename,
"uuid" => uuid
}
end
defp upload_path do
Application.get_env(:pleroma, Pleroma.Upload)
|> Keyword.fetch!(:uploads)
end
defp url_for(file) do
2017-03-30 13:32:36 +01:00
"#{Pleroma.Web.base_url()}/media/#{file}"
2017-03-29 00:39:01 +01:00
end
end