perf(coordinator): remove avatar generator #1242

This commit is contained in:
Reckless_Satoshi 2024-06-16 22:54:31 +00:00 committed by GitHub
commit 0026fc0d68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 51 deletions

View File

@ -21,17 +21,13 @@ admin.site.unregister(TokenProxy)
class RobotInline(admin.StackedInline):
model = Robot
can_delete = False
fields = ("avatar_tag",)
readonly_fields = ["avatar_tag"]
show_change_link = True
# extended users with avatars
@admin.register(User)
class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
inlines = [RobotInline]
list_display = (
"avatar_tag",
"id",
"robot_link",
"username",
@ -43,25 +39,18 @@ class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
change_links = ("robot",)
ordering = ("-id",)
def avatar_tag(self, obj):
return obj.robot.avatar_tag()
# extended tokens with raw id fields and avatars
# extended tokens with raw id fields
@admin.register(TokenProxy)
class ETokenAdmin(AdminChangeLinksMixin, TokenAdmin):
raw_id_fields = ["user"]
list_display = (
"avatar_tag",
"key",
"user_link",
)
list_display_links = ("key",)
change_links = ("user",)
def avatar_tag(self, obj):
return obj.user.robot.avatar_tag()
class LNPaymentInline(admin.StackedInline):
model = LNPayment
@ -510,7 +499,6 @@ class OnchainPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
@admin.register(Robot)
class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
list_display = (
"avatar_tag",
"id",
"user_link",
"telegram_enabled",
@ -523,9 +511,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
)
raw_id_fields = ("user",)
list_editable = ["earned_rewards"]
list_display_links = ("avatar_tag", "id")
list_display_links = ["id"]
change_links = ["user"]
readonly_fields = ["avatar_tag"]
search_fields = ["user__username", "id"]
readonly_fields = ("hash_id", "public_key", "encrypted_private_key")

View File

@ -1,5 +1,4 @@
from datetime import datetime, timedelta
from pathlib import Path
from decouple import config
from django.conf import settings
@ -55,9 +54,6 @@ from control.models import AccountingDay, BalanceLog
EXP_MAKER_BOND_INVOICE = int(config("EXP_MAKER_BOND_INVOICE"))
RETRY_TIME = int(config("RETRY_TIME"))
avatar_path = Path(settings.AVATAR_ROOT)
avatar_path.mkdir(parents=True, exist_ok=True)
class MakerView(CreateAPIView):
serializer_class = MakeOrderSerializer

View File

@ -16,7 +16,6 @@ Pillow==10.1.0
python-decouple==3.8
requests==2.31.0
ring==0.10.1
git+https://github.com/RoboSats/Robohash.git@master
gunicorn==22.0.0
psycopg2==2.9.9
SQLAlchemy==2.0.16

View File

@ -1,16 +1,14 @@
import hashlib
from datetime import timedelta
from pathlib import Path
from channels.db import database_sync_to_async
from channels.middleware import BaseMiddleware
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User, update_last_login
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
from django.http import JsonResponse
from rest_framework.authtoken.models import Token
from robohash import Robohash
from rest_framework.exceptions import AuthenticationFailed
from api.nick_generator.nick_generator import NickGenerator
from api.utils import base91_to_hex, hex_to_base91, is_valid_token, validate_pgp_keys
@ -19,9 +17,6 @@ NickGen = NickGenerator(
lang="English", use_adv=False, use_adj=True, use_noun=True, max_num=999
)
avatar_path = Path(settings.AVATAR_ROOT)
avatar_path.mkdir(parents=True, exist_ok=True)
class DisableCSRFMiddleware(object):
def __init__(self, get_response):
@ -164,21 +159,6 @@ class RobotTokenSHA256AuthenticationMiddleWare:
if not user.robot.encrypted_private_key:
user.robot.encrypted_private_key = encrypted_private_key
# Generate avatar. Does not replace if existing.
image_path = avatar_path.joinpath(nickname + ".webp")
if not image_path.exists():
rh = Robohash(hash)
rh.assemble(roboset="set1", bgset="any") # for backgrounds ON
with open(image_path, "wb") as f:
rh.img.save(f, format="WEBP", quality=80)
image_small_path = avatar_path.joinpath(nickname + ".small.webp")
with open(image_small_path, "wb") as f:
resized_img = rh.img.resize((80, 80))
resized_img.save(f, format="WEBP", quality=80)
user.robot.avatar = "static/assets/avatars/" + nickname + ".webp"
update_last_login(None, user)
user.save()

View File

@ -23,8 +23,6 @@ from .celery.conf import * # noqa
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = "/static/"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
@ -32,8 +30,10 @@ STATIC_URL = "/static/"
SECRET_KEY = config("SECRET_KEY")
DEBUG = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "static/"
STATIC_ROOT = "/usr/src/static/"
# RoboSats version
with open("version.json") as f:
@ -42,9 +42,6 @@ with open("version.json") as f:
# SECURITY WARNING: don't run with debug turned on in production!
if config("DEVELOPMENT", default=False):
DEBUG = True
STATIC_ROOT = "frontend/static/"
AVATAR_ROOT = STATIC_ROOT + "assets/avatars/"
ALLOWED_HOSTS = [
config("HOST_NAME"),
@ -228,10 +225,6 @@ USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = "static/"
ASGI_APPLICATION = "robosats.routing.application"
CHANNEL_LAYERS = {