mirror of
https://github.com/Reckless-Satoshi/robosats.git
synced 2024-09-11 19:57:11 +03:00
perf(coordinator): remove avatar generator
This commit is contained in:
parent
707f76832b
commit
c50b5c4f3b
24
api/admin.py
24
api/admin.py
@ -18,20 +18,9 @@ admin.site.unregister(User)
|
||||
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 +32,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()
|
||||
|
||||
|
||||
@admin.register(Order)
|
||||
class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
@ -446,7 +428,6 @@ class OnchainPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
@admin.register(Robot)
|
||||
class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
list_display = (
|
||||
"avatar_tag",
|
||||
"id",
|
||||
"user_link",
|
||||
"telegram_enabled",
|
||||
@ -459,9 +440,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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
gunicorn==22.0.0
|
||||
psycopg2==2.9.9
|
||||
SQLAlchemy==2.0.16
|
||||
|
@ -1,16 +1,13 @@
|
||||
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 rest_framework.authtoken.models import Token
|
||||
from rest_framework.exceptions import AuthenticationFailed
|
||||
from robohash import Robohash
|
||||
|
||||
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 +16,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):
|
||||
@ -158,21 +152,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()
|
||||
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user