Fix some typespecs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
714e9216c1
commit
83f2880dd9
@ -1,7 +1,7 @@
|
|||||||
defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
|
defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Follower, Member, MemberRole}
|
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||||
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission, Relay}
|
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission, Relay}
|
||||||
alias Mobilizon.Federation.ActivityPub.Types.Entity
|
alias Mobilizon.Federation.ActivityPub.Types.Entity
|
||||||
alias Mobilizon.Federation.ActivityStream
|
alias Mobilizon.Federation.ActivityStream
|
||||||
@ -244,7 +244,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
|
|||||||
Actor.t(),
|
Actor.t(),
|
||||||
ActivityStreams.t(),
|
ActivityStreams.t(),
|
||||||
Member.t(),
|
Member.t(),
|
||||||
MemberRole.t()
|
atom()
|
||||||
) ::
|
) ::
|
||||||
{:ok, ActivityStreams.t(), Member.t()}
|
{:ok, ActivityStreams.t(), Member.t()}
|
||||||
defp approve_if_default_role_is_member(
|
defp approve_if_default_role_is_member(
|
||||||
|
@ -3,7 +3,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
|||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events, as: EventsManager
|
alias Mobilizon.Events, as: EventsManager
|
||||||
alias Mobilizon.Events.{Event, Participant, ParticipantRole}
|
alias Mobilizon.Events.{Event, Participant}
|
||||||
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission}
|
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission}
|
||||||
alias Mobilizon.Federation.ActivityPub.Types.Entity
|
alias Mobilizon.Federation.ActivityPub.Types.Entity
|
||||||
alias Mobilizon.Federation.ActivityStream
|
alias Mobilizon.Federation.ActivityStream
|
||||||
@ -191,7 +191,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
|||||||
Event.t(),
|
Event.t(),
|
||||||
ActivityStreams.t(),
|
ActivityStreams.t(),
|
||||||
Participant.t(),
|
Participant.t(),
|
||||||
ParticipantRole.t()
|
atom()
|
||||||
) :: {:ok, ActivityStreams.t(), Participant.t()} | {:accept, any()}
|
) :: {:ok, ActivityStreams.t(), Participant.t()} | {:accept, any()}
|
||||||
defp approve_if_default_role_is_participant(event, activity_data, participant, role) do
|
defp approve_if_default_role_is_participant(event, activity_data, participant, role) do
|
||||||
case event do
|
case event do
|
||||||
@ -217,7 +217,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), ParticipantRole.t(), map()) ::
|
@spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), atom(), map()) ::
|
||||||
{:accept, any} | {:ok, ActivityStreams.t(), Participant.t()}
|
{:accept, any} | {:ok, ActivityStreams.t(), Participant.t()}
|
||||||
defp do_approve(event, activity_data, participant, role, additionnal) do
|
defp do_approve(event, activity_data, participant, role, additionnal) do
|
||||||
cond do
|
cond do
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
defmodule Mobilizon.Federation.ActivityPub.Types.Members do
|
defmodule Mobilizon.Federation.ActivityPub.Types.Members do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Member, MemberRole}
|
alias Mobilizon.Actors.{Actor, Member}
|
||||||
alias Mobilizon.Federation.ActivityPub.Actions
|
alias Mobilizon.Federation.ActivityPub.Actions
|
||||||
alias Mobilizon.Federation.ActivityStream
|
alias Mobilizon.Federation.ActivityStream
|
||||||
alias Mobilizon.Federation.ActivityStream.Convertible
|
alias Mobilizon.Federation.ActivityStream.Convertible
|
||||||
@ -89,8 +89,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Members do
|
|||||||
@spec check_admins_left?(
|
@spec check_admins_left?(
|
||||||
String.t() | integer,
|
String.t() | integer,
|
||||||
String.t() | integer,
|
String.t() | integer,
|
||||||
MemberRole.t(),
|
atom(),
|
||||||
MemberRole.t()
|
atom()
|
||||||
) :: boolean
|
) :: boolean
|
||||||
defp check_admins_left?(member_id, group_id, current_role, updated_role) do
|
defp check_admins_left?(member_id, group_id, current_role, updated_role) do
|
||||||
Actors.is_only_administrator?(member_id, group_id) && current_role == :administrator &&
|
Actors.is_only_administrator?(member_id, group_id) && current_role == :administrator &&
|
||||||
|
@ -22,7 +22,7 @@ defmodule Mobilizon.GraphQL.API.Reports do
|
|||||||
@doc """
|
@doc """
|
||||||
Update the state of a report
|
Update the state of a report
|
||||||
"""
|
"""
|
||||||
@spec update_report_status(Actor.t(), Report.t(), ReportStatus.t()) ::
|
@spec update_report_status(Actor.t(), Report.t(), atom()) ::
|
||||||
{:ok, Report.t()} | {:error, Ecto.Changeset.t() | String.t()}
|
{:ok, Report.t()} | {:error, Ecto.Changeset.t() | String.t()}
|
||||||
def update_report_status(%Actor{} = actor, %Report{} = report, state) do
|
def update_report_status(%Actor{} = actor, %Report{} = report, state) do
|
||||||
if ReportStatus.valid_value?(state) do
|
if ReportStatus.valid_value?(state) do
|
||||||
|
@ -4,7 +4,7 @@ defmodule Mobilizon.GraphQL.API.Search do
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, ActorType}
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
@ -18,7 +18,7 @@ defmodule Mobilizon.GraphQL.API.Search do
|
|||||||
@doc """
|
@doc """
|
||||||
Searches actors.
|
Searches actors.
|
||||||
"""
|
"""
|
||||||
@spec search_actors(map(), integer | nil, integer | nil, ActorType.t()) ::
|
@spec search_actors(map(), integer | nil, integer | nil, atom()) ::
|
||||||
{:ok, Page.t(Actor.t())} | {:error, String.t()}
|
{:ok, Page.t(Actor.t())} | {:error, String.t()}
|
||||||
def search_actors(%{term: term} = args, page \\ 1, limit \\ 10, result_type) do
|
def search_actors(%{term: term} = args, page \\ 1, limit \\ 10, result_type) do
|
||||||
term = String.trim(term)
|
term = String.trim(term)
|
||||||
|
@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Middleware.ErrorHandler do
|
|||||||
alias Mobilizon.GraphQL.Error
|
alias Mobilizon.GraphQL.Error
|
||||||
|
|
||||||
@behaviour Absinthe.Middleware
|
@behaviour Absinthe.Middleware
|
||||||
@impl true
|
@impl Absinthe.Middleware
|
||||||
def call(resolution, _config) do
|
def call(resolution, _config) do
|
||||||
errors =
|
errors =
|
||||||
resolution.errors
|
resolution.errors
|
||||||
|
@ -345,7 +345,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec change_role(User.t(), Mobilizon.Users.UserRole.t(), boolean()) ::
|
@spec change_role(User.t(), atom(), boolean()) ::
|
||||||
{:ok, User.t()} | {:error, String.t() | Ecto.Changeset.t()}
|
{:ok, User.t()} | {:error, String.t() | Ecto.Changeset.t()}
|
||||||
defp change_role(%User{role: old_role} = user, new_role, notify) do
|
defp change_role(%User{role: old_role} = user, new_role, notify) do
|
||||||
if old_role != new_role do
|
if old_role != new_role do
|
||||||
|
@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||||||
alias Mobilizon.Federation.ActivityPub.Actions
|
alias Mobilizon.Federation.ActivityPub.Actions
|
||||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||||
alias Mobilizon.GraphQL.API
|
alias Mobilizon.GraphQL.API
|
||||||
alias Mobilizon.Users.{User, UserRole}
|
alias Mobilizon.Users.User
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
import Mobilizon.Web.Gettext
|
import Mobilizon.Web.Gettext
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||||||
{:error, "You need to be logged-in to create a group"}
|
{:error, "You need to be logged-in to create a group"}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec can_create_group?(UserRole.t()) :: boolean()
|
@spec can_create_group?(atom()) :: boolean()
|
||||||
defp can_create_group?(role) do
|
defp can_create_group?(role) do
|
||||||
if Config.only_admin_can_create_groups?() do
|
if Config.only_admin_can_create_groups?() do
|
||||||
is_admin(role)
|
is_admin(role)
|
||||||
|
@ -21,13 +21,13 @@ defmodule Mobilizon.Activities.Activity do
|
|||||||
@attrs @required_attrs ++ @optional_attrs
|
@attrs @required_attrs ++ @optional_attrs
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
priority: Priority.t(),
|
priority: pos_integer(),
|
||||||
type: Type.t(),
|
type: String.t(),
|
||||||
subject: Subject.t(),
|
subject: String.t(),
|
||||||
subject_params: map(),
|
subject_params: map(),
|
||||||
message: String.t(),
|
message: String.t(),
|
||||||
message_params: map(),
|
message_params: map(),
|
||||||
object_type: ObjectType.t(),
|
object_type: String.t(),
|
||||||
object_id: String.t(),
|
object_id: String.t(),
|
||||||
object: map(),
|
object: map(),
|
||||||
author: Actor.t(),
|
author: Actor.t(),
|
||||||
|
@ -33,15 +33,15 @@ defmodule Mobilizon.Actors.Actor do
|
|||||||
resources_url: String.t(),
|
resources_url: String.t(),
|
||||||
posts_url: String.t(),
|
posts_url: String.t(),
|
||||||
events_url: String.t(),
|
events_url: String.t(),
|
||||||
type: ActorType.t(),
|
type: atom(),
|
||||||
name: String.t() | nil,
|
name: String.t() | nil,
|
||||||
domain: String.t() | nil,
|
domain: String.t() | nil,
|
||||||
summary: String.t(),
|
summary: String.t(),
|
||||||
preferred_username: String.t(),
|
preferred_username: String.t(),
|
||||||
keys: String.t(),
|
keys: String.t(),
|
||||||
manually_approves_followers: boolean,
|
manually_approves_followers: boolean,
|
||||||
openness: ActorOpenness.t(),
|
openness: atom(),
|
||||||
visibility: ActorVisibility.t(),
|
visibility: atom(),
|
||||||
suspended: boolean,
|
suspended: boolean,
|
||||||
avatar: File.t() | nil,
|
avatar: File.t() | nil,
|
||||||
banner: File.t() | nil,
|
banner: File.t() | nil,
|
||||||
@ -358,7 +358,7 @@ defmodule Mobilizon.Actors.Actor do
|
|||||||
# When we don't even have any preferred_username, don't even try validating preferred_username
|
# When we don't even have any preferred_username, don't even try validating preferred_username
|
||||||
defp unique_username_validator(changeset), do: changeset
|
defp unique_username_validator(changeset), do: changeset
|
||||||
|
|
||||||
@spec build_urls(Ecto.Changeset.t(), ActorType.t()) :: Ecto.Changeset.t()
|
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
|
||||||
defp build_urls(changeset, type \\ :Person)
|
defp build_urls(changeset, type \\ :Person)
|
||||||
|
|
||||||
defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do
|
defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do
|
||||||
|
@ -145,7 +145,7 @@ defmodule Mobilizon.Actors do
|
|||||||
@doc """
|
@doc """
|
||||||
Gets an actor by name.
|
Gets an actor by name.
|
||||||
"""
|
"""
|
||||||
@spec get_actor_by_name(String.t(), ActorType.t() | nil) :: Actor.t() | nil
|
@spec get_actor_by_name(String.t(), atom() | nil) :: Actor.t() | nil
|
||||||
def get_actor_by_name(name, type \\ nil) do
|
def get_actor_by_name(name, type \\ nil) do
|
||||||
Actor
|
Actor
|
||||||
|> filter_by_type(type)
|
|> filter_by_type(type)
|
||||||
@ -1635,7 +1635,7 @@ defmodule Mobilizon.Actors do
|
|||||||
|> preload([f, a], [:target_actor, :actor])
|
|> preload([f, a], [:target_actor, :actor])
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec filter_by_type(Ecto.Queryable.t(), ActorType.t() | nil) :: Ecto.Queryable.t()
|
@spec filter_by_type(Ecto.Queryable.t(), atom() | nil) :: Ecto.Queryable.t()
|
||||||
defp filter_by_type(query, type)
|
defp filter_by_type(query, type)
|
||||||
when type in [:Person, :Group, :Application, :Service, :Organisation] do
|
when type in [:Person, :Group, :Application, :Service, :Organisation] do
|
||||||
from(a in query, where: a.type == ^type)
|
from(a in query, where: a.type == ^type)
|
||||||
|
@ -14,7 +14,7 @@ defmodule Mobilizon.Actors.Member do
|
|||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
id: String.t(),
|
id: String.t(),
|
||||||
url: String.t(),
|
url: String.t(),
|
||||||
role: MemberRole.t(),
|
role: atom(),
|
||||||
parent: Actor.t(),
|
parent: Actor.t(),
|
||||||
actor: Actor.t(),
|
actor: Actor.t(),
|
||||||
metadata: Metadata.t()
|
metadata: Metadata.t()
|
||||||
|
@ -22,7 +22,7 @@ defmodule Mobilizon.Discussions.Comment do
|
|||||||
url: String.t(),
|
url: String.t(),
|
||||||
id: integer(),
|
id: integer(),
|
||||||
local: boolean,
|
local: boolean,
|
||||||
visibility: CommentVisibility.t(),
|
visibility: atom(),
|
||||||
uuid: Ecto.UUID.t(),
|
uuid: Ecto.UUID.t(),
|
||||||
actor: Actor.t(),
|
actor: Actor.t(),
|
||||||
attributed_to: Actor.t(),
|
attributed_to: Actor.t(),
|
||||||
|
@ -43,10 +43,10 @@ defmodule Mobilizon.Events.Event do
|
|||||||
description: String.t(),
|
description: String.t(),
|
||||||
ends_on: DateTime.t(),
|
ends_on: DateTime.t(),
|
||||||
title: String.t(),
|
title: String.t(),
|
||||||
status: EventStatus.t(),
|
status: atom(),
|
||||||
draft: boolean,
|
draft: boolean,
|
||||||
visibility: EventVisibility.t(),
|
visibility: atom(),
|
||||||
join_options: JoinOptions.t(),
|
join_options: atom(),
|
||||||
publish_at: DateTime.t() | nil,
|
publish_at: DateTime.t() | nil,
|
||||||
uuid: Ecto.UUID.t(),
|
uuid: Ecto.UUID.t(),
|
||||||
online_address: String.t() | nil,
|
online_address: String.t() | nil,
|
||||||
|
@ -442,7 +442,7 @@ defmodule Mobilizon.Events do
|
|||||||
|
|
||||||
@spec list_organized_events_for_group(
|
@spec list_organized_events_for_group(
|
||||||
Actor.t(),
|
Actor.t(),
|
||||||
EventVisibility.t() | :all,
|
atom(),
|
||||||
DateTime.t() | nil,
|
DateTime.t() | nil,
|
||||||
DateTime.t() | nil,
|
DateTime.t() | nil,
|
||||||
integer | nil,
|
integer | nil,
|
||||||
|
@ -16,7 +16,7 @@ defmodule Mobilizon.Events.Participant do
|
|||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
id: String.t(),
|
id: String.t(),
|
||||||
role: ParticipantRole.t(),
|
role: atom(),
|
||||||
code: String.t(),
|
code: String.t(),
|
||||||
url: String.t(),
|
url: String.t(),
|
||||||
event: Event.t(),
|
event: Event.t(),
|
||||||
|
@ -39,7 +39,7 @@ defmodule Mobilizon.Posts.Post do
|
|||||||
body: String.t(),
|
body: String.t(),
|
||||||
title: String.t(),
|
title: String.t(),
|
||||||
draft: boolean,
|
draft: boolean,
|
||||||
visibility: PostVisibility.t(),
|
visibility: atom(),
|
||||||
publish_at: DateTime.t(),
|
publish_at: DateTime.t(),
|
||||||
author: Actor.t(),
|
author: Actor.t(),
|
||||||
attributed_to: Actor.t(),
|
attributed_to: Actor.t(),
|
||||||
|
@ -17,7 +17,7 @@ defmodule Mobilizon.Reports.Report do
|
|||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
id: integer(),
|
id: integer(),
|
||||||
content: String.t(),
|
content: String.t(),
|
||||||
status: ReportStatus.t(),
|
status: atom(),
|
||||||
url: String.t(),
|
url: String.t(),
|
||||||
reported: Actor.t(),
|
reported: Actor.t(),
|
||||||
reporter: Actor.t(),
|
reporter: Actor.t(),
|
||||||
|
@ -99,7 +99,7 @@ defmodule Mobilizon.Reports do
|
|||||||
@spec delete_note(Note.t()) :: {:ok, Note.t()} | {:error, Ecto.Changeset.t()}
|
@spec delete_note(Note.t()) :: {:ok, Note.t()} | {:error, Ecto.Changeset.t()}
|
||||||
def delete_note(%Note{} = note), do: Repo.delete(note)
|
def delete_note(%Note{} = note), do: Repo.delete(note)
|
||||||
|
|
||||||
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
|
@spec list_reports_query(atom()) :: Ecto.Query.t()
|
||||||
defp list_reports_query(status) do
|
defp list_reports_query(status) do
|
||||||
Report
|
Report
|
||||||
|> preload([:reported, :reporter, :manager, :event, :comments, :notes])
|
|> preload([:reported, :reporter, :manager, :event, :comments, :notes])
|
||||||
|
@ -13,9 +13,9 @@ defmodule Mobilizon.Users.Setting do
|
|||||||
notification_on_day: boolean,
|
notification_on_day: boolean,
|
||||||
notification_each_week: boolean,
|
notification_each_week: boolean,
|
||||||
notification_before_event: boolean,
|
notification_before_event: boolean,
|
||||||
notification_pending_participation: NotificationPendingNotificationDelay.t(),
|
notification_pending_participation: non_neg_integer(),
|
||||||
notification_pending_membership: NotificationPendingNotificationDelay.t(),
|
notification_pending_membership: non_neg_integer(),
|
||||||
group_notifications: NotificationPendingNotificationDelay.t(),
|
group_notifications: non_neg_integer(),
|
||||||
last_notification_sent: DateTime.t(),
|
last_notification_sent: DateTime.t(),
|
||||||
user: User.t()
|
user: User.t()
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ defmodule Mobilizon.Users.User do
|
|||||||
email: String.t(),
|
email: String.t(),
|
||||||
password_hash: String.t(),
|
password_hash: String.t(),
|
||||||
password: String.t(),
|
password: String.t(),
|
||||||
role: UserRole.t(),
|
role: atom(),
|
||||||
confirmed_at: DateTime.t() | nil,
|
confirmed_at: DateTime.t() | nil,
|
||||||
confirmation_sent_at: DateTime.t(),
|
confirmation_sent_at: DateTime.t(),
|
||||||
confirmation_token: String.t(),
|
confirmation_token: String.t(),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
defmodule Mobilizon.Service.ErrorReporting do
|
defmodule Mobilizon.Service.ErrorReporting do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Mpdule to load and configure error reporting adapters
|
Module to load and configure error reporting adapters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@callback enabled? :: boolean()
|
@callback enabled? :: boolean()
|
||||||
|
@ -30,7 +30,7 @@ defmodule Mobilizon.Service.Export.Participants.Common do
|
|||||||
@doc """
|
@doc """
|
||||||
Match a participant role to it's translated version
|
Match a participant role to it's translated version
|
||||||
"""
|
"""
|
||||||
@spec translate_role(Mobilizon.Events.ParticipantRole.t()) :: String.t()
|
@spec translate_role(atom()) :: String.t()
|
||||||
def translate_role(role) do
|
def translate_role(role) do
|
||||||
case role do
|
case role do
|
||||||
:not_approved ->
|
:not_approved ->
|
||||||
|
@ -93,7 +93,7 @@ defmodule Mobilizon.Service.Notifier.Email do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec match_group_notifications_setting(
|
@spec match_group_notifications_setting(
|
||||||
NotificationPendingNotificationDelay.t(),
|
non_neg_integer(),
|
||||||
String.t(),
|
String.t(),
|
||||||
DateTime.t() | nil,
|
DateTime.t() | nil,
|
||||||
Keyword.t()
|
Keyword.t()
|
||||||
|
@ -7,11 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do
|
|||||||
@moduledoc """
|
@moduledoc """
|
||||||
Extracts metadata about the upload, such as width/height
|
Extracts metadata about the upload, such as width/height
|
||||||
"""
|
"""
|
||||||
require Logger
|
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
@behaviour Filter
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Upload.t()) ::
|
@spec filter(Upload.t()) ::
|
||||||
{:ok, :filtered, Upload.t()} | {:ok, :noop}
|
{:ok, :filtered, Upload.t()} | {:ok, :noop}
|
||||||
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do
|
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do
|
||||||
@ -23,6 +24,7 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do
|
|||||||
{:ok, :filtered, %Upload{upload | width: image.width, height: image.height}}
|
{:ok, :filtered, %Upload{upload | width: image.width, height: image.height}}
|
||||||
rescue
|
rescue
|
||||||
e in ErlangError ->
|
e in ErlangError ->
|
||||||
|
require Logger
|
||||||
Logger.warn("#{__MODULE__}: #{inspect(e)}")
|
Logger.warn("#{__MODULE__}: #{inspect(e)}")
|
||||||
{:ok, :noop}
|
{:ok, :noop}
|
||||||
end
|
end
|
||||||
|
@ -4,9 +4,11 @@ defmodule Mobilizon.Web.Upload.Filter.BlurHash do
|
|||||||
"""
|
"""
|
||||||
require Logger
|
require Logger
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
@behaviour Filter
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Upload.t()) ::
|
@spec filter(Upload.t()) ::
|
||||||
{:ok, :filtered, Upload.t()} | {:ok, :noop}
|
{:ok, :filtered, Upload.t()} | {:ok, :noop}
|
||||||
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do
|
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do
|
||||||
|
@ -7,9 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.Dedupe do
|
|||||||
@moduledoc """
|
@moduledoc """
|
||||||
Names the file after its hash to avoid dedupes
|
Names the file after its hash to avoid dedupes
|
||||||
"""
|
"""
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
|
@behaviour Filter
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
|
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
|
||||||
def filter(%Upload{name: name, tempfile: tempfile} = upload) do
|
def filter(%Upload{name: name, tempfile: tempfile} = upload) do
|
||||||
extension = name |> String.split(".") |> List.last()
|
extension = name |> String.split(".") |> List.last()
|
||||||
|
@ -8,12 +8,14 @@ defmodule Mobilizon.Web.Upload.Filter.Exiftool do
|
|||||||
Also strips or replaces filesystem metadata e.g., timestamps.
|
Also strips or replaces filesystem metadata e.g., timestamps.
|
||||||
"""
|
"""
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
@behaviour Filter
|
||||||
|
|
||||||
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
|
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
|
||||||
|
|
||||||
# webp is not compatible with exiftool at this time
|
# webp is not compatible with exiftool at this time
|
||||||
|
@impl Filter
|
||||||
def filter(%Upload{content_type: "image/webp"}), do: {:ok, :noop}
|
def filter(%Upload{content_type: "image/webp"}), do: {:ok, :noop}
|
||||||
|
|
||||||
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do
|
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do
|
||||||
|
@ -8,13 +8,15 @@ defmodule Mobilizon.Web.Upload.Filter.Mogrify do
|
|||||||
Handle mogrify transformations
|
Handle mogrify transformations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
|
@behaviour Filter
|
||||||
|
|
||||||
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
|
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
|
||||||
@type conversions :: conversion() | [conversion()]
|
@type conversions :: conversion() | [conversion()]
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Mobilizon.Web.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
|
@spec filter(Mobilizon.Web.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
|
||||||
def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do
|
def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do
|
||||||
do_filter(file, Config.get!([__MODULE__, :args]))
|
do_filter(file, Config.get!([__MODULE__, :args]))
|
||||||
|
@ -2,13 +2,13 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do
|
|||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handle media optimizations
|
Handle media optimizations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@behaviour Filter
|
||||||
|
|
||||||
@default_optimizers [
|
@default_optimizers [
|
||||||
JpegOptim,
|
JpegOptim,
|
||||||
PngQuant,
|
PngQuant,
|
||||||
@ -18,6 +18,7 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do
|
|||||||
Cwebp
|
Cwebp
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, :file_not_found}
|
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, :file_not_found}
|
||||||
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do
|
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do
|
||||||
optimizers = Config.get([__MODULE__, :optimizers], @default_optimizers)
|
optimizers = Config.get([__MODULE__, :optimizers], @default_optimizers)
|
||||||
|
@ -5,12 +5,15 @@ defmodule Mobilizon.Web.Upload.Filter.Resize do
|
|||||||
This filter requires `Mobilizon.Web.Upload.Filter.AnalyzeMetadata` to be performed before.
|
This filter requires `Mobilizon.Web.Upload.Filter.AnalyzeMetadata` to be performed before.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Filter
|
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Filter
|
||||||
|
|
||||||
|
@behaviour Filter
|
||||||
|
|
||||||
@maximum_width 1_920
|
@maximum_width 1_920
|
||||||
@maximum_height 1_080
|
@maximum_height 1_080
|
||||||
|
|
||||||
|
@impl Filter
|
||||||
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
|
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
|
||||||
def filter(
|
def filter(
|
||||||
%Upload{
|
%Upload{
|
||||||
|
@ -8,17 +8,18 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
|
|||||||
Local uploader for files
|
Local uploader for files
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Mobilizon.Web.Upload.Uploader
|
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
alias Mobilizon.Web.Upload
|
alias Mobilizon.Web.Upload
|
||||||
|
alias Mobilizon.Web.Upload.Uploader
|
||||||
|
|
||||||
@impl true
|
@behaviour Uploader
|
||||||
|
|
||||||
|
@impl Uploader
|
||||||
def get_file(_) do
|
def get_file(_) do
|
||||||
{:ok, {:static_dir, upload_path()}}
|
{:ok, {:static_dir, upload_path()}}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl Uploader
|
||||||
@spec put_file(Upload.t()) ::
|
@spec put_file(Upload.t()) ::
|
||||||
:ok | {:ok, {:file, String.t()}} | {:error, :tempfile_no_longer_exists}
|
:ok | {:ok, {:file, String.t()}} | {:error, :tempfile_no_longer_exists}
|
||||||
def put_file(%Upload{path: initial_path, tempfile: tempfile}) do
|
def put_file(%Upload{path: initial_path, tempfile: tempfile}) do
|
||||||
@ -38,7 +39,7 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl Uploader
|
||||||
@spec remove_file(String.t()) ::
|
@spec remove_file(String.t()) ::
|
||||||
{:ok, {:file, String.t()}}
|
{:ok, {:file, String.t()}}
|
||||||
| {:error, :folder_not_empty}
|
| {:error, :folder_not_empty}
|
||||||
|
@ -3,7 +3,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
|
|||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Events.{Event, EventOptions, Participant, ParticipantRole}
|
alias Mobilizon.Events.{Event, EventOptions, Participant}
|
||||||
alias Mobilizon.Posts.Post
|
alias Mobilizon.Posts.Post
|
||||||
alias Mobilizon.Web.Endpoint
|
alias Mobilizon.Web.Endpoint
|
||||||
alias Mobilizon.Web.JsonLD.ObjectView
|
alias Mobilizon.Web.JsonLD.ObjectView
|
||||||
@ -166,7 +166,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec reservation_status(ParticipantRole.t()) :: String.t()
|
@spec reservation_status(atom()) :: String.t()
|
||||||
defp reservation_status(:rejected), do: "https://schema.org/ReservationCancelled"
|
defp reservation_status(:rejected), do: "https://schema.org/ReservationCancelled"
|
||||||
defp reservation_status(:not_confirmed), do: "https://schema.org/ReservationPending"
|
defp reservation_status(:not_confirmed), do: "https://schema.org/ReservationPending"
|
||||||
defp reservation_status(:not_approved), do: "https://schema.org/ReservationHold"
|
defp reservation_status(:not_approved), do: "https://schema.org/ReservationHold"
|
||||||
|
Loading…
Reference in New Issue
Block a user