Merge remote-tracking branch 'remotes/origin/develop' into media-preview-proxy
authorIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 11 Sep 2020 14:19:58 +0000 (17:19 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 11 Sep 2020 14:19:58 +0000 (17:19 +0300)
# Conflicts:
# lib/pleroma/instances/instance.ex

1  2 
config/config.exs
config/description.exs
lib/pleroma/instances/instance.ex
lib/pleroma/web/mastodon_api/views/status_view.ex

diff --combined config/config.exs
index 1a4b400f6504a7571b4f9cccb91d440aad106a34,88c47fd032c382b9e92a021dcccdd4c5bbdba869..93c9309370b18dcbcc61552e08f85d1d5149db94
@@@ -424,8 -424,6 +424,8 @@@ config :pleroma, :media_proxy
    proxy_opts: [
      redirect_on_failure: false,
      max_body_length: 25 * 1_048_576,
 +    # Note: max_read_duration defaults to Pleroma.ReverseProxy.max_read_duration_default/1
 +    max_read_duration: 30_000,
      http: [
        follow_redirect: true,
        pool: :media
@@@ -440,13 -438,6 +440,13 @@@ config :pleroma, Pleroma.Web.MediaProxy
  
  config :pleroma, Pleroma.Web.MediaProxy.Invalidation.Script, script_path: nil
  
 +# Note: media preview proxy depends on media proxy to be enabled
 +config :pleroma, :media_preview_proxy,
 +  enabled: false,
 +  thumbnail_max_width: 600,
 +  thumbnail_max_height: 600,
 +  image_quality: 85
 +
  config :pleroma, :chat, enabled: true
  
  config :phoenix, :format_encoders, json: Jason
@@@ -539,6 -530,7 +539,7 @@@ config :pleroma, Oban
    log: false,
    queues: [
      activity_expiration: 10,
+     token_expiration: 5,
      federator_incoming: 50,
      federator_outgoing: 50,
      web_push: 50,
    ],
    plugins: [Oban.Plugins.Pruner],
    crontab: [
-     {"0 0 * * *", Pleroma.Workers.Cron.ClearOauthTokenWorker},
-     {"* * * * *", Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker},
      {"0 0 * * 0", Pleroma.Workers.Cron.DigestEmailsWorker},
      {"0 0 * * *", Pleroma.Workers.Cron.NewUsersDigestWorker}
    ]
@@@ -664,7 -654,7 +663,7 @@@ config :pleroma, :rate_limit
    account_confirmation_resend: {8_640_000, 5},
    ap_routes: {60_000, 15}
  
- config :pleroma, Pleroma.ActivityExpiration, enabled: true
+ config :pleroma, Pleroma.Workers.PurgeExpiredActivity, enabled: true, min_lifetime: 600
  
  config :pleroma, Pleroma.Plugs.RemoteIp, enabled: true
  
@@@ -752,8 -742,8 +751,8 @@@ config :pleroma, :pools
    ],
    media: [
      size: 50,
 -    max_waiting: 10,
 -    recv_timeout: 10_000
 +    max_waiting: 20,
 +    recv_timeout: 15_000
    ],
    upload: [
      size: 25,
diff --combined config/description.exs
index d1c99d002df76478c93024f93f42ead5caefb765,82c7bc6a7d0c98a45b43d8323d120ed490c1320e..c8e709730ad1a68d7ea9538b98ce31708a0283f9
@@@ -1880,7 -1880,6 +1880,7 @@@ config :pleroma, :config_description, 
          suggestions: [
            redirect_on_failure: false,
            max_body_length: 25 * 1_048_576,
 +          max_read_duration: 30_000,
            http: [
              follow_redirect: true,
              pool: :media
                "Limits the content length to be approximately the " <>
                  "specified length. It is validated with the `content-length` header and also verified when proxying."
            },
 +          %{
 +            key: :max_read_duration,
 +            type: :integer,
 +            description: "Timeout (in milliseconds) of GET request to remote URI."
 +          },
            %{
              key: :http,
              label: "HTTP",
        }
      ]
    },
 +  %{
 +    group: :pleroma,
 +    key: :media_preview_proxy,
 +    type: :group,
 +    description: "Media preview proxy",
 +    children: [
 +      %{
 +        key: :enabled,
 +        type: :boolean,
 +        description:
 +          "Enables proxying of remote media preview to the instance's proxy. Requires enabled media proxy."
 +      },
 +      %{
 +        key: :thumbnail_max_width,
 +        type: :integer,
 +        description: "Max width of preview thumbnail."
 +      },
 +      %{
 +        key: :thumbnail_max_height,
 +        type: :integer,
 +        description: "Max height of preview thumbnail."
 +      },
 +      %{
 +        key: :image_quality,
 +        type: :integer,
 +        description: "Quality of the output. Ranges from 0 (min quality) to 100 (max quality)."
 +      }
 +    ]
 +  },
    %{
      group: :pleroma,
      key: Pleroma.Web.MediaProxy.Invalidation.Http,
          type: {:list, :tuple},
          description: "Settings for cron background jobs",
          suggestions: [
-           {"0 0 * * *", Pleroma.Workers.Cron.ClearOauthTokenWorker},
-           {"* * * * *", Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker},
            {"0 0 * * 0", Pleroma.Workers.Cron.DigestEmailsWorker},
            {"0 0 * * *", Pleroma.Workers.Cron.NewUsersDigestWorker}
          ]
    },
    %{
      group: :pleroma,
-     key: Pleroma.ActivityExpiration,
+     key: Pleroma.Workers.PurgeExpiredActivity,
      type: :group,
-     description: "Expired activity settings",
+     description: "Expired activities settings",
      children: [
        %{
          key: :enabled,
          type: :boolean,
-         description: "Whether expired activities will be sent to the job queue to be deleted"
+         description: "Enables expired activities addition & deletion"
+       },
+       %{
+         key: :min_lifetime,
+         type: :integer,
+         description: "Minimum lifetime for ephemeral activity (in seconds)",
+         suggestions: [600]
        }
      ]
    },
index ad7764f05b54145ee912d5dd6124513e12cb14b6,6948651c7bacdbba4768fe8df50a68904a5eeae5..f0f6014690a090b1d97e04f7a47aa4a3b2fe641d
@@@ -156,14 -156,14 +156,12 @@@ defmodule Pleroma.Instances.Instance d
    defp scrape_favicon(%URI{} = instance_uri) do
      try do
        with {:ok, %Tesla.Env{body: html}} <-
 -             Pleroma.HTTP.get(to_string(instance_uri), [{"accept", "text/html"}],
 -               adapter: [pool: :media]
 -             ),
 +             Pleroma.HTTP.get(to_string(instance_uri), [{"accept", "text/html"}], pool: :media),
-            favicon_rel <-
-              html
-              |> Floki.parse_document!()
-              |> Floki.attribute("link[rel=icon]", "href")
-              |> List.first(),
-            favicon <- URI.merge(instance_uri, favicon_rel) |> to_string(),
-            true <- is_binary(favicon) do
+            {_, [favicon_rel | _]} when is_binary(favicon_rel) <-
+              {:parse,
+               html |> Floki.parse_document!() |> Floki.attribute("link[rel=icon]", "href")},
+            {_, favicon} when is_binary(favicon) <-
+              {:merge, URI.merge(instance_uri, favicon_rel) |> to_string()} do
          favicon
        else
          _ -> nil
index 0882d680e63aefcc833544eb34f2d2250e09e4d1,ca42917fc4bd06e0749886a7b8058359cad18903..4f7f27f35df601476a1f14d36c92339e97c10721
@@@ -8,7 -8,6 +8,6 @@@ defmodule Pleroma.Web.MastodonAPI.Statu
    require Pleroma.Constants
  
    alias Pleroma.Activity
-   alias Pleroma.ActivityExpiration
    alias Pleroma.HTML
    alias Pleroma.Object
    alias Pleroma.Repo
  
      expires_at =
        with true <- client_posted_this_activity,
-            %ActivityExpiration{scheduled_at: scheduled_at} <-
-              ActivityExpiration.get_by_activity_id(activity.id) do
+            %Oban.Job{scheduled_at: scheduled_at} <-
+              Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id) do
          scheduled_at
        else
          _ -> nil
      [attachment_url | _] = attachment["url"]
      media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image"
      href = attachment_url["href"] |> MediaProxy.url()
 +    href_preview = attachment_url["href"] |> MediaProxy.preview_url()
  
      type =
        cond do
        id: to_string(attachment["id"] || hash_id),
        url: href,
        remote_url: href,
 -      preview_url: href,
 +      preview_url: href_preview,
        text_url: href,
        type: type,
        description: attachment["name"],