Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F12551370
mascot_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
mascot_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.PleromaAPI.MascotController
do
use
Pleroma.Web
,
:controller
alias
Pleroma.User
alias
Pleroma.Web.ActivityPub.ActivityPub
alias
Pleroma.Web.Plugs.OAuthScopesPlug
plug
(
Majic.Plug
,
[
pool
:
Pleroma.MajicPool
]
when
action
in
[
:update
])
plug
(
Pleroma.Web.ApiSpec.CastAndValidate
,
replace_params
:
false
)
plug
(
OAuthScopesPlug
,
%{
scopes
:
[
"read:accounts"
]}
when
action
==
:show
)
plug
(
OAuthScopesPlug
,
%{
scopes
:
[
"write:accounts"
]}
when
action
!=
:show
)
defdelegate
open_api_operation
(
action
),
to
:
Pleroma.Web.ApiSpec.PleromaMascotOperation
@doc
"GET /api/v1/pleroma/mascot"
def
show
(%{
assigns
:
%{
user
:
user
}}
=
conn
,
_params
)
do
json
(
conn
,
User
.
get_mascot
(
user
))
end
@doc
"PUT /api/v1/pleroma/mascot"
def
update
(
%{
assigns
:
%{
user
:
user
},
private
:
%{
open_api_spex
:
%{
body_params
:
%{
file
:
file
}}}}
=
conn
,
_
)
do
with
{
:content_type
,
"image"
<>
_
}
<-
{
:content_type
,
file
.
content_type
},
{
_
,
{
:ok
,
object
}}
<-
{
:upload
,
ActivityPub
.
upload
(
file
,
actor
:
User
.
ap_id
(
user
))}
do
attachment
=
render_attachment
(
object
)
{
:ok
,
_user
}
=
User
.
mascot_update
(
user
,
attachment
)
json
(
conn
,
attachment
)
else
{
:content_type
,
_
}
->
render_error
(
conn
,
:unsupported_media_type
,
"mascots can only be images"
)
{
:upload
,
{
:error
,
_
}}
->
render_error
(
conn
,
:error
,
"error uploading file"
)
end
end
defp
render_attachment
(
object
)
do
attachment_data
=
Map
.
put
(
object
.
data
,
"id"
,
object
.
id
)
Pleroma.Web.MastodonAPI.StatusView
.
render
(
"attachment.json"
,
%{
attachment
:
attachment_data
})
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Nov 14, 10:42 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
632454
Default Alt Text
mascot_controller.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment