This commit is contained in:
user committed 2024-04-10 11:19:04 +03:00
1 parent 3035a39083
commit a836196a47
7 files changed
+132 -3

No files matched your search

+1
View File
@@ -28,6 +28,7 @@ class UserContent(AlchemyBase, UserContentIndexationMixin):
wallet_connection = relationship('WalletConnection', uselist=False, foreign_keys=[wallet_connection_id])
content = relationship('StoredContent', uselist=False, foreign_keys=[content_id])
class UserAction(AlchemyBase):
__tablename__ = 'users_actions'
+28 -1
View File
@@ -7,11 +7,13 @@ from app.core.logger import make_log
from app.core._config import UPLOADS_DIR, PROJECT_HOST
import os
from app.core.content.content_id import ContentId
from app.core.content.audio import AudioContentMixin
from app.core.content.image import ImageContentMixin
# from app.core.models.content.indexation_mixins import NodeStorageIndexationMixin
from .base import AlchemyBase
class StoredContent(AlchemyBase):
class StoredContent(AlchemyBase, AudioContentMixin):
__tablename__ = 'node_storage'
id = Column(Integer, autoincrement=True, primary_key=True)
@@ -68,6 +70,31 @@ class StoredContent(AlchemyBase):
return bool(self.key_id or self.decrypted_content_id)
def open_content(self, db_session, content_type=None):
try:
# Получение StoredContent в прод-виде с указанием типа данных и доступный для перевода в другие форматы
decrypted_content = self if not self.encrypted else None
encrypted_content = self if self.encrypted else None
content_type = None
if not decrypted_content:
decrypted_content = db_session.query(StoredContent).filter(StoredContent.id == self.decrypted_content_id).first()
else:
encrypted_content = db_session.query(StoredContent).filter(StoredContent.decrypted_content_id == self.id).first()
assert decrypted_content, "Can't get decrypted content"
assert encrypted_content, "Can't get encrypted content"
content_type = content_type or decrypted_content.json_format()['content_type']
content_type, content_encoding = content_type.split('/')
return {
'encrypted_content': encrypted_content,
'decrypted_content': decrypted_content,
'content_type': content_type or 'application/x-binary'
}
except BaseException as e:
make_log("NodeStorage.open_content", f"Can't open content: {self.id} {e}", level='error')
raise e
def json_format(self):
extra_fields = {}
if self.btfs_cid: