fix file uploads, serve them properly, put behind auth wall, decrypt secret message in frontend

This commit is contained in:
2022-02-22 00:16:51 -05:00
parent cac3757723
commit 2ac596b8c8
20 changed files with 420 additions and 148 deletions

View File

@@ -51,9 +51,10 @@ defmodule Entendu.Links do
"""
def create_link(attrs \\ %{}) do
%Link{}
|> Link.changeset(attrs)
|> Repo.insert()
Ecto.Multi.new()
|> Ecto.Multi.insert(:link, Link.changeset(%Link{}, attrs))
|> Ecto.Multi.update(:link_with_file, &Link.file_changeset(&1.link, attrs))
|> Repo.transaction()
end
@doc """

View File

@@ -5,7 +5,17 @@ defmodule Entendu.Links.Link do
import Ecto.Changeset
@primary_key {:id, Ecto.UUID, autogenerate: true}
@derive {Jason.Encoder,
only: [
:burn_after_reading,
:expires,
:filename,
:filetype,
:text_content,
:file_content,
:recipient,
:service
]}
schema "links" do
field :burn_after_reading, :boolean, default: false
field :expires, :utc_datetime
@@ -30,7 +40,10 @@ defmodule Entendu.Links.Link do
:recipient,
:service
])
|> cast_attachments(attrs, [:text_content, :file_content])
end
def file_changeset(link, attrs) do
link
|> cast_attachments(attrs, [:text_content, :file_content])
end
end

View File

@@ -25,15 +25,21 @@ defmodule Entendu.UserFromAuth do
nil
end
defp emails_from_auth(%Auth{ extra: %Auth.Extra{ raw_info: %{ user: %{ "emails" => emails}}}}), do: emails
# github
defp emails_from_auth(%Auth{extra: %Auth.Extra{raw_info: %{user: %{"emails" => emails}}}}),
do: emails
defp emails_from_auth(%Auth{ info: %{ email: email }}), do: [email]
defp emails_from_auth(%Auth{info: %{email: email}}), do: [email]
defp emails_from_auth(_auth), do: []
defp basic_info(auth) do
IO.inspect(auth)
%{id: auth.uid, name: name_from_auth(auth), avatar: avatar_from_auth(auth), emails: emails_from_auth(auth)}
%{
id: auth.uid,
name: name_from_auth(auth),
avatar: avatar_from_auth(auth),
emails: emails_from_auth(auth)
}
end
defp name_from_auth(auth) do
@@ -54,6 +60,6 @@ defmodule Entendu.UserFromAuth do
def can_access?(recipient, emails) do
emails
|> Enum.any?(&( &1["verified"] == true and &1["email"] == recipient))
|> Enum.any?(&(&1["verified"] == true and &1["email"] == recipient))
end
end