diff --git a/lib/nulla/models/actor.ex b/lib/nulla/models/actor.ex
index 6eaf6d7..a4f579c 100644
--- a/lib/nulla/models/actor.ex
+++ b/lib/nulla/models/actor.ex
@@ -103,6 +103,41 @@ defmodule Nulla.Models.Actor do
|> Repo.insert()
end
+ def create_actor_minimal(username, domain, publicKeyPem) do
+ id = Snowflake.next_id()
+
+ attrs = %{
+ id: id,
+ domain: domain,
+ ap_id: "https://#{domain}/users/#{username}",
+ type: "Person",
+ following: "https://#{domain}/users/#{username}/following",
+ followers: "https://#{domain}/users/#{username}/followers",
+ inbox: "https://#{domain}/users/#{username}/inbox",
+ outbox: "https://#{domain}/users/#{username}/outbox",
+ featured: "https://#{domain}/users/#{username}/collections/featured",
+ featuredTags: "https://#{domain}/users/#{username}/collections/tags",
+ preferredUsername: username,
+ url: "https://#{domain}/@#{username}",
+ manuallyApprovesFollowers: false,
+ discoverable: true,
+ indexable: true,
+ published: DateTime.utc_now(),
+ memorial: false,
+ publicKey:
+ Jason.OrderedObject.new(
+ id: "https://#{domain}/users/#{username}#main-key",
+ owner: "https://#{domain}/users/#{username}",
+ publicKeyPem: publicKeyPem
+ ),
+ endpoints: Jason.OrderedObject.new(sharedInbox: "https://#{domain}/inbox")
+ }
+
+ %__MODULE__{}
+ |> changeset(attrs)
+ |> Repo.insert()
+ end
+
def get_actor(username, domain) do
Repo.get_by(__MODULE__, preferredUsername: username, domain: domain)
end
diff --git a/lib/nulla/models/user.ex b/lib/nulla/models/user.ex
index 29f3a8e..4bb596e 100644
--- a/lib/nulla/models/user.ex
+++ b/lib/nulla/models/user.ex
@@ -43,7 +43,9 @@ defmodule Nulla.Models.User do
|> Repo.insert()
end
- def get_user_by_username(username), do: Repo.get_by(User, username: username)
+ def get_user(by) when is_map(by) or is_list(by) do
+ Repo.get_by(User, by)
+ end
def get_total_users_count() do
Repo.aggregate(from(u in User), :count, :id)
diff --git a/lib/nulla/uploader.ex b/lib/nulla/uploader.ex
index bb18bf2..a517600 100644
--- a/lib/nulla/uploader.ex
+++ b/lib/nulla/uploader.ex
@@ -5,12 +5,7 @@ defmodule Nulla.Uploader do
@upload_base "priv/static"
@upload_prefix "system"
- def upload(
- %Plug.Upload{path: temp_path, filename: original_name},
- dir,
- description,
- domain
- ) do
+ def upload(%Plug.Upload{path: temp_path, filename: original_name}, uploadType, name, domain) do
{:ok, binary} = File.read(temp_path)
ext = Path.extname(original_name)
mimetype = MIME.type(ext)
@@ -23,14 +18,54 @@ defmodule Nulla.Uploader do
true -> "Document"
end
+ {width, height} =
+ cond do
+ mimetype =~ "image" or "video" ->
+ {output, 0} =
+ System.cmd("ffprobe", [
+ "-v",
+ "error",
+ "-select_streams",
+ "v:0",
+ "-show_entries",
+ "stream=width,height",
+ "-of",
+ "default=noprint_wrappers=1",
+ temp_path
+ ])
+
+ parsed_width =
+ Regex.run(~r/width=(\d+)/, output)
+ |> List.last()
+ |> String.to_integer()
+
+ parsed_height =
+ Regex.run(~r/height=(\d+)/, output)
+ |> List.last()
+ |> String.to_integer()
+
+ {parsed_width, parsed_height}
+
+ true ->
+ {nil, nil}
+ end
+
filename = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower) <> ext
media_attachment_id = Snowflake.next_id()
+ dirs =
+ cond do
+ uploadType == :avatar -> "accounts/avatars"
+ uploadType == :header -> "accounts/headers"
+ uploadType == :attachment -> "media_attachments/files"
+ uploadType == :emoji -> "custom_emojis/images"
+ end
+
relative_path =
Path.join([
@upload_prefix,
- dir,
+ dirs,
partition_id(media_attachment_id),
"original",
filename
@@ -47,9 +82,9 @@ defmodule Nulla.Uploader do
type: type,
mediaType: mimetype,
url: "https://#{domain}/#{relative_path}",
- name: description,
- width: 1,
- height: 1
+ name: name,
+ width: width,
+ height: height
})
end
diff --git a/lib/nulla_web/components/templates.ex b/lib/nulla_web/components/templates.ex
index be2365a..e8318f3 100644
--- a/lib/nulla_web/components/templates.ex
+++ b/lib/nulla_web/components/templates.ex
@@ -4,12 +4,6 @@ defmodule NullaWeb.PageHTML do
embed_templates "templates/page/*"
end
-defmodule NullaWeb.AuthHTML do
- use NullaWeb, :html
-
- embed_templates "templates/auth/*"
-end
-
defmodule NullaWeb.ActorHTML do
use NullaWeb, :html
diff --git a/lib/nulla_web/components/templates/page/home.html.heex b/lib/nulla_web/components/templates/page/home.html.heex
index e69de29..2d928c6 100644
--- a/lib/nulla_web/components/templates/page/home.html.heex
+++ b/lib/nulla_web/components/templates/page/home.html.heex
@@ -0,0 +1,3 @@
+
+ <.flash_group flash={@flash} />
+
diff --git a/lib/nulla_web/components/templates/auth/sign_in.html.heex b/lib/nulla_web/components/templates/page/sign_in.html.heex
similarity index 82%
rename from lib/nulla_web/components/templates/auth/sign_in.html.heex
rename to lib/nulla_web/components/templates/page/sign_in.html.heex
index 1cdbb55..33ee7da 100644
--- a/lib/nulla_web/components/templates/auth/sign_in.html.heex
+++ b/lib/nulla_web/components/templates/page/sign_in.html.heex
@@ -1,5 +1,8 @@
+ <.flash_group flash={@flash} />
+