From d2ff3324906f2a6cd1f3ffd9d13db00dc23348ba Mon Sep 17 00:00:00 2001 From: user Date: Sat, 26 Apr 2025 13:13:47 +0300 Subject: [PATCH] fix convert service --- app/core/background/convert_service.py | 32 +++++--------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/app/core/background/convert_service.py b/app/core/background/convert_service.py index 3c03f79..132aa81 100644 --- a/app/core/background/convert_service.py +++ b/app/core/background/convert_service.py @@ -65,40 +65,20 @@ async def convert_loop(memory): # Для прочих типов сохраняем raw копию и выходим if content_kind == "other": - raw_hash = unprocessed_encrypted_content.hash - raw_content = StoredContent( - type="local/content_raw", - hash=raw_hash, - user_id=unprocessed_encrypted_content.user_id, - filename=unprocessed_encrypted_content.filename, - meta={'source': 'raw_copy'}, - created=datetime.now(), - ) - session.add(raw_content) - session.commit() - - # Копируем файл в UPLOADS_DIR - dst = os.path.join(UPLOADS_DIR, raw_hash) - try: - os.remove(dst) - except FileNotFoundError: - pass - shutil.copy2(input_file_path, dst) - - # Обновляем оригинальный объект + make_log("ConvertProcess", f"Content {unprocessed_encrypted_content.id} processed. Converted content: {converted_content}", level="info") unprocessed_encrypted_content.btfs_cid = ContentId( - version=2, content_hash=b58decode(raw_hash) + version=2, content_hash=b58decode(converted_content['high' if content_kind=='video' else 'low']) ).serialize_v2() unprocessed_encrypted_content.ipfs_cid = ContentId( - version=2, content_hash=b58decode(raw_hash) + version=2, content_hash=b58decode(converted_content['low']) ).serialize_v2() unprocessed_encrypted_content.meta = { **unprocessed_encrypted_content.meta, - 'converted_content': {'raw': raw_hash} + 'converted_content': { + option_name: decrypted_content.hash for option_name in ['high', 'low', 'low_preview'] + } } session.commit() - - make_log("ConvertProcess", f"Raw content saved for {raw_hash}", level="info") return # ==== Конвертация для видео или аудио: оригинальная логика ====