Merge develop to bump elixir version in the CI so I don't get failing formatting
[akkoma] / lib / pleroma / plugs / uploaded_media.ex
index 994cc8bf641c82e410d529fce5163ca15da62306..fd77b8d8f30500dac7ee7c868bc69be3924c28b0 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Plugs.UploadedMedia do
   @moduledoc """
   """
@@ -8,10 +12,6 @@ defmodule Pleroma.Plugs.UploadedMedia do
   @behaviour Plug
   # no slashes
   @path "media"
-  @cache_control %{
-    default: "public, max-age=1209600",
-    error: "public, must-revalidate, max-age=160"
-  }
 
   def init(_opts) do
     static_plug_opts =
@@ -23,7 +23,19 @@ defmodule Pleroma.Plugs.UploadedMedia do
     %{static_plug_opts: static_plug_opts}
   end
 
-  def call(conn = %{request_path: <<"/", @path, "/", file::binary>>}, opts) do
+  def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
+    conn =
+      case fetch_query_params(conn) do
+        %{query_params: %{"name" => name}} = conn ->
+          name = String.replace(name, "\"", "\\\"")
+
+          conn
+          |> put_resp_header("content-disposition", "filename=\"#{name}\"")
+
+        conn ->
+          conn
+      end
+
     config = Pleroma.Config.get([Pleroma.Upload])
 
     with uploader <- Keyword.fetch!(config, :uploader),