List installed frontend refs in admin API

This commit is contained in:
Ekaterina Vaartis 2023-03-29 23:18:44 +03:00
parent 4f7c11b281
commit d3b27d45a9
4 changed files with 17 additions and 3 deletions

View File

@ -1585,6 +1585,7 @@ Returns the content of the document
"build_url": "https://git.pleroma.social/pleroma/fedi-fe/-/jobs/artifacts/${ref}/download?job=build", "build_url": "https://git.pleroma.social/pleroma/fedi-fe/-/jobs/artifacts/${ref}/download?job=build",
"git": "https://git.pleroma.social/pleroma/fedi-fe", "git": "https://git.pleroma.social/pleroma/fedi-fe",
"installed": true, "installed": true,
"installed_refs": ["master"],
"name": "fedi-fe", "name": "fedi-fe",
"ref": "master" "ref": "master"
}, },
@ -1592,6 +1593,7 @@ Returns the content of the document
"build_url": "https://git.pleroma.social/lambadalambda/kenoma/-/jobs/artifacts/${ref}/download?job=build", "build_url": "https://git.pleroma.social/lambadalambda/kenoma/-/jobs/artifacts/${ref}/download?job=build",
"git": "https://git.pleroma.social/lambadalambda/kenoma", "git": "https://git.pleroma.social/lambadalambda/kenoma",
"installed": false, "installed": false,
"installed_refs": [],
"name": "kenoma", "name": "kenoma",
"ref": "master" "ref": "master"
} }

View File

@ -22,7 +22,9 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do
[:frontends, :available] [:frontends, :available]
|> Config.get([]) |> Config.get([])
|> Enum.map(fn {name, desc} -> |> Enum.map(fn {name, desc} ->
Map.put(desc, "installed", name in installed) desc
|> Map.put("installed", name in installed)
|> Map.put("installed_refs", installed_refs(name))
end) end)
render(conn, "index.json", frontends: frontends) render(conn, "index.json", frontends: frontends)
@ -43,4 +45,12 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do
[] []
end end
end end
def installed_refs(name) do
if name in installed() do
File.ls!(Path.join(Pleroma.Frontend.dir(), name))
else
[]
end
end
end end

View File

@ -15,7 +15,8 @@ defmodule Pleroma.Web.AdminAPI.FrontendView do
git: frontend["git"], git: frontend["git"],
build_url: frontend["build_url"], build_url: frontend["build_url"],
ref: frontend["ref"], ref: frontend["ref"],
installed: frontend["installed"] installed: frontend["installed"],
installed_refs: frontend["installed_refs"]
} }
end end
end end

View File

@ -52,7 +52,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.FrontendOperation do
git: %Schema{type: :string, format: :uri, nullable: true}, git: %Schema{type: :string, format: :uri, nullable: true},
build_url: %Schema{type: :string, format: :uri, nullable: true}, build_url: %Schema{type: :string, format: :uri, nullable: true},
ref: %Schema{type: :string}, ref: %Schema{type: :string},
installed: %Schema{type: :boolean} installed: %Schema{type: :boolean},
installed_refs: %Schema{type: :array, items: %Schema{type: :string}}
} }
} }
} }