Merge branch 'develop' into feld-2168-media-preview-proxy
authorMark Felder <feld@FreeBSD.org>
Tue, 25 Aug 2020 16:57:23 +0000 (11:57 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 25 Aug 2020 16:57:23 +0000 (11:57 -0500)
1  2 
config/config.exs
config/description.exs
lib/pleroma/web/mastodon_api/views/status_view.ex

diff --combined config/config.exs
index b399ce6d7c5f19ad65cfecdbac8054e72f965c24,246712b9f675d245c2180ddac978fb91a74477aa..e1558e29ef562d6e64820e5d0c67e3f040d05ce7
@@@ -72,7 -72,8 +72,8 @@@ config :pleroma, Pleroma.Upload
        pool: :upload
      ]
    ],
-   filename_display_max_length: 30
+   filename_display_max_length: 30,
+   default_description: nil
  
  config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads"
  
@@@ -422,8 -423,6 +423,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
@@@ -438,16 -437,6 +439,16 @@@ 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,
 +  quality: 2,
 +  proxy_opts: [
 +    head_request_max_read_duration: 5_000
 +  ]
 +
  config :pleroma, :chat, enabled: true
  
  config :phoenix, :format_encoders, json: Jason
@@@ -682,7 -671,50 +683,50 @@@ config :pleroma, :static_fe, enabled: f
  # With no frontend configuration, the bundled files from the `static` directory will
  # be used.
  #
- # config :pleroma, :frontends, primary: %{"name" => "pleroma", "ref" => "develop"}
+ # config :pleroma, :frontends, 
+ # primary: %{"name" => "pleroma-fe", "ref" => "develop"},
+ # admin: %{"name" => "admin-fe", "ref" => "stable"},
+ # available: %{...}
+ config :pleroma, :frontends,
+   available: %{
+     "kenoma" => %{
+       "name" => "kenoma",
+       "git" => "https://git.pleroma.social/lambadalambda/kenoma",
+       "build_url" =>
+         "https://git.pleroma.social/lambadalambda/kenoma/-/jobs/artifacts/${ref}/download?job=build",
+       "ref" => "master"
+     },
+     "pleroma-fe" => %{
+       "name" => "pleroma-fe",
+       "git" => "https://git.pleroma.social/pleroma/pleroma-fe",
+       "build_url" =>
+         "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/${ref}/download?job=build",
+       "ref" => "develop"
+     },
+     "fedi-fe" => %{
+       "name" => "fedi-fe",
+       "git" => "https://git.pleroma.social/pleroma/fedi-fe",
+       "build_url" =>
+         "https://git.pleroma.social/pleroma/fedi-fe/-/jobs/artifacts/${ref}/download?job=build",
+       "ref" => "master"
+     },
+     "admin-fe" => %{
+       "name" => "admin-fe",
+       "git" => "https://git.pleroma.social/pleroma/admin-fe",
+       "build_url" =>
+         "https://git.pleroma.social/pleroma/admin-fe/-/jobs/artifacts/${ref}/download?job=build",
+       "ref" => "develop"
+     },
+     "soapbox-fe" => %{
+       "name" => "soapbox-fe",
+       "git" => "https://gitlab.com/soapbox-pub/soapbox-fe",
+       "build_url" =>
+         "https://gitlab.com/soapbox-pub/soapbox-fe/-/jobs/artifacts/${ref}/download?job=build-production",
+       "ref" => "v1.0.0",
+       "build_dir" => "static"
+     }
+   }
  
  config :pleroma, :web_cache_ttl,
    activity_pub: nil,
diff --combined config/description.exs
index 22da60900b29f3908456a0ecf1e7276cfccf1a18,29a657333e50c564fbfeba4bf61be39d36dc19e0..0082cc84f8d349cd4c44a06bdf70cb40a829929c
@@@ -12,6 -12,55 +12,55 @@@ websocket_config = 
    compress: false
  ]
  
+ installed_frontend_options = [
+   %{
+     key: "name",
+     label: "Name",
+     type: :string,
+     description:
+       "Name of the installed frontend. Valid config must include both `Name` and `Reference` values."
+   },
+   %{
+     key: "ref",
+     label: "Reference",
+     type: :string,
+     description:
+       "Reference of the installed frontend to be used. Valid config must include both `Name` and `Reference` values."
+   }
+ ]
+ frontend_options = [
+   %{
+     key: "name",
+     label: "Name",
+     type: :string,
+     description: "Name of the frontend."
+   },
+   %{
+     key: "ref",
+     label: "Reference",
+     type: :string,
+     description: "Reference of the frontend to be used."
+   },
+   %{
+     key: "git",
+     type: :string,
+     description: "URL of the git repository of the frontend"
+   },
+   %{
+     key: "build_url",
+     type: :string,
+     description:
+       "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.",
+     example: "https://some.url/builds/${ref}.zip"
+   },
+   %{
+     key: "build_dir",
+     type: :string,
+     description: "The directory inside the zip file "
+   }
+ ]
  config :pleroma, :config_description, [
    %{
      group: :pleroma,
          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: :quality,
 +        type: :integer,
 +        description: "Quality of the output. Ranges from 1 (max quality) to 31 (lowest quality)."
 +      },
 +      %{
 +        key: :proxy_opts,
 +        type: :keyword,
 +        description: "Media proxy options",
 +        suggestions: [
 +          head_request_max_read_duration: 5_000
 +        ],
 +        children: [
 +          %{
 +            key: :head_request_max_read_duration,
 +            type: :integer,
 +            description: "Timeout (in milliseconds) of HEAD request to remote URI."
 +          }
 +        ]
 +      },
 +      %{
 +        key: :whitelist,
 +        type: {:list, :string},
 +        description: "List of hosts with scheme to bypass the mediaproxy",
 +        suggestions: ["http://example.com"]
 +      }
 +    ]
 +  },
    %{
      group: :pleroma,
      key: Pleroma.Web.MediaProxy.Invalidation.Http,
          key: :primary,
          type: :map,
          description: "Primary frontend, the one that is served for all pages by default",
+         children: installed_frontend_options
+       },
+       %{
+         key: :admin,
+         type: :map,
+         description: "Admin frontend",
+         children: installed_frontend_options
+       },
+       %{
+         key: :available,
+         type: :map,
+         description:
+           "A map containing available frontends and parameters for their installation.",
          children: [
-           %{
-             key: "name",
-             label: "Name",
-             type: :string,
-             description:
-               "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values."
-           },
-           %{
-             key: "ref",
-             label: "Reference",
-             type: :string,
-             description:
-               "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values."
-           }
+           frontend_options
+         ]
+       }
+     ]
+   },
+   %{
+     group: :pleroma,
+     key: Pleroma.Web.Preload,
+     type: :group,
+     description: "Preload-related settings",
+     children: [
+       %{
+         key: :providers,
+         type: {:list, :module},
+         description: "List of preload providers to enable",
+         suggestions: [
+           Pleroma.Web.Preload.Providers.Instance,
+           Pleroma.Web.Preload.Providers.User,
+           Pleroma.Web.Preload.Providers.Timelines,
+           Pleroma.Web.Preload.Providers.StatusNet
          ]
        }
      ]
index 8f4fb593aaca02e1d81f725162c2d0cb0267b090,01b8bb6bb1b1cfd8ac76adc5f04cb758b84257e2..1408a3adde100b765b719996bebeb27a541e1f74
@@@ -417,7 -417,6 +417,7 @@@ defmodule Pleroma.Web.MastodonAPI.Statu
      [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"],
      end
    end
  
-   def render_content(%{data: %{"type" => object_type}} = object)
-       when object_type in ["Video", "Event", "Audio"] do
-     with name when not is_nil(name) and name != "" <- object.data["name"] do
-       "<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}"
-     else
-       _ -> object.data["content"] || ""
-     end
-   end
+   def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
+     url = object.data["url"] || object.data["id"]
  
-   def render_content(%{data: %{"type" => object_type}} = object)
-       when object_type in ["Article", "Page"] do
-     with summary when not is_nil(summary) and summary != "" <- object.data["name"],
-          url when is_bitstring(url) <- object.data["url"] do
-       "<p><a href=\"#{url}\">#{summary}</a></p>#{object.data["content"]}"
-     else
-       _ -> object.data["content"] || ""
-     end
+     "<p><a href=\"#{url}\">#{name}</a></p>#{object.data["content"]}"
    end
  
    def render_content(object), do: object.data["content"] || ""