Ejemplo n.º 1
0
 async def get(cls,
               loc_id: str,
               *,
               _thumbnail: bool = False) -> TelegramFile | None:
     q = (
         "SELECT id, mxc, mime_type, was_converted, timestamp, size, width, height, thumbnail,"
         "       decryption_info "
         "FROM telegram_file WHERE id=$1")
     row = await cls.db.fetchrow(q, loc_id)
     if row is None:
         return None
     data = {**row}
     thumbnail_id = data.pop("thumbnail", None)
     if _thumbnail:
         # Don't allow more than one level of recursion
         thumbnail_id = None
     decryption_info = data.pop("decryption_info", None)
     return cls(
         **data,
         thumbnail=(await cls.get(thumbnail_id, _thumbnail=True))
         if thumbnail_id else None,
         decryption_info=EncryptedFile.parse_json(decryption_info)
         if decryption_info else None,
     )
Ejemplo n.º 2
0
 def process_result_value(self, value: str,
                          dialect) -> Optional[EncryptedFile]:
     if value is not None:
         return EncryptedFile.parse_json(value)
     return None