Update avatar.
This commit is contained in:
parent
076fbb30fb
commit
5af4e5754b
8
Makefile
8
Makefile
@ -5,13 +5,15 @@ GUNICORN=./.venv/bin/gunicorn
|
||||
GUNICORN_WORKERS = 1
|
||||
PORT = 8081
|
||||
|
||||
python:
|
||||
$(PYTHON)
|
||||
|
||||
run:
|
||||
$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload
|
||||
|
||||
install:
|
||||
python3 -m venv .venv
|
||||
$(PIP) install -e .
|
||||
|
||||
|
||||
|
||||
run:
|
||||
$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload
|
||||
|
||||
|
@ -28,6 +28,7 @@ dependencies = [
|
||||
"asyncssh",
|
||||
"emoji",
|
||||
"aiofiles",
|
||||
"PyJWT"
|
||||
"PyJWT",
|
||||
"multiavatar"
|
||||
]
|
||||
|
||||
|
@ -33,8 +33,10 @@ from snek.view.status import StatusView
|
||||
from snek.view.web import WebView
|
||||
from snek.view.upload import UploadView
|
||||
from snek.view.search_user import SearchUserView
|
||||
from snek.view.avatar import AvatarView
|
||||
from snek.system.profiler import profiler_handler
|
||||
|
||||
|
||||
SESSION_KEY = b"c79a0c5fda4b424189c427d28c9f7c34"
|
||||
|
||||
|
||||
@ -101,6 +103,7 @@ class Application(BaseApplication):
|
||||
self.router.add_view("/drive.bin/{uid}.{ext}", UploadView)
|
||||
self.router.add_view("/search-user.html", SearchUserView)
|
||||
self.router.add_view("/search-user.json", SearchUserView)
|
||||
self.router.add_view("/avatar/{uid}.svg", AvatarView)
|
||||
self.router.add_get("/http-get", self.handle_http_get)
|
||||
self.router.add_get("/http-photo", self.handle_http_photo)
|
||||
self.router.add_get("/rpc.ws", RPCView)
|
||||
|
@ -1 +1 @@
|
||||
<div style="max-width:100%;" data-uid="{{uid}}" data-color="{{color}}" data-channel_uid="{{channel_uid}}" data-user_nick="{{user_nick}}" data-created_at="{{created_at}}" data-user_uid="{{user_uid}}" class="message"><div class="avatar" style="background-color: {{color}}; color: black;">{{user_nick[0]}}</div><div class="message-content"><div class="author" style="color: {{color}};">{{user_nick}}</div><div class="text">{% autoescape false %}{% emoji %}{% linkify %}{% markdown %}{% autoescape false %}{{ message }}{%raw %} {% endraw%}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endemoji %}{% endautoescape %}</div><div class="time no-select" data-created_at="{{created_at}}"></div></div></div>
|
||||
<div style="max-width:100%;" data-uid="{{uid}}" data-color="{{color}}" data-channel_uid="{{channel_uid}}" data-user_nick="{{user_nick}}" data-created_at="{{created_at}}" data-user_uid="{{user_uid}}" class="message"><div class="avatar" style="background-color: {{color}}; color: black;"><img src="/avatar/{{user_uid}}.svg" /></div><div class="message-content"><div class="author" style="color: {{color}};">{{user_nick}}</div><div class="text">{% autoescape false %}{% emoji %}{% linkify %}{% markdown %}{% autoescape false %}{{ message }}{%raw %} {% endraw%}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endemoji %}{% endautoescape %}</div><div class="time no-select" data-created_at="{{created_at}}"></div></div></div>
|
||||
|
39
src/snek/view/avatar.py
Normal file
39
src/snek/view/avatar.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Written by retoor@molodetz.nl
|
||||
|
||||
# This code defines a WebView class that inherits from BaseView and includes a method for rendering a web template, requiring login access for its usage.
|
||||
|
||||
# The code imports the BaseView class from the `snek.system.view` module.
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
from multiavatar import multiavatar
|
||||
|
||||
from aiohttp import web
|
||||
from snek.system.view import BaseView
|
||||
|
||||
class AvatarView(BaseView):
|
||||
login_required = True
|
||||
|
||||
async def get(self):
|
||||
uid = self.request.match_info.get("uid")
|
||||
avatar = multiavatar.multiavatar(uid,None, None)
|
||||
response = web.Response(text=avatar, content_type='image/svg+xml')
|
||||
response.headers['Cache-Control'] = f'public, max-age={1337*42}'
|
||||
return response
|
@ -23,7 +23,9 @@ class UploadView(BaseView):
|
||||
async def get(self):
|
||||
uid = self.request.match_info.get("uid")
|
||||
drive_item = await self.services.drive_item.get(uid)
|
||||
return web.FileResponse(drive_item["path"])
|
||||
response = web.FileResponse(drive_item["path"])
|
||||
response.headers['Cache-Control'] = f'public, max-age={1337*420}'
|
||||
return response
|
||||
|
||||
async def post(self):
|
||||
reader = await self.request.multipart()
|
||||
|
Loading…
Reference in New Issue
Block a user