Track usage of media files and add a job to clean them

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-11-26 11:41:13 +01:00
parent c19e326bd8
commit c9457fe0d3
78 changed files with 1405 additions and 700 deletions

View File

@@ -28,8 +28,8 @@ defmodule Mobilizon.GraphQL.Schema.ActorInterface do
field(:suspended, :boolean, description: "If the actor is suspended")
field(:avatar, :picture, description: "The actor's avatar picture")
field(:banner, :picture, description: "The actor's banner picture")
field(:avatar, :media, description: "The actor's avatar media")
field(:banner, :media, description: "The actor's banner media")
# These one should have a privacy setting
field(:following, list_of(:follower), description: "List of followings")

View File

@@ -3,7 +3,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
Schema representation for Group.
"""
alias Mobilizon.GraphQL.Resolvers.Picture
alias Mobilizon.GraphQL.Resolvers.Media
use Absinthe.Schema.Notation
@desc """
@@ -27,8 +27,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
field(:suspended, :boolean, description: "If the actor is suspended")
field(:avatar, :picture, description: "The actor's avatar picture")
field(:banner, :picture, description: "The actor's banner picture")
field(:avatar, :media, description: "The actor's avatar media")
field(:banner, :media, description: "The actor's banner media")
# These one should have a privacy setting
field(:following, list_of(:follower), description: "List of followings")
@@ -37,7 +37,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
field(:followingCount, :integer, description: "Number of actors following this actor")
field(:media_size, :integer,
resolve: &Picture.actor_size/3,
resolve: &Media.actor_size/3,
description: "The total size of the media from this actor"
)
end

View File

@@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Addresses
alias Mobilizon.GraphQL.Resolvers.{Discussion, Group, Member, Picture, Post, Resource, Todos}
alias Mobilizon.GraphQL.Resolvers.{Discussion, Group, Media, Member, Post, Resource, Todos}
alias Mobilizon.GraphQL.Schema
import_types(Schema.Actors.MemberType)
@@ -38,8 +38,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
field(:suspended, :boolean, description: "If the actor is suspended")
field(:avatar, :picture, description: "The actor's avatar picture")
field(:banner, :picture, description: "The actor's banner picture")
field(:avatar, :media, description: "The actor's avatar media")
field(:banner, :media, description: "The actor's banner media")
field(:physical_address, :address,
resolve: dataloader(Addresses),
@@ -53,7 +53,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
field(:followingCount, :integer, description: "Number of actors following this actor")
field(:media_size, :integer,
resolve: &Picture.actor_size/3,
resolve: &Media.actor_size/3,
description: "The total size of the media from this actor"
)
@@ -198,14 +198,14 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
default_value: :public
)
arg(:avatar, :picture_input,
arg(:avatar, :media_input,
description:
"The avatar for the group, either as an object or directly the ID of an existing Picture"
"The avatar for the group, either as an object or directly the ID of an existing media"
)
arg(:banner, :picture_input,
arg(:banner, :media_input,
description:
"The banner for the group, either as an object or directly the ID of an existing Picture"
"The banner for the group, either as an object or directly the ID of an existing media"
)
arg(:physical_address, :address_input, description: "The physical address for the group")
@@ -226,14 +226,14 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
description: "Whether the group can be join freely, with approval or is invite-only."
)
arg(:avatar, :picture_input,
arg(:avatar, :media_input,
description:
"The avatar for the group, either as an object or directly the ID of an existing Picture"
"The avatar for the group, either as an object or directly the ID of an existing media"
)
arg(:banner, :picture_input,
arg(:banner, :media_input,
description:
"The banner for the group, either as an object or directly the ID of an existing Picture"
"The banner for the group, either as an object or directly the ID of an existing media"
)
arg(:physical_address, :address_input, description: "The physical address for the group")

View File

@@ -7,7 +7,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Events
alias Mobilizon.GraphQL.Resolvers.{Person, Picture}
alias Mobilizon.GraphQL.Resolvers.{Media, Person}
alias Mobilizon.GraphQL.Schema
import_types(Schema.Events.FeedTokenType)
@@ -40,8 +40,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
field(:suspended, :boolean, description: "If the actor is suspended")
field(:avatar, :picture, description: "The actor's avatar picture")
field(:banner, :picture, description: "The actor's banner picture")
field(:avatar, :media, description: "The actor's avatar media")
field(:banner, :media, description: "The actor's banner media")
# These one should have a privacy setting
field(:following, list_of(:follower), description: "List of followings")
@@ -50,7 +50,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
field(:followingCount, :integer, description: "Number of actors following this actor")
field(:media_size, :integer,
resolve: &Picture.actor_size/3,
resolve: &Media.actor_size/3,
description: "The total size of the media from this actor"
)
@@ -150,14 +150,14 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
arg(:avatar, :picture_input,
arg(:avatar, :media_input,
description:
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
"The avatar for the profile, either as an object or directly the ID of an existing media"
)
arg(:banner, :picture_input,
arg(:banner, :media_input,
description:
"The banner for the profile, either as an object or directly the ID of an existing Picture"
"The banner for the profile, either as an object or directly the ID of an existing media"
)
resolve(&Person.create_person/3)
@@ -171,14 +171,14 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
arg(:summary, :string, description: "The summary for this profile")
arg(:avatar, :picture_input,
arg(:avatar, :media_input,
description:
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
"The avatar for the profile, either as an object or directly the ID of an existing media"
)
arg(:banner, :picture_input,
arg(:banner, :media_input,
description:
"The banner for the profile, either as an object or directly the ID of an existing Picture"
"The banner for the profile, either as an object or directly the ID of an existing media"
)
resolve(&Person.update_person/3)
@@ -200,14 +200,14 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
arg(:email, non_null(:string), description: "The email from the user previously created")
arg(:avatar, :picture_input,
arg(:avatar, :media_input,
description:
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
"The avatar for the profile, either as an object or directly the ID of an existing media"
)
arg(:banner, :picture_input,
arg(:banner, :media_input,
description:
"The banner for the profile, either as an object or directly the ID of an existing Picture"
"The banner for the profile, either as an object or directly the ID of an existing media"
)
resolve(&Person.register_person/3)

View File

@@ -43,7 +43,6 @@ defmodule Mobilizon.GraphQL.Schema.AddressType do
An address input
"""
input_object :address_input do
# Either a full picture object
field(:geom, :point, description: "The geocoordinates for the point where this address is")
field(:street, :string, description: "The address's street name (with number)")
field(:locality, :string, description: "The address's locality")

View File

@@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Addresses, Discussions}
alias Mobilizon.GraphQL.Resolvers.{Event, Picture, Tag}
alias Mobilizon.GraphQL.Resolvers.{Event, Media, Tag}
alias Mobilizon.GraphQL.Schema
import_types(Schema.AddressType)
@@ -31,9 +31,14 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
field(:visibility, :event_visibility, description: "The event's visibility")
field(:join_options, :event_join_options, description: "The event's visibility")
field(:picture, :picture,
field(:picture, :media,
description: "The event's picture",
resolve: &Picture.picture/3
resolve: &Media.media/3
)
field(:media, list_of(:media),
description: "The event's media",
resolve: &Media.medias/3
)
field(:publish_at, :datetime, description: "When the event was published")
@@ -328,9 +333,9 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
description: "The list of tags associated to the event"
)
arg(:picture, :picture_input,
arg(:picture, :media_input,
description:
"The picture for the event, either as an object or directly the ID of an existing Picture"
"The picture for the event, either as an object or directly the ID of an existing media"
)
arg(:publish_at, :datetime, description: "Datetime when the event was published")
@@ -379,9 +384,9 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
arg(:tags, list_of(:string), description: "The list of tags associated to the event")
arg(:picture, :picture_input,
arg(:picture, :media_input,
description:
"The picture for the event, either as an object or directly the ID of an existing Picture"
"The picture for the event, either as an object or directly the ID of an existing media"
)
arg(:online_address, :string, description: "Online address of the event")

View File

@@ -0,0 +1,68 @@
defmodule Mobilizon.GraphQL.Schema.MediaType do
@moduledoc """
Schema representation for Medias
"""
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.Media
@desc "A media"
object :media do
field(:id, :id, description: "The media's ID")
field(:alt, :string, description: "The media's alternative text")
field(:name, :string, description: "The media's name")
field(:url, :string, description: "The media's full URL")
field(:content_type, :string, description: "The media's detected content type")
field(:size, :integer, description: "The media's size")
end
@desc """
A paginated list of medias
"""
object :paginated_media_list do
field(:elements, list_of(:media), description: "The list of medias")
field(:total, :integer, description: "The total number of medias in the list")
end
@desc "An attached media or a link to a media"
input_object :media_input do
# Either a full media object
field(:media, :media_input_object, description: "A full media attached")
# Or directly the ID of an existing media
field(:media_id, :id, description: "The ID of an existing media")
end
@desc "An attached media"
input_object :media_input_object do
field(:name, non_null(:string), description: "The media's name")
field(:alt, :string, description: "The media's alternative text")
field(:file, non_null(:upload), description: "The media file")
field(:actor_id, :id, description: "The media owner")
end
object :media_queries do
@desc "Get a media"
field :media, :media do
arg(:id, non_null(:id), description: "The media ID")
resolve(&Media.media/3)
end
end
object :media_mutations do
@desc "Upload a media"
field :upload_media, :media do
arg(:name, non_null(:string), description: "The media's name")
arg(:alt, :string, description: "The media's alternative text")
arg(:file, non_null(:upload), description: "The media file")
resolve(&Media.upload_media/3)
end
@desc """
Remove a media
"""
field :remove_media, :deleted_object do
arg(:id, non_null(:id), description: "The media's ID")
resolve(&Media.remove_media/3)
end
end
end

View File

@@ -1,68 +0,0 @@
defmodule Mobilizon.GraphQL.Schema.PictureType do
@moduledoc """
Schema representation for Pictures
"""
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.Picture
@desc "A picture"
object :picture do
field(:id, :id, description: "The picture's ID")
field(:alt, :string, description: "The picture's alternative text")
field(:name, :string, description: "The picture's name")
field(:url, :string, description: "The picture's full URL")
field(:content_type, :string, description: "The picture's detected content type")
field(:size, :integer, description: "The picture's size")
end
@desc """
A paginated list of pictures
"""
object :paginated_picture_list do
field(:elements, list_of(:picture), description: "The list of pictures")
field(:total, :integer, description: "The total number of pictures in the list")
end
@desc "An attached picture or a link to a picture"
input_object :picture_input do
# Either a full picture object
field(:picture, :picture_input_object, description: "A full picture attached")
# Or directly the ID of an existing picture
field(:picture_id, :id, description: "The ID of an existing picture")
end
@desc "An attached picture"
input_object :picture_input_object do
field(:name, non_null(:string), description: "The picture's name")
field(:alt, :string, description: "The picture's alternative text")
field(:file, non_null(:upload), description: "The picture file")
field(:actor_id, :id, description: "The picture owner")
end
object :picture_queries do
@desc "Get a picture"
field :picture, :picture do
arg(:id, non_null(:id), description: "The picture ID")
resolve(&Picture.picture/3)
end
end
object :picture_mutations do
@desc "Upload a picture"
field :upload_picture, :picture do
arg(:name, non_null(:string), description: "The picture's name")
arg(:alt, :string, description: "The picture's alternative text")
arg(:file, non_null(:upload), description: "The picture file")
resolve(&Picture.upload_picture/3)
end
@desc """
Remove a picture
"""
field :remove_picture, :deleted_object do
arg(:id, non_null(:id), description: "The picture's ID")
resolve(&Picture.remove_picture/3)
end
end
end

View File

@@ -3,7 +3,7 @@ defmodule Mobilizon.GraphQL.Schema.PostType do
Schema representation for Posts
"""
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.{Picture, Post, Tag}
alias Mobilizon.GraphQL.Resolvers.{Media, Post, Tag}
@desc "A post"
object :post do
@@ -25,9 +25,9 @@ defmodule Mobilizon.GraphQL.Schema.PostType do
description: "The post's tags"
)
field(:picture, :picture,
description: "The posts's picture",
resolve: &Picture.picture/3
field(:picture, :media,
description: "The posts's media",
resolve: &Media.media/3
)
end
@@ -76,9 +76,9 @@ defmodule Mobilizon.GraphQL.Schema.PostType do
description: "The list of tags associated to the post"
)
arg(:picture, :picture_input,
arg(:picture, :media_input,
description:
"The banner for the post, either as an object or directly the ID of an existing Picture"
"The banner for the post, either as an object or directly the ID of an existing media"
)
resolve(&Post.create_post/3)
@@ -99,9 +99,9 @@ defmodule Mobilizon.GraphQL.Schema.PostType do
arg(:tags, list_of(:string), description: "The list of tags associated to the post")
arg(:picture, :picture_input,
arg(:picture, :media_input,
description:
"The banner for the post, either as an object or directly the ID of an existing Picture"
"The banner for the post, either as an object or directly the ID of an existing media"
)
resolve(&Post.update_post/3)

View File

@@ -7,7 +7,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Events
alias Mobilizon.GraphQL.Resolvers.{Picture, User}
alias Mobilizon.GraphQL.Resolvers.{Media, User}
alias Mobilizon.GraphQL.Schema
import_types(Schema.SortType)
@@ -111,7 +111,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
description: "The IP adress the user's currently signed-in with"
)
field(:media, :paginated_picture_list, description: "The user's media objects") do
field(:media, :paginated_media_list, description: "The user's media objects") do
arg(:page, :integer,
default_value: 1,
description: "The page in the paginated user media list"
@@ -122,7 +122,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
end
field(:media_size, :integer,
resolve: &Picture.user_size/3,
resolve: &Media.user_size/3,
description: "The total size of all the media from this user (from all their actors)"
)
end