Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F12553238
frontend_controller.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
frontend_controller.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Web.AdminAPI.FrontendController
do
use
Pleroma.Web
,
:controller
alias
Pleroma.Config
alias
Pleroma.Web.Plugs.OAuthScopesPlug
plug
(
Pleroma.Web.ApiSpec.CastAndValidate
)
plug
(
OAuthScopesPlug
,
%{
scopes
:
[
"admin:write"
]}
when
action
==
:install
)
plug
(
OAuthScopesPlug
,
%{
scopes
:
[
"admin:read"
]}
when
action
==
:index
)
action_fallback
(
Pleroma.Web.AdminAPI.FallbackController
)
defdelegate
open_api_operation
(
action
),
to
:
Pleroma.Web.ApiSpec.Admin.FrontendOperation
def
index
(
conn
,
_params
)
do
installed
=
installed
()
# FIrst get frontends from config,
# then add frontends that are installed but not in the config
frontends
=
Config
.
get
([
:frontends
,
:available
],
[])
|>
Enum
.
map
(
fn
{
name
,
desc
}
->
desc
|>
Map
.
put
(
"installed"
,
name
in
installed
)
|>
Map
.
put
(
"installed_refs"
,
installed_refs
(
name
))
end
)
frontends
=
frontends
++
(
installed
|>
Enum
.
filter
(
fn
n
->
not
Enum
.
any?
(
frontends
,
fn
f
->
f
[
"name"
]
==
n
end
)
end
)
|>
Enum
.
map
(
fn
name
->
%{
"name"
=>
name
,
"installed"
=>
true
,
"installed_refs"
=>
installed_refs
(
name
)}
end
))
render
(
conn
,
"index.json"
,
frontends
:
frontends
)
end
def
install
(%{
body_params
:
params
}
=
conn
,
_params
)
do
with
:ok
<-
Pleroma.Frontend
.
install
(
params
.
name
,
Map
.
delete
(
params
,
:name
))
do
index
(
conn
,
%{})
end
end
defp
installed
do
frontend_directory
=
Pleroma.Frontend
.
dir
()
if
File
.
exists?
(
frontend_directory
)
do
File
.
ls!
(
frontend_directory
)
else
[]
end
end
def
installed_refs
(
name
)
do
if
name
in
installed
()
do
File
.
ls!
(
Path
.
join
(
Pleroma.Frontend
.
dir
(),
name
))
else
[]
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Nov 15, 1:33 AM (22 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
633037
Default Alt Text
frontend_controller.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment