mariadb -> postgres

This commit is contained in:
user committed 2025-08-22 14:04:21 +03:00
1 parent 21964fa986
commit e51bb86dc0
36 files changed
+650 -464

No files matched your search

+17 -14
View File
@@ -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(