from sqlalchemy import ( Column, String, types, ) from sqlalchemy.dialects.postgresql import UUID import uuid from typing import Literal from .database import Base # DOMAIN_URL = os.environ.get("DOMAIN_URL", "localhost") StatusType = Literal["offline", "online", "webhook_error", "token_error"] class ChoiceType(types.TypeDecorator): impl = types.String def __init__(self, choices, **kw): self.choices = dict(choices) super(ChoiceType, self).__init__(**kw) def process_bind_param(self, value, dialect): return [k for k, v in self.choices.items() if v == value][0] def process_result_value(self, value, dialect): return self.choices[value] class TelegramUpload(Base): __tablename__ = "telegramuploads" id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) path = Column(String, index=True) file_id = Column(String, index=True, default=None) type = Column( ChoiceType( { "pic": "pic", "gif": "gif", } ), default=None, )