Compare commits

...

2 Commits

Author SHA1 Message Date
l.gabrysiak 809609acd0 mod auth 2025-03-02 12:09:55 +01:00
l.gabrysiak 7a43d01cdf mod user (avatar generator) 2025-03-02 12:07:41 +01:00
2 changed files with 37 additions and 0 deletions

View File

@ -7,6 +7,8 @@ from open_webui.internal.db import Base, JSONField, get_db
from open_webui.models.chats import Chats
from open_webui.models.groups import Groups
from PIL import Image, ImageDraw, ImageFont
import random
from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text, JSON
@ -341,7 +343,37 @@ class UsersTable:
with get_db() as db:
users = db.query(User).filter(User.id.in_(user_ids)).all()
return [user.id for user in users]
def generate_letter_image(letter, image_size=(200, 200), font_size=100, font_path=None):
"""
Generuje obraz z podaną literą i losowym kolorem tła.
:param letter: Pojedyncza litera do wyświetlenia
:param image_size: Rozmiar obrazu (szerokość, wysokość)
:param font_size: Rozmiar czcionki
:param font_path: Ścieżka do pliku czcionki (jeśli None, używana jest domyślna)
"""
if not isinstance(letter, str) or len(letter) != 1:
raise ValueError("Parametr 'letter' musi być pojedynczym znakiem.")
background_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
text_color = (255, 255, 255) # Biały kolor czcionki
image = Image.new("RGB", image_size, background_color)
draw = ImageDraw.Draw(image)
try:
font = ImageFont.truetype(font_path if font_path else "arial.ttf", font_size)
except IOError:
font = ImageFont.load_default()
text_width, text_height = draw.textsize(letter, font=font)
text_x = (image_size[0] - text_width) // 2
text_y = (image_size[1] - text_height) // 2
draw.text((text_x, text_y), letter, font=font, fill=text_color)
return image
def update_user_profile(self, id: str, name: str, profile_image_url: str, role: str, permissions: Optional[dict] = None, subscription: Optional[List[str]] = None) -> bool:
try:
with get_db() as db:

View File

@ -320,6 +320,11 @@ class OAuthManager:
print(user_data.get("permissions"))
if not user:
generated_image = Users.generate_letter_image()
print(generated_image)
user_count = Users.get_num_users()
# If the user does not exist, check if signups are enabled