Compare commits

...

3 Commits

Author SHA1 Message Date
itepechi 9104458dd9 Support OpenSearch protocol 2023-10-22 04:43:12 +09:00
itepechi 93cf428e2a Fix invalid version number on 'mix test' 2023-10-22 04:27:36 +09:00
itepechi c06fa7b55f Shorten version name
'akkoma 3.10.3-akkoma+bnakkoma' is unnecessarily long
2023-09-28 06:20:12 +09:00
7 changed files with 67 additions and 1 deletions

View File

@ -151,6 +151,7 @@ config :logger, :ex_syslogger,
config :mime, :types, %{
"application/xml" => ["xml"],
"application/xrd+xml" => ["xrd+xml"],
"application/opensearchdescription+xml" => ["xml"],
"application/jrd+json" => ["jrd+json"],
"application/activity+json" => ["activity+json"],
"application/ld+json" => ["activity+json"]

View 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

View File

@ -156,6 +156,10 @@ defmodule Pleroma.Web.Router do
plug(Pleroma.Web.Plugs.StaticFEPlug)
end
pipeline :accepts_opensearch do
plug(:accepts, ["xml"])
end
scope "/api/v1/pleroma", Pleroma.Web.TwitterAPI do
pipe_through(:pleroma_api)
@ -865,6 +869,12 @@ defmodule Pleroma.Web.Router do
get("/web/manifest.json", MastoFEController, :manifest)
end
scope "/", Pleroma.Web do
pipe_through(:accepts_opensearch)
get("/opensearch.xml", OpenSearchController, :show)
end
scope "/", Pleroma.Web do
pipe_through(:mastodon_html)

View 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>

View 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

View File

@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do
def project do
[
app: :pleroma,
version: version("3.10.3-akkoma+bnakkoma"),
version: version("3.10.3-bnakkoma"),
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: Mix.compilers(),

View 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