mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add api_user_avatar.py
This commit is contained in:
parent
e58860f347
commit
dadf5b94d9
2 changed files with 40 additions and 0 deletions
|
@ -12,6 +12,7 @@ from .api_cvstats_latest import ApiCvstatsLatestStar
|
||||||
from .api_cvstats_avg import ApiCvstatsAvgStar
|
from .api_cvstats_avg import ApiCvstatsAvgStar
|
||||||
from .api_user_ryg import ApiUserRygStar
|
from .api_user_ryg import ApiUserRygStar
|
||||||
from .api_user_ryg_list import ApiUserRygListStar
|
from .api_user_ryg_list import ApiUserRygListStar
|
||||||
|
from .api_user_avatar import ApiUserAvatarStar
|
||||||
|
|
||||||
# Enter the PageStars of your Pack here!
|
# Enter the PageStars of your Pack here!
|
||||||
available_page_stars = [
|
available_page_stars = [
|
||||||
|
@ -28,6 +29,7 @@ available_page_stars = [
|
||||||
ApiCvstatsAvgStar,
|
ApiCvstatsAvgStar,
|
||||||
ApiUserRygStar,
|
ApiUserRygStar,
|
||||||
ApiUserRygListStar,
|
ApiUserRygListStar,
|
||||||
|
ApiUserAvatarStar,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
38
royalpack/stars/api_user_avatar.py
Normal file
38
royalpack/stars/api_user_avatar.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import re
|
||||||
|
import royalnet.utils as ru
|
||||||
|
import royalnet.constellation.api as rca
|
||||||
|
|
||||||
|
|
||||||
|
url_validation = re.compile(r'^(?:http|ftp)s?://'
|
||||||
|
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
|
||||||
|
r'localhost|'
|
||||||
|
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
|
||||||
|
r'(?::\d+)?'
|
||||||
|
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
|
class ApiUserAvatarStar(rca.ApiStar):
|
||||||
|
path = "/api/user/avatar/v2"
|
||||||
|
|
||||||
|
parameters = {
|
||||||
|
"put": {
|
||||||
|
"avatar_url": "The url that the user wants to set as avatar."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"put": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = ["user"]
|
||||||
|
|
||||||
|
@rca.magic
|
||||||
|
async def put(self, data: rca.ApiData) -> ru.JSON:
|
||||||
|
"""Set the avatar of current user."""
|
||||||
|
avatar_url = data["avatar_url"]
|
||||||
|
user = await data.user()
|
||||||
|
if not re.match(url_validation, avatar_url):
|
||||||
|
raise rca.InvalidParameterError("avatar_url is not a valid url.")
|
||||||
|
user.avatar_url = avatar_url
|
||||||
|
await data.session_commit()
|
||||||
|
return user.json()
|
Loading…
Reference in a new issue