mirror of
https://github.com/RoboSats/robosats.git
synced 2024-09-11 14:05:51 +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)
|
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)
|
@admin.register(User)
|
||||||
class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
|
class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
|
||||||
inlines = [RobotInline]
|
|
||||||
list_display = (
|
list_display = (
|
||||||
"avatar_tag",
|
|
||||||
"id",
|
"id",
|
||||||
"robot_link",
|
"robot_link",
|
||||||
"username",
|
"username",
|
||||||
@ -43,25 +32,18 @@ class EUserAdmin(AdminChangeLinksMixin, UserAdmin):
|
|||||||
change_links = ("robot",)
|
change_links = ("robot",)
|
||||||
ordering = ("-id",)
|
ordering = ("-id",)
|
||||||
|
|
||||||
def avatar_tag(self, obj):
|
|
||||||
return obj.robot.avatar_tag()
|
|
||||||
|
|
||||||
|
# extended tokens with raw id fields
|
||||||
# extended tokens with raw id fields and avatars
|
|
||||||
@admin.register(TokenProxy)
|
@admin.register(TokenProxy)
|
||||||
class ETokenAdmin(AdminChangeLinksMixin, TokenAdmin):
|
class ETokenAdmin(AdminChangeLinksMixin, TokenAdmin):
|
||||||
raw_id_fields = ["user"]
|
raw_id_fields = ["user"]
|
||||||
list_display = (
|
list_display = (
|
||||||
"avatar_tag",
|
|
||||||
"key",
|
"key",
|
||||||
"user_link",
|
"user_link",
|
||||||
)
|
)
|
||||||
list_display_links = ("key",)
|
list_display_links = ("key",)
|
||||||
change_links = ("user",)
|
change_links = ("user",)
|
||||||
|
|
||||||
def avatar_tag(self, obj):
|
|
||||||
return obj.user.robot.avatar_tag()
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Order)
|
@admin.register(Order)
|
||||||
class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||||
@ -446,7 +428,6 @@ class OnchainPaymentAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
|||||||
@admin.register(Robot)
|
@admin.register(Robot)
|
||||||
class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
"avatar_tag",
|
|
||||||
"id",
|
"id",
|
||||||
"user_link",
|
"user_link",
|
||||||
"telegram_enabled",
|
"telegram_enabled",
|
||||||
@ -459,9 +440,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
|||||||
)
|
)
|
||||||
raw_id_fields = ("user",)
|
raw_id_fields = ("user",)
|
||||||
list_editable = ["earned_rewards"]
|
list_editable = ["earned_rewards"]
|
||||||
list_display_links = ("avatar_tag", "id")
|
list_display_links = ["id"]
|
||||||
change_links = ["user"]
|
change_links = ["user"]
|
||||||
readonly_fields = ["avatar_tag"]
|
|
||||||
search_fields = ["user__username", "id"]
|
search_fields = ["user__username", "id"]
|
||||||
readonly_fields = ("hash_id", "public_key", "encrypted_private_key")
|
readonly_fields = ("hash_id", "public_key", "encrypted_private_key")
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from decouple import config
|
from decouple import config
|
||||||
from django.conf import settings
|
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"))
|
EXP_MAKER_BOND_INVOICE = int(config("EXP_MAKER_BOND_INVOICE"))
|
||||||
RETRY_TIME = int(config("RETRY_TIME"))
|
RETRY_TIME = int(config("RETRY_TIME"))
|
||||||
|
|
||||||
avatar_path = Path(settings.AVATAR_ROOT)
|
|
||||||
avatar_path.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
|
|
||||||
class MakerView(CreateAPIView):
|
class MakerView(CreateAPIView):
|
||||||
serializer_class = MakeOrderSerializer
|
serializer_class = MakeOrderSerializer
|
||||||
|
@ -16,7 +16,6 @@ Pillow==10.1.0
|
|||||||
python-decouple==3.8
|
python-decouple==3.8
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
ring==0.10.1
|
ring==0.10.1
|
||||||
git+https://github.com/RoboSats/Robohash.git
|
|
||||||
gunicorn==22.0.0
|
gunicorn==22.0.0
|
||||||
psycopg2==2.9.9
|
psycopg2==2.9.9
|
||||||
SQLAlchemy==2.0.16
|
SQLAlchemy==2.0.16
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from channels.db import database_sync_to_async
|
from channels.db import database_sync_to_async
|
||||||
from channels.middleware import BaseMiddleware
|
from channels.middleware import BaseMiddleware
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth.models import AnonymousUser, User, update_last_login
|
from django.contrib.auth.models import AnonymousUser, User, update_last_login
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import MiddlewareMixin
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
from robohash import Robohash
|
|
||||||
|
|
||||||
from api.nick_generator.nick_generator import NickGenerator
|
from api.nick_generator.nick_generator import NickGenerator
|
||||||
from api.utils import base91_to_hex, hex_to_base91, is_valid_token, validate_pgp_keys
|
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
|
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):
|
class DisableCSRFMiddleware(object):
|
||||||
def __init__(self, get_response):
|
def __init__(self, get_response):
|
||||||
@ -158,21 +152,6 @@ class RobotTokenSHA256AuthenticationMiddleWare:
|
|||||||
if not user.robot.encrypted_private_key:
|
if not user.robot.encrypted_private_key:
|
||||||
user.robot.encrypted_private_key = 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)
|
update_last_login(None, user)
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ from .celery.conf import * # noqa
|
|||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
STATIC_URL = "/static/"
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||||
|
|
||||||
@ -32,8 +30,10 @@ STATIC_URL = "/static/"
|
|||||||
SECRET_KEY = config("SECRET_KEY")
|
SECRET_KEY = config("SECRET_KEY")
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
STATIC_ROOT = "/usr/src/static/"
|
|
||||||
|
|
||||||
# RoboSats version
|
# RoboSats version
|
||||||
with open("version.json") as f:
|
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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
if config("DEVELOPMENT", default=False):
|
if config("DEVELOPMENT", default=False):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
STATIC_ROOT = "frontend/static/"
|
|
||||||
|
|
||||||
AVATAR_ROOT = STATIC_ROOT + "assets/avatars/"
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
config("HOST_NAME"),
|
config("HOST_NAME"),
|
||||||
@ -228,10 +225,6 @@ USE_I18N = True
|
|||||||
|
|
||||||
USE_TZ = 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"
|
ASGI_APPLICATION = "robosats.routing.application"
|
||||||
|
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
|
Loading…
Reference in New Issue
Block a user