Support OpenSearch protocol
This commit is contained in:
parent
93cf428e2a
commit
9104458dd9
6 changed files with 66 additions and 0 deletions
|
@ -151,6 +151,7 @@
|
||||||
config :mime, :types, %{
|
config :mime, :types, %{
|
||||||
"application/xml" => ["xml"],
|
"application/xml" => ["xml"],
|
||||||
"application/xrd+xml" => ["xrd+xml"],
|
"application/xrd+xml" => ["xrd+xml"],
|
||||||
|
"application/opensearchdescription+xml" => ["xml"],
|
||||||
"application/jrd+json" => ["jrd+json"],
|
"application/jrd+json" => ["jrd+json"],
|
||||||
"application/activity+json" => ["activity+json"],
|
"application/activity+json" => ["activity+json"],
|
||||||
"application/ld+json" => ["activity+json"]
|
"application/ld+json" => ["activity+json"]
|
||||||
|
|
16
lib/pleroma/web/opensearch_controller.ex
Normal file
16
lib/pleroma/web/opensearch_controller.ex
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.OpenSearchController do
|
||||||
|
use Pleroma.Web, :controller
|
||||||
|
|
||||||
|
plug(:skip_auth when action == :show)
|
||||||
|
|
||||||
|
@doc "GET /opensearch.xml"
|
||||||
|
def show(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/opensearchdescription+xml")
|
||||||
|
|> render("opensearch.xml")
|
||||||
|
end
|
||||||
|
end
|
|
@ -156,6 +156,10 @@ defmodule Pleroma.Web.Router do
|
||||||
plug(Pleroma.Web.Plugs.StaticFEPlug)
|
plug(Pleroma.Web.Plugs.StaticFEPlug)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipeline :accepts_opensearch do
|
||||||
|
plug(:accepts, ["xml"])
|
||||||
|
end
|
||||||
|
|
||||||
scope "/api/v1/pleroma", Pleroma.Web.TwitterAPI do
|
scope "/api/v1/pleroma", Pleroma.Web.TwitterAPI do
|
||||||
pipe_through(:pleroma_api)
|
pipe_through(:pleroma_api)
|
||||||
|
|
||||||
|
@ -865,6 +869,12 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/web/manifest.json", MastoFEController, :manifest)
|
get("/web/manifest.json", MastoFEController, :manifest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope "/", Pleroma.Web do
|
||||||
|
pipe_through(:accepts_opensearch)
|
||||||
|
|
||||||
|
get("/opensearch.xml", OpenSearchController, :show)
|
||||||
|
end
|
||||||
|
|
||||||
scope "/", Pleroma.Web do
|
scope "/", Pleroma.Web do
|
||||||
pipe_through(:mastodon_html)
|
pipe_through(:mastodon_html)
|
||||||
|
|
||||||
|
|
9
lib/pleroma/web/templates/open_search/opensearch.xml.eex
Normal file
9
lib/pleroma/web/templates/open_search/opensearch.xml.eex
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||||
|
<ShortName><%= Config.get([:instance, :name]) %></ShortName>
|
||||||
|
<Description>Search through <%= Config.get([:instance, :name]) %></Description>
|
||||||
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
|
<Image width="16" height="16" type="image/x-icon"><%= Endpoint.url() %>/favicon.ico</Image>
|
||||||
|
<Image type="image/png"><%= Endpoint.url() %>/favicon.png</Image>
|
||||||
|
<Url type="text/html" method="get" template="<%= Endpoint.url() %>/search?query={searchTerms}"/>
|
||||||
|
</OpenSearchDescription>
|
9
lib/pleroma/web/views/opensearch_view.ex
Normal file
9
lib/pleroma/web/views/opensearch_view.ex
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.OpenSearchView do
|
||||||
|
use Pleroma.Web, :view
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Web.Endpoint
|
||||||
|
end
|
21
test/pleroma/web/opensearch_controller_test.exs
Normal file
21
test/pleroma/web/opensearch_controller_test.exs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.OpenSearchControllerTest do
|
||||||
|
use Pleroma.Web.ConnCase, async: false
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Web.Endpoint
|
||||||
|
|
||||||
|
test "opensearch.xml", %{conn: conn} do
|
||||||
|
resp =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/opensearchdescription+xml")
|
||||||
|
|> get("/opensearch.xml")
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
assert resp =~ "<ShortName>#{Config.get([:instance, :name])}</ShortName>"
|
||||||
|
assert resp =~ "<Description>Search through #{Config.get([:instance, :name])}</Description>"
|
||||||
|
assert resp =~ "template=\"#{Endpoint.url()}/search?query={searchTerms}\""
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue