mariadb -> postgres
This commit is contained in:
1 parent
21964fa986
commit
e51bb86dc0
36 files changed
+650
-464
No files matched your search
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import and_, select
|
||||
from app.core.models.node_storage import StoredContent
|
||||
from app.core.models.content.user_content import UserContent, UserAction
|
||||
from app.core.logger import make_log
|
||||
@@ -27,17 +27,17 @@ class PlayerTemplates:
|
||||
if not content.encrypted:
|
||||
local_content = content
|
||||
else:
|
||||
local_content = db_session.query(StoredContent).filter_by(
|
||||
id=content.decrypted_content_id
|
||||
).first()
|
||||
local_content = (await db_session.execute(select(StoredContent).where(StoredContent.id == content.decrypted_content_id))).scalars().first()
|
||||
# TODO: add check decrypted_content by .format_json()['content_cid']
|
||||
if local_content:
|
||||
cd_log += f"Decrypted: {local_content.hash}. "
|
||||
else:
|
||||
cd_log += "Can't decrypt content. "
|
||||
|
||||
user_wallet_address = self.user.wallet_address(self.db_session)
|
||||
user_existing_license = self.db_session.query(UserContent).filter_by(user_id=self.user.id, content_id=content.id).first()
|
||||
user_wallet_address = await self.user.wallet_address_async(self.db_session)
|
||||
user_existing_license = (await self.db_session.execute(select(UserContent).where(
|
||||
and_(UserContent.user_id == self.user.id, UserContent.content_id == content.id)
|
||||
))).scalars().first()
|
||||
|
||||
if local_content:
|
||||
content_meta = content.json_format()
|
||||
@@ -48,12 +48,12 @@ class PlayerTemplates:
|
||||
except:
|
||||
content_type, content_encoding = 'application', 'x-binary'
|
||||
|
||||
content_metadata = StoredContent.from_cid(db_session, content_meta.get('metadata_cid') or None)
|
||||
content_metadata = await StoredContent.from_cid_async(db_session, content_meta.get('metadata_cid') or None)
|
||||
with open(content_metadata.filepath, 'r') as f:
|
||||
content_metadata_json = json.loads(f.read())
|
||||
|
||||
try:
|
||||
cover_content = StoredContent.from_cid(self.db_session, content_meta.get('cover_cid') or None)
|
||||
cover_content = await StoredContent.from_cid_async(self.db_session, content_meta.get('cover_cid') or None)
|
||||
cd_log += f"Cover content: {cover_content.cid.serialize_v2()}. "
|
||||
except BaseException as e:
|
||||
cd_log += f"Can't get cover content: {e}. "
|
||||
@@ -88,12 +88,15 @@ class PlayerTemplates:
|
||||
<blockquote><a href="{content_share_link['url']}">🔴 «открыть в MY»</a></blockquote>"""
|
||||
|
||||
make_log("TG-Player", f"Send content {content_type} ({content_encoding}) to chat {self._chat_id}. {cd_log}")
|
||||
for kmsg in self.db_session.query(KnownTelegramMessage).filter_by(
|
||||
content_id=content.id,
|
||||
chat_id=self._chat_id,
|
||||
type=f'content/{content_type}',
|
||||
deleted=False
|
||||
).all():
|
||||
kmsgs = (await self.db_session.execute(select(KnownTelegramMessage).where(
|
||||
and_(
|
||||
KnownTelegramMessage.content_id == content.id,
|
||||
KnownTelegramMessage.chat_id == self._chat_id,
|
||||
KnownTelegramMessage.type == f'content/{content_type}',
|
||||
KnownTelegramMessage.deleted == False
|
||||
)
|
||||
))).scalars().all()
|
||||
for kmsg in kmsgs:
|
||||
await self.delete_message(kmsg.message_id)
|
||||
|
||||
r = await tg_process_template(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from aiogram import Bot, types
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import and_, select
|
||||
|
||||
from app.core.logger import make_log
|
||||
from app.core.models.messages import KnownTelegramMessage
|
||||
@@ -46,14 +46,15 @@ class Wrapped_CBotChat(T, PlayerTemplates):
|
||||
if self.db_session:
|
||||
if message_type == 'common':
|
||||
ci = 0
|
||||
for oc_msg in self.db_session.query(KnownTelegramMessage).filter(
|
||||
result = await self.db_session.execute(select(KnownTelegramMessage).where(
|
||||
and_(
|
||||
KnownTelegramMessage.type == 'common',
|
||||
KnownTelegramMessage.bot_id == self.bot_id,
|
||||
KnownTelegramMessage.chat_id == self._chat_id,
|
||||
KnownTelegramMessage.deleted == False
|
||||
)
|
||||
).all():
|
||||
))
|
||||
for oc_msg in result.scalars().all():
|
||||
make_log(self, f"Delete old message {oc_msg.message_id} {oc_msg.type} {oc_msg.bot_id} {oc_msg.chat_id}")
|
||||
await self.delete_message(oc_msg.message_id)
|
||||
ci += 1
|
||||
@@ -75,7 +76,7 @@ class Wrapped_CBotChat(T, PlayerTemplates):
|
||||
content_id=content_id
|
||||
)
|
||||
)
|
||||
self.db_session.commit()
|
||||
await self.db_session.commit()
|
||||
else:
|
||||
make_log(self, f"Unknown result type: {type(result)}", level='warning')
|
||||
|
||||
@@ -127,14 +128,16 @@ class Wrapped_CBotChat(T, PlayerTemplates):
|
||||
message_id
|
||||
)):
|
||||
if self.db_session:
|
||||
known_message = self.db_session.query(KnownTelegramMessage).filter(
|
||||
KnownTelegramMessage.bot_id == self.bot_id,
|
||||
KnownTelegramMessage.chat_id == self._chat_id,
|
||||
KnownTelegramMessage.message_id == message_id
|
||||
).first()
|
||||
known_message = (await self.db_session.execute(select(KnownTelegramMessage).where(
|
||||
and_(
|
||||
KnownTelegramMessage.bot_id == self.bot_id,
|
||||
KnownTelegramMessage.chat_id == self._chat_id,
|
||||
KnownTelegramMessage.message_id == message_id
|
||||
)
|
||||
))).scalars().first()
|
||||
if known_message:
|
||||
known_message.deleted = True
|
||||
self.db_session.commit()
|
||||
await self.db_session.commit()
|
||||
except Exception as e:
|
||||
make_log(self, f"Error deleting message {self._chat_id}/{message_id}. Error: {e}", level='warning')
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user